From 22d4e991d5726ca034924fa697a32a42578202c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bert=20M=C3=BCnnich?= Date: Thu, 29 Sep 2011 10:16:13 +0200 Subject: Transformed function macros in util.h to inline functions --- util.h | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'util.h') diff --git a/util.h b/util.h index ff749a5..7bd6a61 100644 --- a/util.h +++ b/util.h @@ -22,8 +22,11 @@ #include #include #include +#include #include +#include "types.h" + #ifndef MIN #define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif @@ -33,21 +36,6 @@ #define ARRLEN(a) (sizeof(a) / sizeof((a)[0])) -#define STREQ(a,b) (!strcmp((a), (b))) - -#define TIMEDIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec) * 1000 + \ - ((t1)->tv_usec - (t2)->tv_usec) / 1000) - -#define MSEC_TO_TIMEVAL(t,tv) { \ - (tv)->tv_sec = (t) / 1000; \ - (tv)->tv_usec = (t) % 1000 * 1000; \ -} - -#define MSEC_ADD_TO_TIMEVAL(t,tv) { \ - (tv)->tv_sec += (t) / 1000; \ - (tv)->tv_usec += (t) % 1000 * 1000; \ -} - typedef struct { DIR *dir; char *name; @@ -58,6 +46,29 @@ typedef struct { int stlen; } r_dir_t; +static inline +bool streq(const char *a, const char *b) { + return strcmp(a, b) == 0; +} + +static inline +long tv_diff(const struct timeval *t1, const struct timeval *t2) { + return (t1->tv_sec - t2->tv_sec) * 1000 + + (t1->tv_usec - t2->tv_usec) / 1000; +} + +static inline +void tv_set_msec(struct timeval *t, int msec) { + t->tv_sec = msec / 1000; + t->tv_usec = msec % 1000 * 1000; +} + +static inline +void tv_add_msec(struct timeval *t, int msec) { + t->tv_sec += msec / 1000; + t->tv_usec += msec % 1000 * 1000; +} + void* s_malloc(size_t); void* s_realloc(void*, size_t); char* s_strdup(char*); -- cgit v1.2.3