Krolyxon
Commit dcd04e5

Branches

Refs →

nsxivutil.h

77 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
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, 5th 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#define ABS(a) ((a) < 0 ? (-(a)) : (a))
27#define MIN(a,b) ((a) < (b) ? (a) : (b))
28#define MAX(a,b) ((a) > (b) ? (a) : (b))
29#define LEN(a) (sizeof(a) / sizeof(a[0]))
30
31#define TIMEDIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec) * 1000 + \
32 ((t1)->tv_usec - (t2)->tv_usec) / 1000)
33
34#define MSEC_TO_TIMEVAL(t,tv) { \
35 (tv)->tv_sec = (t) / 1000; \
36 (tv)->tv_usec = (t) % 1000 * 1000; \
37}
38
39#define MSEC_ADD_TO_TIMEVAL(t,tv) { \
40 (tv)->tv_sec += (t) / 1000; \
41 (tv)->tv_usec += (t) % 1000 * 1000; \
42}
43
44#ifndef TIMESPEC_TO_TIMEVAL
45#define TIMESPEC_TO_TIMEVAL(tv,ts) { \
46 (tv)->tv_sec = (ts)->tv_sec; \
47 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
48}
49#endif
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
68void size_readable(float*, const char**);
69
70char* absolute_path(const char*);
71
72int r_opendir(r_dir_t*, const char*);
73int r_closedir(r_dir_t*);
74char* r_readdir(r_dir_t*);
75int r_mkdir(const char *);
76
77#endif /* UTIL_H */