1 /*
2  * Copyright 2004-2007 James Bursa <bursa@users.sourceforge.net>
3  * Copyright 2004 John Tytgat <joty@netsurf-browser.org>
4  *
5  * This file is part of NetSurf, http://www.netsurf-browser.org/
6  *
7  * NetSurf is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; version 2 of the License.
10  *
11  * NetSurf is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 /**
21  * \file
22  * \brief Interface to a number of general purpose functionality.
23  * \todo Many of these functions and macros should have their own headers.
24  */
25 
26 #ifndef NETSURF_UTILS_UTILS_H
27 #define NETSURF_UTILS_UTILS_H
28 
29 #include <stdbool.h>
30 
31 #ifndef NOF_ELEMENTS
32 #define NOF_ELEMENTS(array) (sizeof(array)/sizeof(*(array)))
33 #endif
34 
35 #ifndef ABS
36 #define ABS(x) (((x)>0)?(x):(-(x)))
37 #endif
38 
39 #ifdef __MINT__ /* avoid using GCCs builtin min/max functions */
40 #undef min
41 #undef max
42 #endif
43 
44 #ifndef __cplusplus
45 #ifndef min
46 #define min(x,y) (((x)<(y))?(x):(y))
47 #endif
48 
49 #ifndef max
50 #define max(x,y) (((x)>(y))?(x):(y))
51 #endif
52 #endif
53 
54 /* Windows does not have POSIX mkdir so work around that */
55 #if defined(_WIN32)
56 /** windows mkdir function */
57 #define nsmkdir(dir, mode) mkdir((dir))
58 #else
59 /** POSIX mkdir function */
60 #define nsmkdir(dir, mode) mkdir((dir), (mode))
61 #endif
62 
63 #if defined(__GNUC__) && (__GNUC__ < 3)
64 #define FLEX_ARRAY_LEN_DECL 0
65 #else
66 #define FLEX_ARRAY_LEN_DECL
67 #endif
68 
69 #if defined(__HAIKU__) || defined(__BEOS__)
70 #include <stdlib.h>
71 #define strtof(s,p) ((float)(strtod((s),(p))))
72 #endif
73 
74 #if !defined(ceilf) && defined(__MINT__)
75 #define ceilf(x) (float)ceil((double)x)
76 #endif
77 
78 /**
79  * Calculate length of constant C string.
80  *
81  * \param  x a constant C string.
82  * \return The length of C string without its terminator.
83  */
84 #define SLEN(x) (sizeof((x)) - 1)
85 
86 
87 /**
88  * Check if a directory exists.
89  */
90 bool is_dir(const char *path);
91 
92 #endif
93