2003-06-30 16:44:03 +04:00
|
|
|
/*
|
2007-01-30 01:27:15 +03:00
|
|
|
* Copyright 2004-2007 James Bursa <bursa@users.sourceforge.net>
|
2008-08-05 05:30:31 +04:00
|
|
|
* Copyright 2004 John Tytgat <joty@netsurf-browser.org>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2002-04-22 13:24:35 +04:00
|
|
|
*/
|
|
|
|
|
2014-05-12 00:31:14 +04:00
|
|
|
/**
|
2016-04-21 01:56:29 +03:00
|
|
|
* \file
|
2014-05-12 00:31:14 +04:00
|
|
|
* \brief Interface to a number of general purpose functionality.
|
|
|
|
* \todo Many of these functions and macros should have their own headers.
|
|
|
|
*/
|
|
|
|
|
2017-01-21 17:20:55 +03:00
|
|
|
#ifndef NETSURF_UTILS_UTILS_H
|
|
|
|
#define NETSURF_UTILS_UTILS_H
|
2002-08-12 03:04:02 +04:00
|
|
|
|
2003-11-08 02:47:55 +03:00
|
|
|
#include <stdbool.h>
|
2002-08-12 03:04:02 +04:00
|
|
|
|
2005-04-15 09:52:04 +04:00
|
|
|
#ifndef NOF_ELEMENTS
|
|
|
|
#define NOF_ELEMENTS(array) (sizeof(array)/sizeof(*(array)))
|
|
|
|
#endif
|
2012-08-13 20:00:43 +04:00
|
|
|
|
2005-04-22 01:36:23 +04:00
|
|
|
#ifndef ABS
|
|
|
|
#define ABS(x) (((x)>0)?(x):(-(x)))
|
|
|
|
#endif
|
2012-08-13 20:00:43 +04:00
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
#ifdef __MINT__ /* avoid using GCCs builtin min/max functions */
|
|
|
|
#undef min
|
|
|
|
#undef max
|
|
|
|
#endif
|
2012-08-13 20:00:43 +04:00
|
|
|
|
2015-08-17 21:09:47 +03:00
|
|
|
#ifndef __cplusplus
|
2005-04-22 01:36:23 +04:00
|
|
|
#ifndef min
|
|
|
|
#define min(x,y) (((x)<(y))?(x):(y))
|
|
|
|
#endif
|
2012-08-13 20:00:43 +04:00
|
|
|
|
2005-04-22 01:36:23 +04:00
|
|
|
#ifndef max
|
|
|
|
#define max(x,y) (((x)>(y))?(x):(y))
|
|
|
|
#endif
|
2015-08-17 21:09:47 +03:00
|
|
|
#endif
|
2012-08-13 20:00:43 +04:00
|
|
|
|
2017-01-21 17:20:55 +03:00
|
|
|
/* Windows does not have POSIX mkdir so work around that */
|
2012-08-13 20:00:43 +04:00
|
|
|
#if defined(_WIN32)
|
2016-03-18 00:55:12 +03:00
|
|
|
/** windows mkdir function */
|
2014-04-28 20:36:51 +04:00
|
|
|
#define nsmkdir(dir, mode) mkdir((dir))
|
2012-08-13 20:00:43 +04:00
|
|
|
#else
|
2016-03-18 00:55:12 +03:00
|
|
|
/** POSIX mkdir function */
|
2014-04-28 20:36:51 +04:00
|
|
|
#define nsmkdir(dir, mode) mkdir((dir), (mode))
|
2012-08-13 20:00:43 +04:00
|
|
|
#endif
|
|
|
|
|
2012-03-19 22:24:43 +04:00
|
|
|
#if defined(__GNUC__) && (__GNUC__ < 3)
|
|
|
|
#define FLEX_ARRAY_LEN_DECL 0
|
|
|
|
#else
|
|
|
|
#define FLEX_ARRAY_LEN_DECL
|
|
|
|
#endif
|
|
|
|
|
2008-08-13 21:37:59 +04:00
|
|
|
#if defined(__HAIKU__) || defined(__BEOS__)
|
2016-04-22 01:56:16 +03:00
|
|
|
#include <stdlib.h>
|
2008-08-13 21:37:59 +04:00
|
|
|
#define strtof(s,p) ((float)(strtod((s),(p))))
|
|
|
|
#endif
|
2005-04-15 09:52:04 +04:00
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
#if !defined(ceilf) && defined(__MINT__)
|
|
|
|
#define ceilf(x) (float)ceil((double)x)
|
|
|
|
#endif
|
|
|
|
|
2019-10-20 11:34:39 +03:00
|
|
|
#if !defined(__amigaos4__) && defined(__AMIGA__)
|
|
|
|
#define strtoull(n,e,b) (unsigned long long int)strtoul(n,e,b)
|
|
|
|
#endif
|
|
|
|
|
2008-05-25 19:51:30 +04:00
|
|
|
/**
|
|
|
|
* Calculate length of constant C string.
|
|
|
|
*
|
2014-05-12 00:31:14 +04:00
|
|
|
* \param x a constant C string.
|
|
|
|
* \return The length of C string without its terminator.
|
2008-05-25 19:51:30 +04:00
|
|
|
*/
|
|
|
|
#define SLEN(x) (sizeof((x)) - 1)
|
|
|
|
|
2005-04-23 06:58:27 +04:00
|
|
|
|
2014-05-12 00:31:14 +04:00
|
|
|
/**
|
|
|
|
* Check if a directory exists.
|
|
|
|
*/
|
2003-11-08 02:47:55 +03:00
|
|
|
bool is_dir(const char *path);
|
2014-05-12 00:31:14 +04:00
|
|
|
|
2002-08-12 03:04:02 +04:00
|
|
|
#endif
|