Fix register_namespaces() documentation
[libisds.git] / src / utils.h
blob6781cb0a45db1b0e0b95f8059bcbdd1de5662cfd
1 #ifndef __ISDS_UTILS_H__
2 #define __ISDS_UTILS_H__
4 #include <stdlib.h>
5 #include <stdarg.h>
6 #include <stdio.h>
8 /* _hidden macro marks library private symbols. GCC can exclude them from global
9 * symbols table */
10 #if defined(__GNUC__) && (__GNUC__ >= 4)
11 #define _hidden __attribute__((visibility("hidden")))
12 #else
13 #define _hidden
14 #endif
16 /* PANIC macro aborts current proces without any clean up.
17 * Use it as last resort fatal error solution */
18 #define PANIC(message) { \
19 if (stderr != NULL ) fprintf(stderr, \
20 "LIBISDS PANIC (%s:%d): %s\n", __FILE__, __LINE__, (message)); \
21 abort(); \
24 /* Concatenate two strings into newly allocated buffer.
25 * You must free() them, when you don't need it anymore.
26 * Any of the arguments can be NULL meaning empty string.
27 * In case of error returns NULL.
28 * Empty string is always returned as allocated empty string. */
29 char *astrcat(const char *first, const char *second);
31 /* Concatenate three strings into newly allocated buffer.
32 * You must free() them, when you don't need it anymore.
33 * Any of the arguments can be NULL meaning empty string.
34 * In case of error returns NULL.
35 * Empty string is always returned as allocated empty string. */
36 char *astrcat3(const char *first, const char *second,
37 const char *third);
39 /* Print formated string into automtically reallocated @uffer.
40 * @buffer automatically reallocated buffer. Must be &NULL or preallocated
41 * memory.
42 * @format format string as for printf(3)
43 * @ap list of variadic arguments, after call will be in udefined state
44 * @Returns number of bytes printed. In case of errror, -1 and NULL @buffer*/
45 int isds_vasprintf(char **buffer, const char *format, va_list ap);
47 /* Print formated string into automtically reallocated @uffer.
48 * @buffer automatically reallocated buffer. Must be &NULL or preallocated
49 * memory.
50 * @format format string as for printf(3)
51 * @... variadic arguments
52 * @Returns number of bytes printed. In case of errror, -1 and NULL @buffer*/
53 int isds_asprintf(char **buffer, const char *format, ...);
55 /* Converts UTF8 string into locale encoded string.
56 * @utf string int UTF-8 terminated by zero byte
57 * @return allocated string encoded in locale specific encoding. You must free
58 * it. In case of error or NULL @utf returns NULL. */
59 char *utf82locale(const char *utf);
61 /* Encode given data into MIME Base64 encoded zero terminated string.
62 * @plain are input data (binary stream)
63 * @length is length of @plain data in bytes
64 * @return allocated string of base64 encoded plain data or NULL in case of
65 * error. You must free it. */
66 char *b64encode(const void *plain, const size_t length);
68 /* Decode given data from MIME Base64 encoded zero terminated string to binary
69 * stream.
70 * @encoded are input data (Base64 zero terminated string)
71 * @plain are automatically realocated output data (binary stream). You must
72 * free it. Will be freed in case of error.
73 * @return length of @plain data in bytes or (size_t) -1 in case of decoding
74 * failure. */
75 size_t b64decode(const char *encoded, void **plain);
77 /* Switches time zone to UTC.
78 * XXX: This is not reentrant and not thread-safe */
79 void switch_tz_to_utc(void);
81 /* Switches time zone to original value.
82 * XXX: This is not reentrant and not thread-safe */
83 void switch_tz_to_native(void);
85 /* Free() and set to NULL pointed memory */
86 #define zfree(memory) { \
87 free(memory); \
88 (memory) = NULL; \
91 #endif