aboutsummaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
authorBert Münnich <ber.t@gmx.com>2011-09-29 10:16:13 +0200
committerBert Münnich <ber.t@gmx.com>2011-09-29 10:16:13 +0200
commit22d4e991d5726ca034924fa697a32a42578202c2 (patch)
tree6bc19435e00edfd22b824cabdaa20310af2bd384 /util.h
parentd369f10aa56deafbc1816037d5a30af2f9bdbc50 (diff)
Transformed function macros in util.h to inline functions
Diffstat (limited to 'util.h')
-rw-r--r--util.h41
1 files changed, 26 insertions, 15 deletions
diff --git a/util.h b/util.h
index ff749a5..7bd6a61 100644
--- a/util.h
+++ b/util.h
@@ -22,8 +22,11 @@
#include <stdio.h>
#include <stdarg.h>
#include <dirent.h>
+#include <sys/time.h>
#include <sys/types.h>
+#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*);