Transformed function macros in util.h to inline functions
This commit is contained in:
parent
d369f10aa5
commit
22d4e991d5
2
Makefile
2
Makefile
@ -1,4 +1,4 @@
|
||||
VERSION = git-20110928
|
||||
VERSION = git-20110929
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -pedantic -O2
|
||||
|
4
image.c
4
image.c
@ -303,11 +303,11 @@ bool img_load(img_t *img, const fileinfo_t *file) {
|
||||
(void) fmt;
|
||||
|
||||
#if EXIF_SUPPORT
|
||||
if (STREQ(fmt, "jpeg"))
|
||||
if (streq(fmt, "jpeg"))
|
||||
exif_auto_orientate(file);
|
||||
#endif
|
||||
#if GIF_SUPPORT
|
||||
if (STREQ(fmt, "gif"))
|
||||
if (streq(fmt, "gif"))
|
||||
img_load_gif(img, file);
|
||||
#endif
|
||||
|
||||
|
6
main.c
6
main.c
@ -144,7 +144,7 @@ void set_timeout(timeout_f handler, int time, bool overwrite) {
|
||||
if (timeouts[i].handler == handler) {
|
||||
if (!timeouts[i].active || overwrite) {
|
||||
gettimeofday(&timeouts[i].when, 0);
|
||||
MSEC_ADD_TO_TIMEVAL(time, &timeouts[i].when);
|
||||
tv_add_msec(&timeouts[i].when, time);
|
||||
timeouts[i].active = true;
|
||||
}
|
||||
return;
|
||||
@ -170,7 +170,7 @@ bool check_timeouts(struct timeval *t) {
|
||||
gettimeofday(&now, 0);
|
||||
while (i < ARRLEN(timeouts)) {
|
||||
if (timeouts[i].active) {
|
||||
tdiff = TIMEDIFF(&timeouts[i].when, &now);
|
||||
tdiff = tv_diff(&timeouts[i].when, &now);
|
||||
if (tdiff <= 0) {
|
||||
timeouts[i].active = false;
|
||||
if (timeouts[i].handler)
|
||||
@ -183,7 +183,7 @@ bool check_timeouts(struct timeval *t) {
|
||||
i++;
|
||||
}
|
||||
if (tmin > 0 && t)
|
||||
MSEC_TO_TIMEVAL(tmin, t);
|
||||
tv_set_msec(t, tmin);
|
||||
return tmin > 0;
|
||||
}
|
||||
|
||||
|
@ -140,5 +140,5 @@ void parse_options(int argc, char **argv) {
|
||||
_options.filenames = argv + optind;
|
||||
_options.filecnt = argc - optind;
|
||||
_options.from_stdin = _options.filecnt == 1 &&
|
||||
STREQ(_options.filenames[0], "-");
|
||||
streq(_options.filenames[0], "-");
|
||||
}
|
||||
|
2
thumbs.c
2
thumbs.c
@ -255,7 +255,7 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file,
|
||||
(void) fmt;
|
||||
|
||||
#if EXIF_SUPPORT
|
||||
if (!cache_hit && STREQ(fmt, "jpeg"))
|
||||
if (!cache_hit && streq(fmt, "jpeg"))
|
||||
exif_auto_orientate(file);
|
||||
#endif
|
||||
|
||||
|
2
util.c
2
util.c
@ -270,7 +270,7 @@ char* r_readdir(r_dir_t *rdir) {
|
||||
|
||||
while (1) {
|
||||
if (rdir->dir && (dentry = readdir(rdir->dir))) {
|
||||
if (STREQ(dentry->d_name, ".") || STREQ(dentry->d_name, ".."))
|
||||
if (streq(dentry->d_name, ".") || streq(dentry->d_name, ".."))
|
||||
continue;
|
||||
|
||||
len = strlen(rdir->name) + strlen(dentry->d_name) + 2;
|
||||
|
41
util.h
41
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*);
|
||||
|
Loading…
Reference in New Issue
Block a user