Krolyxon
Commit 878d970

Branches

Refs →

nsxivutil.h

80 lines · 1.9 KB · Objective-C

1/* Copyright 2011 Bert Muennich
2 *
3 * This file is part of sxiv.
4 *
5 * sxiv is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 2 of the License,
8 * or (at your option) any later version.
9 *
10 * sxiv is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef UTIL_H
20#define UTIL_H
21
22#include <stdio.h>
23#include <stdarg.h>
24#include <dirent.h>
25#include <sys/time.h>
26#include <sys/types.h>
27
28#include "types.h"
29
30#ifndef MIN
31#define MIN(a,b) ((a) < (b) ? (a) : (b))
32#endif
33#ifndef MAX
34#define MAX(a,b) ((a) > (b) ? (a) : (b))
35#endif
36
37#define ARRLEN(a) (sizeof(a) / sizeof((a)[0]))
38
39#define STREQ(s1,s2) (strcmp((s1), (s2)) == 0)
40
41#define TV_DIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec ) * 1000 + \
42 ((t1)->tv_usec - (t2)->tv_usec) / 1000)
43
44#define TV_SET_MSEC(tv,t) { \
45 (tv)->tv_sec = (t) / 1000; \
46 (tv)->tv_usec = (t) % 1000 * 1000; \
47}
48
49#define TV_ADD_MSEC(tv,t) { \
50 (tv)->tv_sec += (t) / 1000; \
51 (tv)->tv_usec += (t) % 1000 * 1000; \
52}
53
54typedef struct {
55 DIR *dir;
56 char *name;
57 int d;
58 bool recursive;
59
60 char **stack;
61 int stcap;
62 int stlen;
63} r_dir_t;
64
65extern const char *progname;
66
67void* emalloc(size_t);
68void* erealloc(void*, size_t);
69char* estrdup(const char*);
70
71void error(int, int, const char*, ...);
72
73void size_readable(float*, const char**);
74
75int r_opendir(r_dir_t*, const char*, bool);
76int r_closedir(r_dir_t*);
77char* r_readdir(r_dir_t*);
78int r_mkdir(char*);
79
80#endif /* UTIL_H */