Krolyxon
Commit f2a3d73

Branches

Refs →

nsxivutil.h

85 lines · 2.1 KB · Objective-C

1/* sxiv: util.h
2 * Copyright (c) 2012 Bert Muennich <be.muennich at googlemail.com>
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/time.h>
26#include <sys/types.h>
27
28#include "types.h"
29
30#ifndef ABS
31#define ABS(a) ((a) < 0 ? -(a) : (a))
32#endif
33#ifndef MIN
34#define MIN(a,b) ((a) < (b) ? (a) : (b))
35#endif
36#ifndef MAX
37#define MAX(a,b) ((a) > (b) ? (a) : (b))
38#endif
39
40#define ARRLEN(a) (sizeof(a) / sizeof((a)[0]))
41
42#define STREQ(s1,s2) (strcmp((s1), (s2)) == 0)
43
44#define TV_DIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec ) * 1000 + \
45 ((t1)->tv_usec - (t2)->tv_usec) / 1000)
46
47#define TV_SET_MSEC(tv,t) { \
48 (tv)->tv_sec = (t) / 1000; \
49 (tv)->tv_usec = (t) % 1000 * 1000; \
50}
51
52#define TV_ADD_MSEC(tv,t) { \
53 (tv)->tv_sec += (t) / 1000; \
54 (tv)->tv_usec += (t) % 1000 * 1000; \
55}
56
57typedef struct {
58 DIR *dir;
59 char *name;
60 int d;
61
62 char **stack;
63 int stcap;
64 int stlen;
65} r_dir_t;
66
67void* s_malloc(size_t);
68void* s_realloc(void*, size_t);
69char* s_strdup(char*);
70
71void warn(const char*, ...);
72void die(const char*, ...);
73
74ssize_t get_line(char**, size_t*, FILE*);
75
76void size_readable(float*, const char**);
77
78char* absolute_path(const char*);
79
80int r_opendir(r_dir_t*, const char*);
81int r_closedir(r_dir_t*);
82char* r_readdir(r_dir_t*);
83int r_mkdir(const char *);
84
85#endif /* UTIL_H */