Krolyxon
Commit 14d1daf

Branches

Refs →

nsxivutil.h

81 lines · 2.0 KB · Objective-C

1/* sxiv: util.h
2 * Copyright (c) 2011 Bert Muennich <muennich at informatik.hu-berlin.de>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#ifndef UTIL_H
20#define UTIL_H
21
22#include <stdio.h>
23#include <stdarg.h>
24#include <dirent.h>
25
26#ifndef MIN
27#define MIN(a,b) ((a) < (b) ? (a) : (b))
28#endif
29#ifndef MAX
30#define MAX(a,b) ((a) > (b) ? (a) : (b))
31#endif
32
33#define ARRLEN(a) (sizeof(a) / sizeof(a[0]))
34
35#define TIMEDIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec) * 1000 + \
36 ((t1)->tv_usec - (t2)->tv_usec) / 1000)
37
38#define MSEC_TO_TIMEVAL(t,tv) { \
39 (tv)->tv_sec = (t) / 1000; \
40 (tv)->tv_usec = (t) % 1000 * 1000; \
41}
42
43#define MSEC_ADD_TO_TIMEVAL(t,tv) { \
44 (tv)->tv_sec += (t) / 1000; \
45 (tv)->tv_usec += (t) % 1000 * 1000; \
46}
47
48#ifndef TIMESPEC_TO_TIMEVAL
49#define TIMESPEC_TO_TIMEVAL(tv,ts) { \
50 (tv)->tv_sec = (ts)->tv_sec; \
51 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
52}
53#endif
54
55typedef struct {
56 DIR *dir;
57 char *name;
58 int d;
59
60 char **stack;
61 int stcap;
62 int stlen;
63} r_dir_t;
64
65void* s_malloc(size_t);
66void* s_realloc(void*, size_t);
67char* s_strdup(char*);
68
69void warn(const char*, ...);
70void die(const char*, ...);
71
72void size_readable(float*, const char**);
73
74char* absolute_path(const char*);
75
76int r_opendir(r_dir_t*, const char*);
77int r_closedir(r_dir_t*);
78char* r_readdir(r_dir_t*);
79int r_mkdir(const char *);
80
81#endif /* UTIL_H */