aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmdsserver/macros.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-12-09 04:14:07 +0100
committerMattias Andrée <maandree@operamail.com>2014-12-09 04:14:07 +0100
commit187fc87408446ad2bb5eab3e3d57535f3c6662e1 (patch)
treecc65039fcc2e8de070db938f59cfe8c9c1dd0b16 /src/libmdsserver/macros.h
parenttypo (diff)
downloadmds-187fc87408446ad2bb5eab3e3d57535f3c6662e1.tar.gz
mds-187fc87408446ad2bb5eab3e3d57535f3c6662e1.tar.bz2
mds-187fc87408446ad2bb5eab3e3d57535f3c6662e1.tar.xz
make some macros easiler on the syntax
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/libmdsserver/macros.h68
1 files changed, 37 insertions, 31 deletions
diff --git a/src/libmdsserver/macros.h b/src/libmdsserver/macros.h
index 89e47fa..40d68d0 100644
--- a/src/libmdsserver/macros.h
+++ b/src/libmdsserver/macros.h
@@ -142,7 +142,7 @@
* @return [type] A slot that can be set or get
*/
#define buf_cast(buffer, type, index) \
- ((type*)(buffer))[index]
+ (((type*)(buffer))[index])
/**
@@ -155,7 +155,7 @@
* @return variable: The new value of the element
*/
#define buf_set(buffer, type, index, variable) \
- ((type*)(buffer))[index] = (variable)
+ (((type*)(buffer))[index] = (variable))
/**
@@ -168,7 +168,7 @@
* @return variable: The value of the element
*/
#define buf_get(buffer, type, index, variable) \
- variable = ((const type*)(buffer))[index]
+ (variable = ((const type*)(buffer))[index])
/**
@@ -180,7 +180,7 @@
* @return buffer: The buffer
*/
#define buf_next(buffer, type, count) \
- buffer += (count) * sizeof(type) / sizeof(char)
+ (buffer += (count) * sizeof(type) / sizeof(char))
/**
@@ -192,7 +192,7 @@
* @return buffer: The buffer
*/
#define buf_prev(buffer, type, count) \
- buffer -= (count) * sizeof(type) / sizeof(char)
+ (buffer -= (count) * sizeof(type) / sizeof(char))
/**
@@ -205,8 +205,8 @@
* @return variable: The new value of the element
*/
#define buf_set_next(buffer, type, variable) \
- buf_set(buffer, type, 0, variable), \
- buf_next(buffer, type, 1)
+ (buf_set(buffer, type, 0, variable), \
+ buf_next(buffer, type, 1))
/**
@@ -219,8 +219,8 @@
* @return variable: The value of the element
*/
#define buf_get_next(buffer, type, variable) \
- buf_get(buffer, type, 0, variable), \
- buf_next(buffer, type, 1)
+ (buf_get(buffer, type, 0, variable), \
+ buf_next(buffer, type, 1))
/**
@@ -273,24 +273,26 @@
*
* @param condition The condition, it should evaluate the variable `fd`
*/
-#define close_files(condition) \
-{ \
- DIR* dir = opendir(SELF_FD); \
- struct dirent* file; \
- \
- if (dir == NULL) \
- perror(*argv); /* Well, that is just unfortunate, but we cannot really do anything. */ \
- else \
- while ((file = readdir(dir)) != NULL) \
- if (strcmp(file->d_name, ".") && strcmp(file->d_name, "..")) \
- { \
- int fd = atoi(file->d_name); \
- if (condition) \
- close(fd); \
- } \
- \
- closedir(dir); \
-}
+#define close_files(condition) \
+ do \
+ { \
+ DIR* dir = opendir(SELF_FD); \
+ struct dirent* file; \
+ \
+ if (dir == NULL) \
+ perror(*argv); /* Well, that is just unfortunate, but we cannot really do anything. */ \
+ else \
+ while ((file = readdir(dir)) != NULL) \
+ if (strcmp(file->d_name, ".") && strcmp(file->d_name, "..")) \
+ { \
+ int fd = atoi(file->d_name); \
+ if (condition) \
+ close(fd); \
+ } \
+ \
+ closedir(dir); \
+ } \
+ while (0)
/**
@@ -300,10 +302,14 @@
* @param elements:size_t The number of elements, in the array, to free
* @scope i:size_t The variable `i` must be declared as `size_t` and avaiable for use
*/
-#define xfree(array, elements) \
- for (i = 0; i < elements; i++) \
- free((array)[i]); \
- free(array)
+#define xfree(array, elements) \
+ do \
+ { \
+ for (i = 0; i < (elements); i++) \
+ free((array)[i]); \
+ free(array), (array) = NULL; \
+ } \
+ while (0)
/**