2 This file is part of GNUnet.
3 (C) 2006, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_common.h
23 * @brief commonly used definitions; globals in this file
24 * are exempt from the rule that the module name ("common")
25 * must be part of the symbol name.
27 * @author Christian Grothoff
30 #ifndef GNUNET_COMMON_H
31 #define GNUNET_COMMON_H
34 #include <sys/socket.h>
37 #include <netinet/in.h>
52 #if 0 /* keep Emacsens' auto-indent happy */
58 * Version of the API (for entire gnunetutil.so library).
60 #define GNUNET_UTIL_VERSION 0x00090200
63 * Named constants for return values. The following
64 * invariants hold: "GNUNET_NO == 0" (to allow "if (GNUNET_NO)")
65 * "GNUNET_OK != GNUNET_SYSERR", "GNUNET_OK != GNUNET_NO", "GNUNET_NO != GNUNET_SYSERR"
66 * and finally "GNUNET_YES != GNUNET_NO".
69 #define GNUNET_SYSERR -1
73 #define GNUNET_MIN(a,b) (((a) < (b)) ? (a) : (b))
75 #define GNUNET_MAX(a,b) (((a) > (b)) ? (a) : (b))
77 /* some systems use one underscore only, and mingw uses no underscore... */
80 #define __BYTE_ORDER _BYTE_ORDER
83 #define __BYTE_ORDER BYTE_ORDER
89 #define __BIG_ENDIAN _BIG_ENDIAN
92 #define __BIG_ENDIAN BIG_ENDIAN
96 #ifndef __LITTLE_ENDIAN
98 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
101 #define __LITTLE_ENDIAN LITTLE_ENDIAN
110 # if __BYTE_ORDER == __LITTLE_ENDIAN
111 # define GNUNET_htobe16(x) __bswap_16 (x)
112 # define GNUNET_htole16(x) (x)
113 # define GNUNET_be16toh(x) __bswap_16 (x)
114 # define GNUNET_le16toh(x) (x)
116 # define GNUNET_htobe32(x) __bswap_32 (x)
117 # define GNUNET_htole32(x) (x)
118 # define GNUNET_be32toh(x) __bswap_32 (x)
119 # define GNUNET_le32toh(x) (x)
121 # define GNUNET_htobe64(x) __bswap_64 (x)
122 # define GNUNET_htole64(x) (x)
123 # define GNUNET_be64toh(x) __bswap_64 (x)
124 # define GNUNET_le64toh(x) (x)
126 # if __BYTE_ORDER == __BIG_ENDIAN
127 # define GNUNET_htobe16(x) (x)
128 # define GNUNET_htole16(x) __bswap_16 (x)
129 # define GNUNET_be16toh(x) (x)
130 # define GNUNET_le16toh(x) __bswap_16 (x)
132 # define GNUNET_htobe32(x) (x)
133 # define GNUNET_htole32(x) __bswap_32 (x)
134 # define GNUNET_be32toh(x) (x)
135 # define GNUNET_le32toh(x) __bswap_32 (x)
137 # define GNUNET_htobe64(x) (x)
138 # define GNUNET_htole64(x) __bswap_64 (x)
139 # define GNUNET_be64toh(x) (x)
140 # define GNUNET_le64toh(x) __bswap_64 (x)
147 * gcc-ism to get packed structs.
149 #define GNUNET_PACKED __attribute__((packed))
152 * gcc-ism to get gcc bitfield layout when compiling with -mms-bitfields
155 #define GNUNET_GCC_STRUCT_LAYOUT __attribute__((gcc_struct))
157 #define GNUNET_GCC_STRUCT_LAYOUT
161 * gcc-ism to force alignment; we use this to align char-arrays
162 * that may then be cast to 'struct's. See also gcc
165 #ifdef __BIGGEST_ALIGNMENT__
166 #define GNUNET_ALIGN __attribute__((aligned (__BIGGEST_ALIGNMENT__)))
168 #define GNUNET_ALIGN __attribute__((aligned (8)))
172 * gcc-ism to document unused arguments
174 #define GNUNET_UNUSED __attribute__((unused))
177 * gcc-ism to document functions that don't return
179 #define GNUNET_NORETURN __attribute__((noreturn))
184 * gcc 4.x-ism to pack structures even on W32 (to be used before structs);
185 * Using this would cause structs to be unaligned on the stack on Sparc,
186 * so we *only* use this on W32 (see #670578 from Debian); fortunately,
187 * W32 doesn't run on sparc anyway.
189 #define GNUNET_NETWORK_STRUCT_BEGIN \
190 _Pragma("pack(push)") \
194 * gcc 4.x-ism to pack structures even on W32 (to be used after structs)
195 * Using this would cause structs to be unaligned on the stack on Sparc,
196 * so we *only* use this on W32 (see #670578 from Debian); fortunately,
197 * W32 doesn't run on sparc anyway.
199 #define GNUNET_NETWORK_STRUCT_END _Pragma("pack(pop)")
202 #error gcc 4.x or higher required on W32 systems
206 * Define as empty, GNUNET_PACKED should suffice, but this won't work on W32
208 #define GNUNET_NETWORK_STRUCT_BEGIN
211 * Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;
213 #define GNUNET_NETWORK_STRUCT_END
216 /* ************************ super-general types *********************** */
218 GNUNET_NETWORK_STRUCT_BEGIN
221 * Header for all communications.
223 struct GNUNET_MessageHeader
227 * The length of the struct (in bytes, including the length field itself),
228 * in big-endian format.
230 uint16_t size GNUNET_PACKED;
233 * The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
235 uint16_t type GNUNET_PACKED;
241 * @brief 512-bit hashcode
243 struct GNUNET_HashCode
245 uint32_t bits[512 / 8 / sizeof (uint32_t)]; /* = 16 */
250 * The identity of the host (basically the SHA-512 hashcode of
253 struct GNUNET_PeerIdentity
255 struct GNUNET_HashCode hashPubKey;
257 GNUNET_NETWORK_STRUCT_END
260 * Function called with a filename.
263 * @param filename complete filename (absolute path)
264 * @return GNUNET_OK to continue to iterate,
265 * GNUNET_SYSERR to abort iteration with error!
267 typedef int (*GNUNET_FileNameCallback) (void *cls, const char *filename);
270 /* ****************************** logging ***************************** */
275 enum GNUNET_ErrorType
277 GNUNET_ERROR_TYPE_UNSPECIFIED = -1,
278 GNUNET_ERROR_TYPE_NONE = 0,
279 GNUNET_ERROR_TYPE_ERROR = 1,
280 GNUNET_ERROR_TYPE_WARNING = 2,
281 GNUNET_ERROR_TYPE_INFO = 4,
282 GNUNET_ERROR_TYPE_DEBUG = 8,
283 GNUNET_ERROR_TYPE_INVALID = 16,
284 GNUNET_ERROR_TYPE_BULK = 32
289 * User-defined handler for log messages.
292 * @param kind severeity
293 * @param component what component is issuing the message?
294 * @param date when was the message logged?
295 * @param message what is the message
297 typedef void (*GNUNET_Logger) (void *cls, enum GNUNET_ErrorType kind,
298 const char *component, const char *date,
299 const char *message);
303 * Get the number of log calls that are going to be skipped
305 * @return number of log calls to be ignored
308 GNUNET_get_log_skip ();
310 #if !defined(GNUNET_CULL_LOGGING)
312 GNUNET_get_log_call_status (int caller_level, const char *comp,
313 const char *file, const char *function, int line);
318 * @param kind how serious is the error?
319 * @param message what is the message (format string)
320 * @param ... arguments for format string
323 GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...);
326 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
327 #define _GNUNET_BOOLEAN_EXPR(expr) \
329 int _gnunet_boolean_var_; \
331 _gnunet_boolean_var_ = 1; \
333 _gnunet_boolean_var_ = 0; \
334 _gnunet_boolean_var_; \
336 #define GN_LIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR(expr), 1))
337 #define GN_UNLIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR(expr), 0))
339 #define GN_LIKELY(expr) (expr)
340 #define GN_UNLIKELY(expr) (expr)
343 #if !defined(GNUNET_LOG_CALL_STATUS)
344 #define GNUNET_LOG_CALL_STATUS -1
348 * Log function that specifies an alternative component.
349 * This function should be used by plugins.
351 * @param kind how serious is the error?
352 * @param comp component responsible for generating the message
353 * @param message what is the message (format string)
354 * @param ... arguments for format string
357 GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp,
358 const char *message, ...);
360 #if !defined(GNUNET_CULL_LOGGING)
361 #define GNUNET_log_from(kind,comp,...) do { int log_line = __LINE__;\
362 static int log_call_enabled = GNUNET_LOG_CALL_STATUS;\
363 if ((GNUNET_EXTRA_LOGGING > 0) || ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) { \
364 if (GN_UNLIKELY(log_call_enabled == -1))\
365 log_call_enabled = GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), (comp), __FILE__, __FUNCTION__, log_line); \
366 if (GN_UNLIKELY(GNUNET_get_log_skip () > 0)) { GNUNET_log_skip (-1, GNUNET_NO); }\
368 if (GN_UNLIKELY(log_call_enabled))\
369 GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \
374 #define GNUNET_log(kind,...) do { int log_line = __LINE__;\
375 static int log_call_enabled = GNUNET_LOG_CALL_STATUS;\
376 if ((GNUNET_EXTRA_LOGGING > 0) || ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) { \
377 if (GN_UNLIKELY(log_call_enabled == -1))\
378 log_call_enabled = GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), NULL, __FILE__, __FUNCTION__, log_line);\
379 if (GN_UNLIKELY(GNUNET_get_log_skip () > 0)) { GNUNET_log_skip (-1, GNUNET_NO); }\
381 if (GN_UNLIKELY(log_call_enabled))\
382 GNUNET_log_nocheck ((kind), __VA_ARGS__); \
387 #define GNUNET_log(...)
388 #define GNUNET_log_from(...)
393 * Abort the process, generate a core dump if possible.
396 GNUNET_abort (void) GNUNET_NORETURN;
399 * Ignore the next n calls to the log function.
401 * @param n number of log calls to ignore (could be negative)
402 * @param check_reset GNUNET_YES to assert that the log skip counter is currently zero
405 GNUNET_log_skip (int n, int check_reset);
411 * @param comp default component to use
412 * @param loglevel what types of messages should be logged
413 * @param logfile change logging to logfile (use NULL to keep stderr)
414 * @return GNUNET_OK on success, GNUNET_SYSERR if logfile could not be opened
417 GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile);
421 * Add a custom logger.
423 * @param logger log function
424 * @param logger_cls closure for logger
427 GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls);
431 * Remove a custom logger.
433 * @param logger log function
434 * @param logger_cls closure for logger
437 GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls);
441 * Convert a hash value to a string (for printing debug messages).
442 * This is one of the very few calls in the entire API that is
445 * @param hc the hash code
449 GNUNET_h2s (const struct GNUNET_HashCode * hc);
453 * Convert a hash value to a string (for printing debug messages).
454 * This prints all 104 characters of a hashcode!
455 * This is one of the very few calls in the entire API that is
458 * @param hc the hash code
462 GNUNET_h2s_full (const struct GNUNET_HashCode * hc);
466 * Convert a peer identity to a string (for printing debug messages).
467 * This is one of the very few calls in the entire API that is
470 * @param pid the peer identity
471 * @return string form of the pid; will be overwritten by next
472 * call to GNUNET_i2s.
475 GNUNET_i2s (const struct GNUNET_PeerIdentity *pid);
478 * Convert a peer identity to a string (for printing debug messages).
479 * This is one of the very few calls in the entire API that is
482 * @param pid the peer identity
483 * @return string form of the pid; will be overwritten by next
484 * call to GNUNET_i2s.
487 GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid);
490 * Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string
491 * (for printing debug messages). This is one of the very few calls
492 * in the entire API that is NOT reentrant!
494 * @param addr the address
495 * @param addrlen the length of the address
496 * @return nicely formatted string for the address
497 * will be overwritten by next call to GNUNET_a2s.
500 GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen);
503 * Convert error type to string.
505 * @param kind type to convert
506 * @return string corresponding to the type
509 GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
513 * Use this for fatal errors that cannot be handled
515 #define GNUNET_assert(cond) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Assertion failed at %s:%d.\n"), __FILE__, __LINE__); GNUNET_abort(); } } while(0)
518 * Use this for fatal errors that cannot be handled
520 #define GNUNET_assert_at(cond, f, l) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Assertion failed at %s:%d.\n"), f, l); GNUNET_abort(); } } while(0)
523 * Use this for internal assertion violations that are
524 * not fatal (can be handled) but should not occur.
526 #define GNUNET_break(cond) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Assertion failed at %s:%d.\n"), __FILE__, __LINE__); } } while(0)
529 * Use this for assertion violations caused by other
530 * peers (i.e. protocol violations). We do not want to
531 * confuse end-users (say, some other peer runs an
532 * older, broken or incompatible GNUnet version), but
533 * we still want to see these problems during
534 * development and testing. "OP == other peer".
536 #define GNUNET_break_op(cond) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, _("External protocol violation detected at %s:%d.\n"), __FILE__, __LINE__); } } while(0)
539 * Log an error message at log-level 'level' that indicates
540 * a failure of the command 'cmd' with the message given
541 * by strerror(errno).
543 #define GNUNET_log_strerror(level, cmd) do { GNUNET_log(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, STRERROR(errno)); } while(0)
546 * Log an error message at log-level 'level' that indicates
547 * a failure of the command 'cmd' with the message given
548 * by strerror(errno).
550 #define GNUNET_log_from_strerror(level, component, cmd) do { GNUNET_log_from (level, component, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, STRERROR(errno)); } while(0)
553 * Log an error message at log-level 'level' that indicates
554 * a failure of the command 'cmd' with the message given
555 * by strerror(errno).
557 #define GNUNET_log_strerror_file(level, cmd, filename) do { GNUNET_log(level, _("`%s' failed on file `%s' at %s:%d with error: %s\n"), cmd, filename,__FILE__, __LINE__, STRERROR(errno)); } while(0)
560 * Log an error message at log-level 'level' that indicates
561 * a failure of the command 'cmd' with the message given
562 * by strerror(errno).
564 #define GNUNET_log_from_strerror_file(level, component, cmd, filename) do { GNUNET_log_from (level, component, _("`%s' failed on file `%s' at %s:%d with error: %s\n"), cmd, filename,__FILE__, __LINE__, STRERROR(errno)); } while(0)
566 /* ************************* endianess conversion ****************** */
569 * Convert unsigned 64-bit integer to host-byte-order.
570 * @param n the value in network byte order
571 * @return the same value in host byte order
574 GNUNET_ntohll (uint64_t n);
577 * Convert unsigned 64-bit integer to network-byte-order.
578 * @param n the value in host byte order
579 * @return the same value in network byte order
582 GNUNET_htonll (uint64_t n);
585 * Convert double to network-byte-order.
586 * @param d the value in network byte order
587 * @return the same value in host byte order
590 GNUNET_hton_double (double d);
593 * Convert double to host-byte-order
594 * @param d the value in network byte order
595 * @return the same value in host byte order
598 GNUNET_ntoh_double (double d);
600 /* ************************* allocation functions ****************** */
603 * Maximum allocation with GNUNET_malloc macro.
605 #define GNUNET_MAX_MALLOC_CHECKED (1024 * 1024 * 40)
608 * Wrapper around malloc. Allocates size bytes of memory.
609 * The memory will be zero'ed out.
611 * @param size the number of bytes to allocate, must be
612 * smaller than 40 MB.
613 * @return pointer to size bytes of memory, never NULL (!)
615 #define GNUNET_malloc(size) GNUNET_xmalloc_(size, __FILE__, __LINE__)
618 * Allocate and initialize a block of memory.
620 * @param buf data to initalize the block with
621 * @param size the number of bytes in buf (and size of the allocation)
622 * @return pointer to size bytes of memory, never NULL (!)
624 #define GNUNET_memdup(buf,size) GNUNET_xmemdup_(buf, size, __FILE__, __LINE__)
627 * Wrapper around malloc. Allocates size bytes of memory.
628 * The memory will be zero'ed out.
630 * @param size the number of bytes to allocate
631 * @return pointer to size bytes of memory, NULL if we do not have enough memory
633 #define GNUNET_malloc_large(size) GNUNET_xmalloc_unchecked_(size, __FILE__, __LINE__)
636 * Wrapper around realloc. Rellocates size bytes of memory.
638 * @param ptr the pointer to reallocate
639 * @param size the number of bytes to reallocate
640 * @return pointer to size bytes of memory
642 #define GNUNET_realloc(ptr, size) GNUNET_xrealloc_(ptr, size, __FILE__, __LINE__)
645 * Wrapper around free. Frees the memory referred to by ptr.
646 * Note that is is generally better to free memory that was
647 * allocated with GNUNET_array_grow using GNUNET_array_grow(mem, size, 0) instead of GNUNET_free.
649 * @param ptr location where to free the memory. ptr must have
650 * been returned by GNUNET_strdup, GNUNET_strndup, GNUNET_malloc or GNUNET_array_grow earlier.
652 #define GNUNET_free(ptr) GNUNET_xfree_(ptr, __FILE__, __LINE__)
655 * Free the memory pointed to by ptr if ptr is not NULL.
656 * Equivalent to if (ptr!=null)GNUNET_free(ptr).
658 * @param ptr the location in memory to free
660 #define GNUNET_free_non_null(ptr) do { void * __x__ = ptr; if (__x__ != NULL) { GNUNET_free(__x__); } } while(0)
663 * Wrapper around GNUNET_strdup. Makes a copy of the zero-terminated string
666 * @param a pointer to a zero-terminated string
667 * @return a copy of the string including zero-termination
669 #define GNUNET_strdup(a) GNUNET_xstrdup_(a,__FILE__,__LINE__)
672 * Wrapper around GNUNET_strndup. Makes a partial copy of the string
675 * @param a pointer to a string
676 * @param length of the string to duplicate
677 * @return a partial copy of the string including zero-termination
679 #define GNUNET_strndup(a,length) GNUNET_xstrndup_(a,length,__FILE__,__LINE__)
682 * Grow a well-typed (!) array. This is a convenience
683 * method to grow a vector <tt>arr</tt> of size <tt>size</tt>
684 * to the new (target) size <tt>tsize</tt>.
687 * Example (simple, well-typed stack):
690 * static struct foo * myVector = NULL;
691 * static int myVecLen = 0;
693 * static void push(struct foo * elem) {
694 * GNUNET_array_grow(myVector, myVecLen, myVecLen+1);
695 * memcpy(&myVector[myVecLen-1], elem, sizeof(struct foo));
698 * static void pop(struct foo * elem) {
699 * if (myVecLen == 0) die();
700 * memcpy(elem, myVector[myVecLen-1], sizeof(struct foo));
701 * GNUNET_array_grow(myVector, myVecLen, myVecLen-1);
705 * @param arr base-pointer of the vector, may be NULL if size is 0;
706 * will be updated to reflect the new address. The TYPE of
707 * arr is important since size is the number of elements and
708 * not the size in bytes
709 * @param size the number of elements in the existing vector (number
710 * of elements to copy over)
711 * @param tsize the target size for the resulting vector, use 0 to
712 * free the vector (then, arr will be NULL afterwards).
714 #define GNUNET_array_grow(arr,size,tsize) GNUNET_xgrow_((void**)&arr, sizeof(arr[0]), &size, tsize, __FILE__, __LINE__)
717 * Append an element to a list (growing the
720 #define GNUNET_array_append(arr,size,element) do { GNUNET_array_grow(arr,size,size+1); arr[size-1] = element; } while(0)
723 * Like snprintf, just aborts if the buffer is of insufficient size.
725 * @param buf pointer to buffer that is written to
726 * @param size number of bytes in buf
727 * @param format format strings
728 * @param ... data for format string
729 * @return number of bytes written to buf or negative value on error
732 GNUNET_snprintf (char *buf, size_t size, const char *format, ...);
736 * Like asprintf, just portable.
738 * @param buf set to a buffer of sufficient size (allocated, caller must free)
739 * @param format format string (see printf, fprintf, etc.)
740 * @param ... data for format string
741 * @return number of bytes in "*buf" excluding 0-termination
744 GNUNET_asprintf (char **buf, const char *format, ...);
747 /* ************** internal implementations, use macros above! ************** */
750 * Allocate memory. Checks the return value, aborts if no more
751 * memory is available. Don't use GNUNET_xmalloc_ directly. Use the
752 * GNUNET_malloc macro.
753 * The memory will be zero'ed out.
755 * @param size number of bytes to allocate
756 * @param filename where is this call being made (for debugging)
757 * @param linenumber line where this call is being made (for debugging)
758 * @return allocated memory, never NULL
761 GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber);
765 * Allocate and initialize memory. Checks the return value, aborts if no more
766 * memory is available. Don't use GNUNET_xmemdup_ directly. Use the
767 * GNUNET_memdup macro.
769 * @param buf buffer to initialize from (must contain size bytes)
770 * @param size number of bytes to allocate
771 * @param filename where is this call being made (for debugging)
772 * @param linenumber line where this call is being made (for debugging)
773 * @return allocated memory, never NULL
776 GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename,
781 * Allocate memory. This function does not check if the allocation
782 * request is within reasonable bounds, allowing allocations larger
783 * than 40 MB. If you don't expect the possibility of very large
784 * allocations, use GNUNET_malloc instead. The memory will be zero'ed
787 * @param size number of bytes to allocate
788 * @param filename where is this call being made (for debugging)
789 * @param linenumber line where this call is being made (for debugging)
790 * @return pointer to size bytes of memory, NULL if we do not have enough memory
793 GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber);
796 * Reallocate memory. Checks the return value, aborts if no more
797 * memory is available.
800 GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber);
803 * Free memory. Merely a wrapper for the case that we
804 * want to keep track of allocations. Don't use GNUNET_xfree_
805 * directly. Use the GNUNET_free macro.
807 * @param ptr pointer to memory to free
808 * @param filename where is this call being made (for debugging)
809 * @param linenumber line where this call is being made (for debugging)
812 GNUNET_xfree_ (void *ptr, const char *filename, int linenumber);
816 * Dup a string. Don't call GNUNET_xstrdup_ directly. Use the GNUNET_strdup macro.
817 * @param str string to duplicate
818 * @param filename where is this call being made (for debugging)
819 * @param linenumber line where this call is being made (for debugging)
820 * @return the duplicated string
823 GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber);
826 * Dup partially a string. Don't call GNUNET_xstrndup_ directly. Use the GNUNET_strndup macro.
828 * @param str string to duplicate
829 * @param len length of the string to duplicate
830 * @param filename where is this call being made (for debugging)
831 * @param linenumber line where this call is being made (for debugging)
832 * @return the duplicated string
835 GNUNET_xstrndup_ (const char *str, size_t len, const char *filename,
839 * Grow an array, the new elements are zeroed out.
840 * Grows old by (*oldCount-newCount)*elementSize
841 * bytes and sets *oldCount to newCount.
843 * Don't call GNUNET_xgrow_ directly. Use the GNUNET_array_grow macro.
845 * @param old address of the pointer to the array
847 * @param elementSize the size of the elements of the array
848 * @param oldCount address of the number of elements in the *old array
849 * @param newCount number of elements in the new array, may be 0 (then *old will be NULL afterwards)
850 * @param filename where is this call being made (for debugging)
851 * @param linenumber line where this call is being made (for debugging)
854 GNUNET_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount,
855 unsigned int newCount, const char *filename, int linenumber);
859 * Create a copy of the given message.
861 * @param msg message to copy
862 * @return duplicate of the message
864 struct GNUNET_MessageHeader *
865 GNUNET_copy_message (const struct GNUNET_MessageHeader *msg);
868 #if __STDC_VERSION__ < 199901L
870 #define __func__ __FUNCTION__
872 #define __func__ "<unknown>"
879 #if 0 /* keep Emacsens' auto-indent happy */
889 #endif /*GNUNET_COMMON_H_ */