]> git.ozlabs.org Git - ccan/blob - ccan/argcheck/_info
620ff838a2d59e82188803b970be1836649a89bb
[ccan] / ccan / argcheck / _info
1 #include "config.h"
2
3 /**
4  * argcheck - macros to check arguments at runtime
5  *
6  * This code provides some macros to check arguments for valid value ranges.
7  * Consider this a mild version of assert(3), because all it does is to log
8  * a message and continue.
9  *
10  * These macros don't replace error handling, but they are useful in
11  * situations where an error is unexpected but not common, i.e.
12  * "this shouldn't happen but if it does let me know".
13  *
14  * argcheck's error messages can be disabled by defining
15  * ARGCHECK_DISABLE_LOGGING before including the header file. The conditions
16  * will continue to evaluate but no error messages will be generated. It is thus
17  * safe to use argcheck macros inside if conditions.
18  *
19  * By default, argcheck prints to fprintf(stderr). That can be changed by
20  * defining argcheck_log to a custom log function. See argcheck_log_() for the
21  * function signature. If ARGCHECK_DISABLE_LOGGING is defined, the custom log
22  * function is not called.
23  *
24  * Example:
25  *      #include <stdio.h>
26  *      #include <ccan/argcheck/argcheck.h>
27  *
28  *      enum state { S1, S2, S3 };
29  *
30  *      static int some_state_machine(enum state s) {
31  *          int b;
32  *
33  *          argcheck_int_range(s, S1, S3);
34  *
35  *          switch(s) {
36  *              case S1: b = 8; break;
37  *              case S2: b = 9; break;
38  *              case S3: b = 88; break;
39  *              default:
40  *                      break;
41  *          }
42  *
43  *          return b;
44  *      }
45  *
46  *      int main(int argc, char *argv[]) {
47  *          int a = S1;
48  *
49  *          if (!argcheck_int_gt(argc, 1))
50  *              return 1;
51  *
52  *          return some_state_machine(a);
53  *      }
54  *
55  * Author: Peter Hutterer <peter.hutterer@who-t.net>
56  * Maintainer: Peter Hutterer <peter.hutterer@who-t.net>
57  * License: BSD-MIT
58  */
59
60 int main(int argc, char *argv[])
61 {
62         /* Expect exactly one argument */
63         if (argc != 2)
64                 return 1;
65
66         if (strcmp(argv[1], "depends") == 0) {
67                 printf("ccan/likely\n");
68                 printf("ccan/compiler\n");
69                 return 0;
70         }
71
72         return 1;
73 }