Krolyxon
Commit 25077ac

Branches

Refs →

nsxivutil.h

82 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
59 char **stack;
60 int stcap;
61 int stlen;
62} r_dir_t;
63
64void* s_malloc(size_t);
65void* s_realloc(void*, size_t);
66char* s_strdup(const char*);
67
68void warn(const char*, ...);
69void die(const char*, ...);
70
71ssize_t get_line(char**, size_t*, FILE*);
72
73void size_readable(float*, const char**);
74
75char* absolute_path(const char*);
76
77int r_opendir(r_dir_t*, const char*);
78int r_closedir(r_dir_t*);
79char* r_readdir(r_dir_t*);
80int r_mkdir(const char *);
81
82#endif /* UTIL_H */