NetSurf
utils
utils.h
Go to the documentation of this file.
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
/**
93
* switch fall through
94
*/
95
#if defined __cplusplus && defined __has_cpp_attribute
96
#if __has_cpp_attribute(fallthrough) && __cplusplus >= __has_cpp_attribute(fallthrough)
97
#define fallthrough [[fallthrough]]
98
#elif __has_cpp_attribute(gnu::fallthrough) && __STDC_VERSION__ >= __has_cpp_attribute(gnu::fallthrough)
99
#define fallthrough [[gnu::fallthrough]]
100
#elif __has_cpp_attribute(clang::fallthrough) && __STDC_VERSION__ >= __has_cpp_attribute(clang::fallthrough)
101
#define fallthrough [[clang::fallthrough]]
102
#endif
103
#elif defined __STDC_VERSION__ && defined __has_c_attribute
104
#if __has_c_attribute(fallthrough) && __STDC_VERSION__ >= __has_c_attribute(fallthrough)
105
#define fallthrough [[fallthrough]]
106
#endif
107
#endif
108
#if !defined fallthrough && defined __has_attribute
109
#if __has_attribute(__fallthrough__)
110
#define fallthrough __attribute__((__fallthrough__))
111
#endif
112
#endif
113
#if !defined fallthrough
114
/* early gcc and clang have no implicit fallthrough warning */
115
#define fallthrough do {} while(0)
116
#endif
117
118
119
#endif
is_dir
bool is_dir(const char *path)
Check if a directory exists.
Definition:
utils.c:94
path
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.
Definition:
plot.c:821
Generated on Tue Apr 9 2024 22:30:01 for NetSurf by
1.9.4