_info 1.9 KB

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