diff options
Diffstat (limited to 'src/include/gnunet_common.h')
-rw-r--r-- | src/include/gnunet_common.h | 485 |
1 files changed, 260 insertions, 225 deletions
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 9fa3de37d..c5885e7c4 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h | |||
@@ -55,20 +55,20 @@ | |||
55 | #if defined(__FreeBSD__) | 55 | #if defined(__FreeBSD__) |
56 | 56 | ||
57 | #include <sys/endian.h> | 57 | #include <sys/endian.h> |
58 | #define bswap_32(x) bswap32(x) | 58 | #define bswap_32(x) bswap32 (x) |
59 | #define bswap_64(x) bswap64(x) | 59 | #define bswap_64(x) bswap64 (x) |
60 | 60 | ||
61 | #elif defined(__OpenBSD__) | 61 | #elif defined(__OpenBSD__) |
62 | 62 | ||
63 | #define bswap_32(x) swap32(x) | 63 | #define bswap_32(x) swap32 (x) |
64 | #define bswap_64(x) swap64(x) | 64 | #define bswap_64(x) swap64 (x) |
65 | 65 | ||
66 | #elif defined(__NetBSD__) | 66 | #elif defined(__NetBSD__) |
67 | 67 | ||
68 | #include <machine/bswap.h> | 68 | #include <machine/bswap.h> |
69 | #if defined(__BSWAP_RENAME) && !defined(__bswap_32) | 69 | #if defined(__BSWAP_RENAME) && ! defined(__bswap_32) |
70 | #define bswap_32(x) bswap32(x) | 70 | #define bswap_32(x) bswap32 (x) |
71 | #define bswap_64(x) bswap64(x) | 71 | #define bswap_64(x) bswap64 (x) |
72 | #endif | 72 | #endif |
73 | 73 | ||
74 | #elif defined(__linux__) || defined(GNU) | 74 | #elif defined(__linux__) || defined(GNU) |
@@ -166,15 +166,19 @@ enum GNUNET_GenericReturnValue | |||
166 | #define BYTE_SWAP_16(x) ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8)) | 166 | #define BYTE_SWAP_16(x) ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8)) |
167 | 167 | ||
168 | #define BYTE_SWAP_32(x) \ | 168 | #define BYTE_SWAP_32(x) \ |
169 | ((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \ | 169 | ((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \ |
170 | | (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24)) | 170 | | (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24)) |
171 | 171 | ||
172 | #define BYTE_SWAP_64(x) \ | 172 | #define BYTE_SWAP_64(x) \ |
173 | ((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << 40) \ | 173 | ((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << \ |
174 | | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) << 8) \ | 174 | 40) \ |
175 | | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) >> 24) \ | 175 | | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) \ |
176 | | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) >> \ | 176 | << 8) \ |
177 | 56)) | 177 | | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) \ |
178 | >> 24) \ | ||
179 | | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) \ | ||
180 | >> \ | ||
181 | 56)) | ||
178 | #endif | 182 | #endif |
179 | 183 | ||
180 | #if __BYTE_ORDER == __LITTLE_ENDIAN | 184 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
@@ -479,7 +483,7 @@ GNUNET_get_log_call_status (int caller_level, | |||
479 | 483 | ||
480 | #endif | 484 | #endif |
481 | 485 | ||
482 | 486 | /* *INDENT-OFF* */ | |
483 | /** | 487 | /** |
484 | * @ingroup logging | 488 | * @ingroup logging |
485 | * Main log function. | 489 | * Main log function. |
@@ -489,13 +493,15 @@ GNUNET_get_log_call_status (int caller_level, | |||
489 | * @param ... arguments for format string | 493 | * @param ... arguments for format string |
490 | */ | 494 | */ |
491 | void | 495 | void |
492 | GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...) | 496 | GNUNET_log_nocheck (enum GNUNET_ErrorType kind, |
497 | const char *message, | ||
498 | ...) | ||
493 | __attribute__ ((format (printf, 2, 3))); | 499 | __attribute__ ((format (printf, 2, 3))); |
494 | 500 | ||
495 | /* from glib */ | 501 | /* from glib */ |
496 | #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) | 502 | #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) |
497 | #define _GNUNET_BOOLEAN_EXPR(expr) \ | 503 | #define _GNUNET_BOOLEAN_EXPR(expr) \ |
498 | __extension__ ({ \ | 504 | __extension__ ({ \ |
499 | int _gnunet_boolean_var_; \ | 505 | int _gnunet_boolean_var_; \ |
500 | if (expr) \ | 506 | if (expr) \ |
501 | _gnunet_boolean_var_ = 1; \ | 507 | _gnunet_boolean_var_ = 1; \ |
@@ -513,6 +519,7 @@ __attribute__ ((format (printf, 2, 3))); | |||
513 | #if ! defined(GNUNET_LOG_CALL_STATUS) | 519 | #if ! defined(GNUNET_LOG_CALL_STATUS) |
514 | #define GNUNET_LOG_CALL_STATUS -1 | 520 | #define GNUNET_LOG_CALL_STATUS -1 |
515 | #endif | 521 | #endif |
522 | /* *INDENT-ON* */ | ||
516 | 523 | ||
517 | 524 | ||
518 | /** | 525 | /** |
@@ -534,56 +541,56 @@ __attribute__ ((format (printf, 3, 4))); | |||
534 | 541 | ||
535 | #if ! defined(GNUNET_CULL_LOGGING) | 542 | #if ! defined(GNUNET_CULL_LOGGING) |
536 | #define GNUNET_log_from(kind, comp, ...) \ | 543 | #define GNUNET_log_from(kind, comp, ...) \ |
537 | do \ | 544 | do \ |
538 | { \ | 545 | { \ |
539 | static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \ | 546 | static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \ |
540 | if ((GNUNET_EXTRA_LOGGING > 0) || \ | 547 | if ((GNUNET_EXTRA_LOGGING > 0) || \ |
541 | ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ | 548 | ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ |
542 | { \ | 549 | { \ |
543 | if (GN_UNLIKELY (log_call_enabled == -1)) \ | 550 | if (GN_UNLIKELY (log_call_enabled == -1)) \ |
544 | log_call_enabled = \ | 551 | log_call_enabled = \ |
545 | GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \ | 552 | GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \ |
546 | (comp), \ | 553 | (comp), \ |
547 | __FILE__, \ | 554 | __FILE__, \ |
548 | __FUNCTION__, \ | 555 | __FUNCTION__, \ |
549 | __LINE__); \ | 556 | __LINE__); \ |
550 | if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ | 557 | if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ |
551 | { \ | 558 | { \ |
552 | GNUNET_log_skip (-1, GNUNET_NO); \ | 559 | GNUNET_log_skip (-1, GNUNET_NO); \ |
553 | } \ | 560 | } \ |
554 | else \ | 561 | else \ |
555 | { \ | 562 | { \ |
556 | if (GN_UNLIKELY (log_call_enabled)) \ | 563 | if (GN_UNLIKELY (log_call_enabled)) \ |
557 | GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \ | 564 | GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \ |
558 | } \ | 565 | } \ |
559 | } \ | 566 | } \ |
560 | } while (0) | 567 | } while (0) |
561 | 568 | ||
562 | #define GNUNET_log(kind, ...) \ | 569 | #define GNUNET_log(kind, ...) \ |
563 | do \ | 570 | do \ |
564 | { \ | 571 | { \ |
565 | static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \ | 572 | static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \ |
566 | if ((GNUNET_EXTRA_LOGGING > 0) || \ | 573 | if ((GNUNET_EXTRA_LOGGING > 0) || \ |
567 | ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ | 574 | ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ |
568 | { \ | 575 | { \ |
569 | if (GN_UNLIKELY (log_call_enabled == -1)) \ | 576 | if (GN_UNLIKELY (log_call_enabled == -1)) \ |
570 | log_call_enabled = \ | 577 | log_call_enabled = \ |
571 | GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \ | 578 | GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \ |
572 | NULL, \ | 579 | NULL, \ |
573 | __FILE__, \ | 580 | __FILE__, \ |
574 | __FUNCTION__, \ | 581 | __FUNCTION__, \ |
575 | __LINE__); \ | 582 | __LINE__); \ |
576 | if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ | 583 | if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ |
577 | { \ | 584 | { \ |
578 | GNUNET_log_skip (-1, GNUNET_NO); \ | 585 | GNUNET_log_skip (-1, GNUNET_NO); \ |
579 | } \ | 586 | } \ |
580 | else \ | 587 | else \ |
581 | { \ | 588 | { \ |
582 | if (GN_UNLIKELY (log_call_enabled)) \ | 589 | if (GN_UNLIKELY (log_call_enabled)) \ |
583 | GNUNET_log_nocheck ((kind), __VA_ARGS__); \ | 590 | GNUNET_log_nocheck ((kind), __VA_ARGS__); \ |
584 | } \ | 591 | } \ |
585 | } \ | 592 | } \ |
586 | } while (0) | 593 | } while (0) |
587 | #else | 594 | #else |
588 | #define GNUNET_log(...) | 595 | #define GNUNET_log(...) |
589 | #define GNUNET_log_from(...) | 596 | #define GNUNET_log_from(...) |
@@ -642,7 +649,7 @@ GNUNET_abort_ (void) GNUNET_NORETURN; | |||
642 | */ | 649 | */ |
643 | const char * | 650 | const char * |
644 | GNUNET_b2s (const void *buf, | 651 | GNUNET_b2s (const void *buf, |
645 | size_t buf_size); | 652 | size_t buf_size); |
646 | 653 | ||
647 | 654 | ||
648 | /** | 655 | /** |
@@ -676,7 +683,9 @@ GNUNET_log_skip (int n, int check_reset); | |||
676 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if logfile could not be opened | 683 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if logfile could not be opened |
677 | */ | 684 | */ |
678 | enum GNUNET_GenericReturnValue | 685 | enum GNUNET_GenericReturnValue |
679 | GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile); | 686 | GNUNET_log_setup (const char *comp, |
687 | const char *loglevel, | ||
688 | const char *logfile); | ||
680 | 689 | ||
681 | 690 | ||
682 | /** | 691 | /** |
@@ -690,7 +699,8 @@ GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile); | |||
690 | * @param logger_cls closure for @a logger | 699 | * @param logger_cls closure for @a logger |
691 | */ | 700 | */ |
692 | void | 701 | void |
693 | GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls); | 702 | GNUNET_logger_add (GNUNET_Logger logger, |
703 | void *logger_cls); | ||
694 | 704 | ||
695 | 705 | ||
696 | /** | 706 | /** |
@@ -701,7 +711,8 @@ GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls); | |||
701 | * @param logger_cls closure for @a logger | 711 | * @param logger_cls closure for @a logger |
702 | */ | 712 | */ |
703 | void | 713 | void |
704 | GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls); | 714 | GNUNET_logger_remove (GNUNET_Logger logger, |
715 | void *logger_cls); | ||
705 | 716 | ||
706 | 717 | ||
707 | /** | 718 | /** |
@@ -916,36 +927,37 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
916 | * @ingroup logging | 927 | * @ingroup logging |
917 | * Use this for fatal errors that cannot be handled | 928 | * Use this for fatal errors that cannot be handled |
918 | */ | 929 | */ |
919 | #if __GNUC__ >= 6 || __clang_major__ >= 6 | 930 | #if __GNUC__ >= 6 || __clang_major__ >= 6 |
920 | #define GNUNET_assert(cond) \ | 931 | #define GNUNET_assert(cond) \ |
921 | do \ | 932 | do \ |
922 | { \ | 933 | { \ |
923 | _Pragma("GCC diagnostic push") \ | 934 | _Pragma("GCC diagnostic push") \ |
924 | _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \ | 935 | _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \ |
925 | if (! (cond)) \ | 936 | if (! (cond)) \ |
926 | { \ | 937 | { \ |
927 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ | 938 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ |
928 | dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ | 939 | dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ |
929 | __FILE__, \ | 940 | __FILE__, \ |
930 | __LINE__); \ | 941 | __LINE__); \ |
931 | GNUNET_abort_ (); \ | 942 | GNUNET_abort_ (); \ |
932 | } \ | 943 | } \ |
933 | _Pragma("GCC diagnostic pop") \ | 944 | _Pragma("GCC diagnostic pop") \ |
934 | } while (0) | 945 | } while (0) |
935 | #else | 946 | #else |
936 | /* older GCC/clangs do not support -Wtautological-compare */ | 947 | /* older GCC/clangs do not support -Wtautological-compare */ |
937 | #define GNUNET_assert(cond) \ | 948 | #define GNUNET_assert(cond) \ |
938 | do \ | 949 | do \ |
939 | { \ | 950 | { \ |
940 | if (! (cond)) \ | 951 | if (! (cond)) \ |
941 | { \ | 952 | { \ |
942 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ | 953 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ |
943 | dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ | 954 | dgettext ("gnunet", \ |
944 | __FILE__, \ | 955 | "Assertion failed at %s:%d. Aborting.\n"), \ |
945 | __LINE__); \ | 956 | __FILE__, \ |
946 | GNUNET_abort_ (); \ | 957 | __LINE__); \ |
947 | } \ | 958 | GNUNET_abort_ (); \ |
948 | } while (0) | 959 | } \ |
960 | } while (0) | ||
949 | #endif | 961 | #endif |
950 | 962 | ||
951 | /** | 963 | /** |
@@ -953,17 +965,18 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
953 | * Use this for fatal errors that cannot be handled | 965 | * Use this for fatal errors that cannot be handled |
954 | */ | 966 | */ |
955 | #define GNUNET_assert_at(cond, f, l) \ | 967 | #define GNUNET_assert_at(cond, f, l) \ |
956 | do \ | 968 | do \ |
957 | { \ | 969 | { \ |
958 | if (! (cond)) \ | 970 | if (! (cond)) \ |
959 | { \ | 971 | { \ |
960 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ | 972 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ |
961 | dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ | 973 | dgettext ("gnunet", \ |
962 | f, \ | 974 | "Assertion failed at %s:%d. Aborting.\n"), \ |
963 | l); \ | 975 | f, \ |
964 | GNUNET_abort_ (); \ | 976 | l); \ |
965 | } \ | 977 | GNUNET_abort_ (); \ |
966 | } while (0) | 978 | } \ |
979 | } while (0) | ||
967 | 980 | ||
968 | 981 | ||
969 | /** | 982 | /** |
@@ -974,18 +987,20 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
974 | * @param comp Component string to use for logging | 987 | * @param comp Component string to use for logging |
975 | */ | 988 | */ |
976 | #define GNUNET_assert_from(cond, comp) \ | 989 | #define GNUNET_assert_from(cond, comp) \ |
977 | do \ | 990 | do \ |
978 | { \ | 991 | { \ |
979 | if (! (cond)) \ | 992 | if (! (cond)) \ |
980 | { \ | 993 | { \ |
981 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \ | 994 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \ |
982 | comp, \ | 995 | comp, \ |
983 | dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ | 996 | dgettext ("gnunet", \ |
984 | __FILE__, \ | 997 | "Assertion failed at %s:%d. Aborting.\n") \ |
985 | __LINE__); \ | 998 | , \ |
986 | GNUNET_abort_ (); \ | 999 | __FILE__, \ |
987 | } \ | 1000 | __LINE__); \ |
988 | } while (0) | 1001 | GNUNET_abort_ (); \ |
1002 | } \ | ||
1003 | } while (0) | ||
989 | 1004 | ||
990 | 1005 | ||
991 | #ifdef _Static_assert | 1006 | #ifdef _Static_assert |
@@ -1016,16 +1031,16 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
1016 | * not fatal (can be handled) but should not occur. | 1031 | * not fatal (can be handled) but should not occur. |
1017 | */ | 1032 | */ |
1018 | #define GNUNET_break(cond) \ | 1033 | #define GNUNET_break(cond) \ |
1019 | do \ | 1034 | do \ |
1020 | { \ | 1035 | { \ |
1021 | if (! (cond)) \ | 1036 | if (! (cond)) \ |
1022 | { \ | 1037 | { \ |
1023 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ | 1038 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ |
1024 | dgettext ("gnunet", "Assertion failed at %s:%d.\n"), \ | 1039 | dgettext ("gnunet", "Assertion failed at %s:%d.\n"), \ |
1025 | __FILE__, \ | 1040 | __FILE__, \ |
1026 | __LINE__); \ | 1041 | __LINE__); \ |
1027 | } \ | 1042 | } \ |
1028 | } while (0) | 1043 | } while (0) |
1029 | 1044 | ||
1030 | 1045 | ||
1031 | /** | 1046 | /** |
@@ -1038,16 +1053,17 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
1038 | * development and testing. "OP == other peer". | 1053 | * development and testing. "OP == other peer". |
1039 | */ | 1054 | */ |
1040 | #define GNUNET_break_op(cond) \ | 1055 | #define GNUNET_break_op(cond) \ |
1041 | do \ | 1056 | do \ |
1042 | { \ | 1057 | { \ |
1043 | if (! (cond)) \ | 1058 | if (! (cond)) \ |
1044 | { \ | 1059 | { \ |
1045 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \ | 1060 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \ |
1046 | dgettext ("gnunet", "External protocol violation detected at %s:%d.\n"), \ | 1061 | dgettext ("gnunet", \ |
1047 | __FILE__, \ | 1062 | "External protocol violation detected at %s:%d.\n"), \ |
1048 | __LINE__); \ | 1063 | __FILE__, \ |
1049 | } \ | 1064 | __LINE__); \ |
1050 | } while (0) | 1065 | } \ |
1066 | } while (0) | ||
1051 | 1067 | ||
1052 | 1068 | ||
1053 | /** | 1069 | /** |
@@ -1057,15 +1073,16 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
1057 | * by strerror(errno). | 1073 | * by strerror(errno). |
1058 | */ | 1074 | */ |
1059 | #define GNUNET_log_strerror(level, cmd) \ | 1075 | #define GNUNET_log_strerror(level, cmd) \ |
1060 | do \ | 1076 | do \ |
1061 | { \ | 1077 | { \ |
1062 | GNUNET_log (level, \ | 1078 | GNUNET_log (level, \ |
1063 | dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \ | 1079 | dgettext ("gnunet", \ |
1064 | cmd, \ | 1080 | "`%s' failed at %s:%d with error: %s\n"), \ |
1065 | __FILE__, \ | 1081 | cmd, \ |
1066 | __LINE__, \ | 1082 | __FILE__, \ |
1067 | strerror (errno)); \ | 1083 | __LINE__, \ |
1068 | } while (0) | 1084 | strerror (errno)); \ |
1085 | } while (0) | ||
1069 | 1086 | ||
1070 | 1087 | ||
1071 | /** | 1088 | /** |
@@ -1075,16 +1092,17 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
1075 | * by strerror(errno). | 1092 | * by strerror(errno). |
1076 | */ | 1093 | */ |
1077 | #define GNUNET_log_from_strerror(level, component, cmd) \ | 1094 | #define GNUNET_log_from_strerror(level, component, cmd) \ |
1078 | do \ | 1095 | do \ |
1079 | { \ | 1096 | { \ |
1080 | GNUNET_log_from (level, \ | 1097 | GNUNET_log_from (level, \ |
1081 | component, \ | 1098 | component, \ |
1082 | dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \ | 1099 | dgettext ("gnunet", \ |
1083 | cmd, \ | 1100 | "`%s' failed at %s:%d with error: %s\n"), \ |
1084 | __FILE__, \ | 1101 | cmd, \ |
1085 | __LINE__, \ | 1102 | __FILE__, \ |
1086 | strerror (errno)); \ | 1103 | __LINE__, \ |
1087 | } while (0) | 1104 | strerror (errno)); \ |
1105 | } while (0) | ||
1088 | 1106 | ||
1089 | 1107 | ||
1090 | /** | 1108 | /** |
@@ -1094,16 +1112,17 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
1094 | * by strerror(errno). | 1112 | * by strerror(errno). |
1095 | */ | 1113 | */ |
1096 | #define GNUNET_log_strerror_file(level, cmd, filename) \ | 1114 | #define GNUNET_log_strerror_file(level, cmd, filename) \ |
1097 | do \ | 1115 | do \ |
1098 | { \ | 1116 | { \ |
1099 | GNUNET_log (level, \ | 1117 | GNUNET_log (level, \ |
1100 | dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \ | 1118 | dgettext ("gnunet", \ |
1101 | cmd, \ | 1119 | "`%s' failed on file `%s' at %s:%d with error: %s\n"), \ |
1102 | filename, \ | 1120 | cmd, \ |
1103 | __FILE__, \ | 1121 | filename, \ |
1104 | __LINE__, \ | 1122 | __FILE__, \ |
1105 | strerror (errno)); \ | 1123 | __LINE__, \ |
1106 | } while (0) | 1124 | strerror (errno)); \ |
1125 | } while (0) | ||
1107 | 1126 | ||
1108 | 1127 | ||
1109 | /** | 1128 | /** |
@@ -1113,17 +1132,18 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); | |||
1113 | * by strerror(errno). | 1132 | * by strerror(errno). |
1114 | */ | 1133 | */ |
1115 | #define GNUNET_log_from_strerror_file(level, component, cmd, filename) \ | 1134 | #define GNUNET_log_from_strerror_file(level, component, cmd, filename) \ |
1116 | do \ | 1135 | do \ |
1117 | { \ | 1136 | { \ |
1118 | GNUNET_log_from (level, \ | 1137 | GNUNET_log_from (level, \ |
1119 | component, \ | 1138 | component, \ |
1120 | dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \ | 1139 | dgettext ("gnunet", \ |
1121 | cmd, \ | 1140 | "`%s' failed on file `%s' at %s:%d with error: %s\n"), \ |
1122 | filename, \ | 1141 | cmd, \ |
1123 | __FILE__, \ | 1142 | filename, \ |
1124 | __LINE__, \ | 1143 | __FILE__, \ |
1125 | strerror (errno)); \ | 1144 | __LINE__, \ |
1126 | } while (0) | 1145 | strerror (errno)); \ |
1146 | } while (0) | ||
1127 | 1147 | ||
1128 | /* ************************* endianness conversion ****************** */ | 1148 | /* ************************* endianness conversion ****************** */ |
1129 | 1149 | ||
@@ -1216,7 +1236,7 @@ GNUNET_ntoh_double (double d); | |||
1216 | * the first element! | 1236 | * the first element! |
1217 | */ | 1237 | */ |
1218 | #define GNUNET_memcmp(a, b) \ | 1238 | #define GNUNET_memcmp(a, b) \ |
1219 | ({ \ | 1239 | ({ \ |
1220 | const typeof (*b) * _a = (a); \ | 1240 | const typeof (*b) * _a = (a); \ |
1221 | const typeof (*a) * _b = (b); \ | 1241 | const typeof (*a) * _b = (b); \ |
1222 | memcmp (_a, _b, sizeof(*a)); \ | 1242 | memcmp (_a, _b, sizeof(*a)); \ |
@@ -1245,7 +1265,7 @@ GNUNET_memcmp_ct_ (const void *b1, | |||
1245 | * the first element! | 1265 | * the first element! |
1246 | */ | 1266 | */ |
1247 | #define GNUNET_memcmp_priv(a, b) \ | 1267 | #define GNUNET_memcmp_priv(a, b) \ |
1248 | ({ \ | 1268 | ({ \ |
1249 | const typeof (*b) * _a = (a); \ | 1269 | const typeof (*b) * _a = (a); \ |
1250 | const typeof (*a) * _b = (b); \ | 1270 | const typeof (*a) * _b = (b); \ |
1251 | GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \ | 1271 | GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \ |
@@ -1258,9 +1278,9 @@ GNUNET_memcmp_ct_ (const void *b1, | |||
1258 | * @param a pointer to @a n bytes which should be tested for the | 1278 | * @param a pointer to @a n bytes which should be tested for the |
1259 | * entire memory being zero'ed out. | 1279 | * entire memory being zero'ed out. |
1260 | * @param n number of bytes in @a to be tested | 1280 | * @param n number of bytes in @a to be tested |
1261 | * @return GNUNET_YES if a is zero, GNUNET_NO otherwise | 1281 | * @return true if @a a is zero, false_NO otherwise |
1262 | */ | 1282 | */ |
1263 | enum GNUNET_GenericReturnValue | 1283 | bool |
1264 | GNUNET_is_zero_ (const void *a, | 1284 | GNUNET_is_zero_ (const void *a, |
1265 | size_t n); | 1285 | size_t n); |
1266 | 1286 | ||
@@ -1273,7 +1293,7 @@ GNUNET_is_zero_ (const void *a, | |||
1273 | * @return GNUNET_YES if a is zero, GNUNET_NO otherwise | 1293 | * @return GNUNET_YES if a is zero, GNUNET_NO otherwise |
1274 | */ | 1294 | */ |
1275 | #define GNUNET_is_zero(a) \ | 1295 | #define GNUNET_is_zero(a) \ |
1276 | GNUNET_is_zero_ ((a), sizeof (*(a))) | 1296 | GNUNET_is_zero_ ((a), sizeof (*(a))) |
1277 | 1297 | ||
1278 | 1298 | ||
1279 | /** | 1299 | /** |
@@ -1286,15 +1306,16 @@ GNUNET_is_zero_ (const void *a, | |||
1286 | * @param n number of bytes to copy | 1306 | * @param n number of bytes to copy |
1287 | */ | 1307 | */ |
1288 | #define GNUNET_memcpy(dst, src, n) \ | 1308 | #define GNUNET_memcpy(dst, src, n) \ |
1289 | do \ | 1309 | do \ |
1290 | { \ | 1310 | { \ |
1291 | if (0 != n) \ | 1311 | if (0 != n) \ |
1292 | { \ | 1312 | { \ |
1293 | (void) memcpy (dst, src, n); \ | 1313 | (void) memcpy (dst, src, n); \ |
1294 | } \ | 1314 | } \ |
1295 | } while (0) | 1315 | } while (0) |
1296 | 1316 | ||
1297 | 1317 | ||
1318 | /* *INDENT-OFF* */ | ||
1298 | /** | 1319 | /** |
1299 | * @ingroup memory | 1320 | * @ingroup memory |
1300 | * Allocate a size @a n array with structs or unions of the given @a type. | 1321 | * Allocate a size @a n array with structs or unions of the given @a type. |
@@ -1308,6 +1329,7 @@ GNUNET_is_zero_ (const void *a, | |||
1308 | GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \ | 1329 | GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \ |
1309 | (type *) GNUNET_malloc ((n) * sizeof(type)); \ | 1330 | (type *) GNUNET_malloc ((n) * sizeof(type)); \ |
1310 | }) | 1331 | }) |
1332 | /* *INDENT-ON* */ | ||
1311 | 1333 | ||
1312 | /** | 1334 | /** |
1313 | * @ingroup memory | 1335 | * @ingroup memory |
@@ -1319,7 +1341,7 @@ GNUNET_is_zero_ (const void *a, | |||
1319 | * @param type name of the struct or union, i.e. pass 'struct Foo'. | 1341 | * @param type name of the struct or union, i.e. pass 'struct Foo'. |
1320 | */ | 1342 | */ |
1321 | #define GNUNET_new_array_2d(n, m, type) \ | 1343 | #define GNUNET_new_array_2d(n, m, type) \ |
1322 | (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__) | 1344 | (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__) |
1323 | 1345 | ||
1324 | /** | 1346 | /** |
1325 | * @ingroup memory | 1347 | * @ingroup memory |
@@ -1332,7 +1354,8 @@ GNUNET_is_zero_ (const void *a, | |||
1332 | * @param type name of the struct or union, i.e. pass 'struct Foo'. | 1354 | * @param type name of the struct or union, i.e. pass 'struct Foo'. |
1333 | */ | 1355 | */ |
1334 | #define GNUNET_new_array_3d(n, m, o, type) \ | 1356 | #define GNUNET_new_array_3d(n, m, o, type) \ |
1335 | (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof(type), __FILE__, __LINE__) | 1357 | (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof(type), __FILE__, \ |
1358 | __LINE__) | ||
1336 | 1359 | ||
1337 | /** | 1360 | /** |
1338 | * @ingroup memory | 1361 | * @ingroup memory |
@@ -1364,7 +1387,7 @@ GNUNET_is_zero_ (const void *a, | |||
1364 | * @return pointer to size bytes of memory, NULL if we do not have enough memory | 1387 | * @return pointer to size bytes of memory, NULL if we do not have enough memory |
1365 | */ | 1388 | */ |
1366 | #define GNUNET_malloc_large(size) \ | 1389 | #define GNUNET_malloc_large(size) \ |
1367 | GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__) | 1390 | GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__) |
1368 | 1391 | ||
1369 | 1392 | ||
1370 | /** | 1393 | /** |
@@ -1377,7 +1400,7 @@ GNUNET_is_zero_ (const void *a, | |||
1377 | * @return pointer to size bytes of memory | 1400 | * @return pointer to size bytes of memory |
1378 | */ | 1401 | */ |
1379 | #define GNUNET_realloc(ptr, size) \ | 1402 | #define GNUNET_realloc(ptr, size) \ |
1380 | GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__) | 1403 | GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__) |
1381 | 1404 | ||
1382 | 1405 | ||
1383 | /** | 1406 | /** |
@@ -1404,8 +1427,8 @@ GNUNET_is_zero_ (const void *a, | |||
1404 | * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier. NULL is allowed. | 1427 | * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier. NULL is allowed. |
1405 | */ | 1428 | */ |
1406 | #define GNUNET_free(ptr) do { \ | 1429 | #define GNUNET_free(ptr) do { \ |
1407 | GNUNET_xfree_ (ptr, __FILE__, __LINE__); \ | 1430 | GNUNET_xfree_ (ptr, __FILE__, __LINE__); \ |
1408 | ptr = NULL; \ | 1431 | ptr = NULL; \ |
1409 | } while (0) | 1432 | } while (0) |
1410 | 1433 | ||
1411 | 1434 | ||
@@ -1419,6 +1442,7 @@ GNUNET_is_zero_ (const void *a, | |||
1419 | */ | 1442 | */ |
1420 | #define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__) | 1443 | #define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__) |
1421 | 1444 | ||
1445 | |||
1422 | /** | 1446 | /** |
1423 | * @ingroup memory | 1447 | * @ingroup memory |
1424 | * Wrapper around #GNUNET_xstrndup_. Makes a partial copy of the string | 1448 | * Wrapper around #GNUNET_xstrndup_. Makes a partial copy of the string |
@@ -1429,7 +1453,7 @@ GNUNET_is_zero_ (const void *a, | |||
1429 | * @return a partial copy of the string including zero-termination | 1453 | * @return a partial copy of the string including zero-termination |
1430 | */ | 1454 | */ |
1431 | #define GNUNET_strndup(a, length) \ | 1455 | #define GNUNET_strndup(a, length) \ |
1432 | GNUNET_xstrndup_ (a, length, __FILE__, __LINE__) | 1456 | GNUNET_xstrndup_ (a, length, __FILE__, __LINE__) |
1433 | 1457 | ||
1434 | /** | 1458 | /** |
1435 | * @ingroup memory | 1459 | * @ingroup memory |
@@ -1467,12 +1491,12 @@ GNUNET_is_zero_ (const void *a, | |||
1467 | * free the vector (then, arr will be NULL afterwards). | 1491 | * free the vector (then, arr will be NULL afterwards). |
1468 | */ | 1492 | */ |
1469 | #define GNUNET_array_grow(arr, size, tsize) \ | 1493 | #define GNUNET_array_grow(arr, size, tsize) \ |
1470 | GNUNET_xgrow_ ((void **) &(arr), \ | 1494 | GNUNET_xgrow_ ((void **) &(arr), \ |
1471 | sizeof((arr)[0]), \ | 1495 | sizeof((arr)[0]), \ |
1472 | &size, \ | 1496 | &size, \ |
1473 | tsize, \ | 1497 | tsize, \ |
1474 | __FILE__, \ | 1498 | __FILE__, \ |
1475 | __LINE__) | 1499 | __LINE__) |
1476 | 1500 | ||
1477 | /** | 1501 | /** |
1478 | * @ingroup memory | 1502 | * @ingroup memory |
@@ -1488,12 +1512,12 @@ GNUNET_is_zero_ (const void *a, | |||
1488 | * @param element the element that will be appended to the array | 1512 | * @param element the element that will be appended to the array |
1489 | */ | 1513 | */ |
1490 | #define GNUNET_array_append(arr, len, element) \ | 1514 | #define GNUNET_array_append(arr, len, element) \ |
1491 | do \ | 1515 | do \ |
1492 | { \ | 1516 | { \ |
1493 | GNUNET_assert ((len) + 1 > (len)); \ | 1517 | GNUNET_assert ((len) + 1 > (len)); \ |
1494 | GNUNET_array_grow (arr, len, len + 1); \ | 1518 | GNUNET_array_grow (arr, len, len + 1); \ |
1495 | (arr) [len - 1] = element; \ | 1519 | (arr) [len - 1] = element; \ |
1496 | } while (0) | 1520 | } while (0) |
1497 | 1521 | ||
1498 | 1522 | ||
1499 | /** | 1523 | /** |
@@ -1520,15 +1544,15 @@ GNUNET_is_zero_ (const void *a, | |||
1520 | 1544 | ||
1521 | */ | 1545 | */ |
1522 | #define GNUNET_array_concatenate(arr1, len1, arr2, len2) \ | 1546 | #define GNUNET_array_concatenate(arr1, len1, arr2, len2) \ |
1523 | do \ | 1547 | do \ |
1524 | { \ | 1548 | { \ |
1525 | const typeof (*arr2) * _a1 = (arr1); \ | 1549 | const typeof (*arr2) * _a1 = (arr1); \ |
1526 | const typeof (*arr1) * _a2 = (arr2); \ | 1550 | const typeof (*arr1) * _a2 = (arr2); \ |
1527 | GNUNET_assert ((len1) + (len2) >= (len1)); \ | 1551 | GNUNET_assert ((len1) + (len2) >= (len1)); \ |
1528 | GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \ | 1552 | GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \ |
1529 | GNUNET_array_grow (arr1, len1, (len1) + (len2)); \ | 1553 | GNUNET_array_grow (arr1, len1, (len1) + (len2)); \ |
1530 | memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \ | 1554 | memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \ |
1531 | } while (0) | 1555 | } while (0) |
1532 | 1556 | ||
1533 | 1557 | ||
1534 | /** | 1558 | /** |
@@ -1579,7 +1603,9 @@ __attribute__ ((format (printf, 2, 3))); | |||
1579 | * @return allocated memory, never NULL | 1603 | * @return allocated memory, never NULL |
1580 | */ | 1604 | */ |
1581 | void * | 1605 | void * |
1582 | GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber); | 1606 | GNUNET_xmalloc_ (size_t size, |
1607 | const char *filename, | ||
1608 | int linenumber); | ||
1583 | 1609 | ||
1584 | 1610 | ||
1585 | /** | 1611 | /** |
@@ -1659,7 +1685,9 @@ GNUNET_xmemdup_ (const void *buf, | |||
1659 | * @return pointer to size bytes of memory, NULL if we do not have enough memory | 1685 | * @return pointer to size bytes of memory, NULL if we do not have enough memory |
1660 | */ | 1686 | */ |
1661 | void * | 1687 | void * |
1662 | GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber); | 1688 | GNUNET_xmalloc_unchecked_ (size_t size, |
1689 | const char *filename, | ||
1690 | int linenumber); | ||
1663 | 1691 | ||
1664 | 1692 | ||
1665 | /** | 1693 | /** |
@@ -1667,7 +1695,10 @@ GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber); | |||
1667 | * memory is available. | 1695 | * memory is available. |
1668 | */ | 1696 | */ |
1669 | void * | 1697 | void * |
1670 | GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber); | 1698 | GNUNET_xrealloc_ (void *ptr, |
1699 | size_t n, | ||
1700 | const char *filename, | ||
1701 | int linenumber); | ||
1671 | 1702 | ||
1672 | 1703 | ||
1673 | /** | 1704 | /** |
@@ -1680,7 +1711,9 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber); | |||
1680 | * @param linenumber line where this call is being made (for debugging) | 1711 | * @param linenumber line where this call is being made (for debugging) |
1681 | */ | 1712 | */ |
1682 | void | 1713 | void |
1683 | GNUNET_xfree_ (void *ptr, const char *filename, int linenumber); | 1714 | GNUNET_xfree_ (void *ptr, |
1715 | const char *filename, | ||
1716 | int linenumber); | ||
1684 | 1717 | ||
1685 | 1718 | ||
1686 | /** | 1719 | /** |
@@ -1691,7 +1724,9 @@ GNUNET_xfree_ (void *ptr, const char *filename, int linenumber); | |||
1691 | * @return the duplicated string | 1724 | * @return the duplicated string |
1692 | */ | 1725 | */ |
1693 | char * | 1726 | char * |
1694 | GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber); | 1727 | GNUNET_xstrdup_ (const char *str, |
1728 | const char *filename, | ||
1729 | int linenumber); | ||
1695 | 1730 | ||
1696 | /** | 1731 | /** |
1697 | * Dup partially a string. Don't call GNUNET_xstrndup_ directly. Use the #GNUNET_strndup macro. | 1732 | * Dup partially a string. Don't call GNUNET_xstrndup_ directly. Use the #GNUNET_strndup macro. |
@@ -1861,6 +1896,8 @@ enum GNUNET_SCHEDULER_Priority | |||
1861 | }; | 1896 | }; |
1862 | 1897 | ||
1863 | 1898 | ||
1899 | /* *INDENT-OFF* */ | ||
1900 | |||
1864 | #if 0 /* keep Emacsens' auto-indent happy */ | 1901 | #if 0 /* keep Emacsens' auto-indent happy */ |
1865 | { | 1902 | { |
1866 | #endif | 1903 | #endif |
@@ -1869,5 +1906,3 @@ enum GNUNET_SCHEDULER_Priority | |||
1869 | #endif | 1906 | #endif |
1870 | 1907 | ||
1871 | #endif /* GNUNET_COMMON_H */ | 1908 | #endif /* GNUNET_COMMON_H */ |
1872 | |||
1873 | /** @} */ /* end of group addition */ | ||