Krolyxon
Commit 0a91ede

Branches

Refs →

nsxivutil.h

80 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#include <sys/types.h>
26
27#ifndef MIN
28#define MIN(a,b) ((a) < (b) ? (a) : (b))
29#endif
30#ifndef MAX
31#define MAX(a,b) ((a) > (b) ? (a) : (b))
32#endif
33
34#define ARRLEN(a) (sizeof(a) / sizeof((a)[0]))
35
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
51typedef struct {
52 DIR *dir;
53 char *name;
54 int d;
55
56 char **stack;
57 int stcap;
58 int stlen;
59} r_dir_t;
60
61void* s_malloc(size_t);
62void* s_realloc(void*, size_t);
63char* s_strdup(char*);
64
65void warn(const char*, ...);
66void die(const char*, ...);
67
68ssize_t get_line(char**, size_t*, FILE*);
69
70void size_readable(float*, const char**);
71void time_readable(float*, const char**);
72
73char* absolute_path(const char*);
74
75int r_opendir(r_dir_t*, const char*);
76int r_closedir(r_dir_t*);
77char* r_readdir(r_dir_t*);
78int r_mkdir(const char *);
79
80#endif /* UTIL_H */