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
53
#ifndef clamp
54
#define clamp(x,low,high) (min(max((x),(low)),(high)))
55
#endif
56
#endif
57
58
/* Windows does not have POSIX mkdir so work around that */
59
#if defined(_WIN32)
60
/** windows mkdir function */
61
#define nsmkdir(dir, mode) mkdir((dir))
62
#else
63
/** POSIX mkdir function */
64
#define nsmkdir(dir, mode) mkdir((dir), (mode))
65
#endif
66
67
#if defined(__GNUC__) && (__GNUC__ < 3)
68
#define FLEX_ARRAY_LEN_DECL 0
69
#else
70
#define FLEX_ARRAY_LEN_DECL
71
#endif
72
73
#if defined(__HAIKU__) || defined(__BEOS__)
74
#include <stdlib.h>
75
#define strtof(s,p) ((float)(strtod((s),(p))))
76
#endif
77
78
#if !defined(ceilf) && defined(__MINT__)
79
#define ceilf(x) (float)ceil((double)x)
80
#endif
81
82
/**
83
* Calculate length of constant C string.
84
*
85
* \param x a constant C string.
86
* \return The length of C string without its terminator.
87
*/
88
#define SLEN(x) (sizeof((x)) - 1)
89
90
91
/**
92
* Check if a directory exists.
93
*/
94
bool
is_dir
(
const
char
*
path
);
95
96
/**
97
* switch fall through
98
*/
99
#if defined __cplusplus && defined __has_cpp_attribute
100
#if __has_cpp_attribute(fallthrough) && __cplusplus >= __has_cpp_attribute(fallthrough)
101
#define fallthrough [[fallthrough]]
102
#elif __has_cpp_attribute(gnu::fallthrough) && __STDC_VERSION__ >= __has_cpp_attribute(gnu::fallthrough)
103
#define fallthrough [[gnu::fallthrough]]
104
#elif __has_cpp_attribute(clang::fallthrough) && __STDC_VERSION__ >= __has_cpp_attribute(clang::fallthrough)
105
#define fallthrough [[clang::fallthrough]]
106
#endif
107
#elif defined __STDC_VERSION__ && defined __has_c_attribute
108
#if __has_c_attribute(fallthrough) && __STDC_VERSION__ >= __has_c_attribute(fallthrough)
109
#define fallthrough [[fallthrough]]
110
#endif
111
#endif
112
#if !defined fallthrough && defined __has_attribute
113
#if __has_attribute(__fallthrough__)
114
#define fallthrough __attribute__((__fallthrough__))
115
#endif
116
#endif
117
#if !defined fallthrough
118
/* early gcc and clang have no implicit fallthrough warning */
119
#define fallthrough do {} while(0)
120
#endif
121
122
123
#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 Fri Dec 27 2024 08:42:01 for NetSurf by
1.9.4