Krolyxon
Commit 22d4e99

Branches

Refs →

nsxiv22d4e99

Transformed function macros in util.h to inline functions

Author
Bert Münnich
Date
2011-09-29 10:16 +0200
Parent
d369f10
Commit
22d4e991d5726ca034924fa697a32a42578202c2

+35 −24

7 files changed

  1. M Makefile +1 −1
  2. M image.c +2 −2
  3. M main.c +3 −3
  4. M options.c +1 −1
  5. M thumbs.c +1 −1
  6. M util.c +1 −1
  7. M util.h +26 −15
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION = git-20110928
1+VERSION = git-20110929
22
33 CC = gcc
44 CFLAGS = -Wall -pedantic -O2
M image.c View
@@ -303,11 +303,11 @@ bool img_load(img_t *img, const fileinfo_t *file) {
303303 (void) fmt;
304304
305305 #if EXIF_SUPPORT
306− if (STREQ(fmt, "jpeg"))
306+ if (streq(fmt, "jpeg"))
307307 exif_auto_orientate(file);
308308 #endif
309309 #if GIF_SUPPORT
310− if (STREQ(fmt, "gif"))
310+ if (streq(fmt, "gif"))
311311 img_load_gif(img, file);
312312 #endif
313313
M main.c View
@@ -144,7 +144,7 @@ void set_timeout(timeout_f handler, int time, bool overwrite) {
144144 if (timeouts[i].handler == handler) {
145145 if (!timeouts[i].active || overwrite) {
146146 gettimeofday(&timeouts[i].when, 0);
147− MSEC_ADD_TO_TIMEVAL(time, &timeouts[i].when);
147+ tv_add_msec(&timeouts[i].when, time);
148148 timeouts[i].active = true;
149149 }
150150 return;
@@ -170,7 +170,7 @@ bool check_timeouts(struct timeval *t) {
170170 gettimeofday(&now, 0);
171171 while (i < ARRLEN(timeouts)) {
172172 if (timeouts[i].active) {
173− tdiff = TIMEDIFF(&timeouts[i].when, &now);
173+ tdiff = tv_diff(&timeouts[i].when, &now);
174174 if (tdiff <= 0) {
175175 timeouts[i].active = false;
176176 if (timeouts[i].handler)
@@ -183,7 +183,7 @@ bool check_timeouts(struct timeval *t) {
183183 i++;
184184 }
185185 if (tmin > 0 && t)
186− MSEC_TO_TIMEVAL(tmin, t);
186+ tv_set_msec(t, tmin);
187187 return tmin > 0;
188188 }
189189
M options.c View
@@ -140,5 +140,5 @@ void parse_options(int argc, char **argv) {
140140 _options.filenames = argv + optind;
141141 _options.filecnt = argc - optind;
142142 _options.from_stdin = _options.filecnt == 1 &&
143− STREQ(_options.filenames[0], "-");
143+ streq(_options.filenames[0], "-");
144144 }
M thumbs.c View
@@ -255,7 +255,7 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file,
255255 (void) fmt;
256256
257257 #if EXIF_SUPPORT
258− if (!cache_hit && STREQ(fmt, "jpeg"))
258+ if (!cache_hit && streq(fmt, "jpeg"))
259259 exif_auto_orientate(file);
260260 #endif
261261
M util.c View
@@ -270,7 +270,7 @@ char* r_readdir(r_dir_t *rdir) {
270270
271271 while (1) {
272272 if (rdir->dir && (dentry = readdir(rdir->dir))) {
273− if (STREQ(dentry->d_name, ".") || STREQ(dentry->d_name, ".."))
273+ if (streq(dentry->d_name, ".") || streq(dentry->d_name, ".."))
274274 continue;
275275
276276 len = strlen(rdir->name) + strlen(dentry->d_name) + 2;
M util.h View
@@ -22,8 +22,11 @@
2222 #include <stdio.h>
2323 #include <stdarg.h>
2424 #include <dirent.h>
25+#include <sys/time.h>
2526 #include <sys/types.h>
2627
28+#include "types.h"
29+
2730 #ifndef MIN
2831 #define MIN(a,b) ((a) < (b) ? (a) : (b))
2932 #endif
@@ -33,21 +36,6 @@
3336
3437 #define ARRLEN(a) (sizeof(a) / sizeof((a)[0]))
3538
36−#define STREQ(a,b) (!strcmp((a), (b)))
37−
38−#define TIMEDIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec) * 1000 + \
39− ((t1)->tv_usec - (t2)->tv_usec) / 1000)
40−
41−#define MSEC_TO_TIMEVAL(t,tv) { \
42− (tv)->tv_sec = (t) / 1000; \
43− (tv)->tv_usec = (t) % 1000 * 1000; \
44−}
45−
46−#define MSEC_ADD_TO_TIMEVAL(t,tv) { \
47− (tv)->tv_sec += (t) / 1000; \
48− (tv)->tv_usec += (t) % 1000 * 1000; \
49−}
50−
5139 typedef struct {
5240 DIR *dir;
5341 char *name;
@@ -58,6 +46,29 @@ typedef struct {
5846 int stlen;
5947 } r_dir_t;
6048
49+static inline
50+bool streq(const char *a, const char *b) {
51+ return strcmp(a, b) == 0;
52+}
53+
54+static inline
55+long tv_diff(const struct timeval *t1, const struct timeval *t2) {
56+ return (t1->tv_sec - t2->tv_sec) * 1000 +
57+ (t1->tv_usec - t2->tv_usec) / 1000;
58+}
59+
60+static inline
61+void tv_set_msec(struct timeval *t, int msec) {
62+ t->tv_sec = msec / 1000;
63+ t->tv_usec = msec % 1000 * 1000;
64+}
65+
66+static inline
67+void tv_add_msec(struct timeval *t, int msec) {
68+ t->tv_sec += msec / 1000;
69+ t->tv_usec += msec % 1000 * 1000;
70+}
71+
6172 void* s_malloc(size_t);
6273 void* s_realloc(void*, size_t);
6374 char* s_strdup(char*);