aboutsummaryrefslogtreecommitdiffstats
path: root/valid.h
blob: c753443a74694d96d01a95bdbd49baba4d5ab379 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* ==========================================================================
    Licensed under BSD 2clause license. See LICENSE file for more information
    Author: Michał Łyszczek <michal.lyszczek@bofc.pl>
   ========================================================================== */


#ifndef EL_VALID_H
#define EL_VALID_H 1


#include <errno.h>


/* ==========================================================================
    If expression 'x' evaluates to false,  macro will set errno value to 'e'
    and will force function to return with code '-1'
   ========================================================================== */


#define VALID(e, x) if (!(x)) { errno = (e); return -1; }


/* ==========================================================================
    If expression 'x' evaluates to false,  macro will set errno value to 'e'
    and will force function to return value 'v'
   ========================================================================== */


#define VALIDR(e, v, x) if (!(x)) { errno = (e); return (v); }


/* ==========================================================================
    If expression 'x' evaluates to false,  macro will set errno value to 'e'
    and will jump to lable 'l'
   ========================================================================== */


#define VALIDGO(e, l, x) if (!(x)) { errno = (e); goto l; }


#endif