2003-06-30 12:44:03 +00:00
|
|
|
/*
|
2007-01-29 22:27:15 +00:00
|
|
|
* Copyright 2004-2007 James Bursa <bursa@users.sourceforge.net>
|
2008-08-05 01:30:31 +00:00
|
|
|
* Copyright 2004 John Tytgat <joty@netsurf-browser.org>
|
2007-08-08 16:16:03 +00: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 09:24:35 +00:00
|
|
|
*/
|
|
|
|
|
2014-05-11 21:31:14 +01:00
|
|
|
/**
|
2016-04-20 23:56:29 +01:00
|
|
|
* \file
|
2014-05-11 21:31:14 +01:00
|
|
|
* \brief Interface to a number of general purpose functionality.
|
|
|
|
* \todo Many of these functions and macros should have their own headers.
|
|
|
|
*/
|
|
|
|
|
2003-02-09 12:58:15 +00:00
|
|
|
#ifndef _NETSURF_UTILS_UTILS_H_
|
|
|
|
#define _NETSURF_UTILS_UTILS_H_
|
2002-08-11 23:04:02 +00:00
|
|
|
|
2010-08-02 21:44:35 +00:00
|
|
|
#include <inttypes.h>
|
2003-11-07 23:47:55 +00:00
|
|
|
#include <stdbool.h>
|
2002-08-11 23:04:02 +00:00
|
|
|
|
2014-11-09 15:28:03 +00:00
|
|
|
/** Rectangle coordinates */
|
2014-11-02 20:10:32 +00:00
|
|
|
struct rect {
|
2014-11-09 15:28:03 +00:00
|
|
|
int x0, y0; /**< Top left */
|
|
|
|
int x1, y1; /**< Bottom right */
|
2014-11-02 20:10:32 +00:00
|
|
|
};
|
|
|
|
|
2013-11-14 21:01:51 +00:00
|
|
|
struct dirent;
|
|
|
|
|
2005-04-15 05:52:04 +00:00
|
|
|
#ifndef NOF_ELEMENTS
|
|
|
|
#define NOF_ELEMENTS(array) (sizeof(array)/sizeof(*(array)))
|
|
|
|
#endif
|
2012-08-13 17:00:43 +01:00
|
|
|
|
2005-04-21 21:36:23 +00:00
|
|
|
#ifndef ABS
|
|
|
|
#define ABS(x) (((x)>0)?(x):(-(x)))
|
|
|
|
#endif
|
2012-08-13 17:00:43 +01:00
|
|
|
|
2011-01-05 21:02:22 +00:00
|
|
|
#ifdef __MINT__ /* avoid using GCCs builtin min/max functions */
|
|
|
|
#undef min
|
|
|
|
#undef max
|
|
|
|
#endif
|
2012-08-13 17:00:43 +01:00
|
|
|
|
2015-08-17 20:09:47 +02:00
|
|
|
#ifndef __cplusplus
|
2005-04-21 21:36:23 +00:00
|
|
|
#ifndef min
|
|
|
|
#define min(x,y) (((x)<(y))?(x):(y))
|
|
|
|
#endif
|
2012-08-13 17:00:43 +01:00
|
|
|
|
2005-04-21 21:36:23 +00:00
|
|
|
#ifndef max
|
|
|
|
#define max(x,y) (((x)>(y))?(x):(y))
|
|
|
|
#endif
|
2015-08-17 20:09:47 +02:00
|
|
|
#endif
|
2012-08-13 17:00:43 +01:00
|
|
|
|
2008-08-13 17:37:59 +00:00
|
|
|
#ifndef PRIxPTR
|
|
|
|
#define PRIxPTR "x"
|
|
|
|
#endif
|
2012-08-13 17:00:43 +01:00
|
|
|
|
2010-08-02 21:44:35 +00:00
|
|
|
#ifndef PRId64
|
|
|
|
#define PRId64 "lld"
|
|
|
|
#endif
|
2008-08-13 17:37:59 +00:00
|
|
|
|
2016-03-17 21:55:12 +00:00
|
|
|
/* Windows does not have sizet formating codes or POSIX mkdir so work
|
|
|
|
* around that
|
|
|
|
*/
|
2012-08-13 17:00:43 +01:00
|
|
|
#if defined(_WIN32)
|
2016-03-17 21:55:12 +00:00
|
|
|
/** windows printf formatting for size_t type */
|
|
|
|
#define PRIsizet "Iu"
|
|
|
|
/** windows printf formatting for ssize_t type */
|
|
|
|
#define PRIssizet "Id"
|
|
|
|
/** windows mkdir function */
|
2014-04-28 17:36:51 +01:00
|
|
|
#define nsmkdir(dir, mode) mkdir((dir))
|
2012-08-13 17:00:43 +01:00
|
|
|
#else
|
2016-03-17 21:55:12 +00:00
|
|
|
/** c99 standard printf formatting for size_t type */
|
|
|
|
#define PRIsizet "zu"
|
|
|
|
/** c99 standard printf formatting for ssize_t type */
|
|
|
|
#define PRIssizet "zd"
|
|
|
|
/** POSIX mkdir function */
|
2014-04-28 17:36:51 +01:00
|
|
|
#define nsmkdir(dir, mode) mkdir((dir), (mode))
|
2012-08-13 17:00:43 +01:00
|
|
|
#endif
|
|
|
|
|
2012-03-19 18:24:43 +00:00
|
|
|
#if defined(__GNUC__) && (__GNUC__ < 3)
|
|
|
|
#define FLEX_ARRAY_LEN_DECL 0
|
|
|
|
#else
|
|
|
|
#define FLEX_ARRAY_LEN_DECL
|
|
|
|
#endif
|
|
|
|
|
2008-08-13 17:37:59 +00:00
|
|
|
#if defined(__HAIKU__) || defined(__BEOS__)
|
2016-04-21 23:56:16 +01:00
|
|
|
#include <stdlib.h>
|
2008-08-13 17:37:59 +00:00
|
|
|
#define strtof(s,p) ((float)(strtod((s),(p))))
|
|
|
|
#endif
|
2005-04-15 05:52:04 +00:00
|
|
|
|
2011-01-05 21:02:22 +00:00
|
|
|
#if !defined(ceilf) && defined(__MINT__)
|
|
|
|
#define ceilf(x) (float)ceil((double)x)
|
|
|
|
#endif
|
|
|
|
|
2008-05-25 15:51:30 +00:00
|
|
|
/**
|
|
|
|
* Calculate length of constant C string.
|
|
|
|
*
|
2014-05-11 21:31:14 +01:00
|
|
|
* \param x a constant C string.
|
|
|
|
* \return The length of C string without its terminator.
|
2008-05-25 15:51:30 +00:00
|
|
|
*/
|
|
|
|
#define SLEN(x) (sizeof((x)) - 1)
|
|
|
|
|
2005-04-23 02:58:27 +00:00
|
|
|
|
2014-05-11 21:31:14 +01:00
|
|
|
/**
|
|
|
|
* Check if a directory exists.
|
|
|
|
*/
|
2003-11-07 23:47:55 +00:00
|
|
|
bool is_dir(const char *path);
|
2014-05-11 21:31:14 +01:00
|
|
|
|
2002-08-11 23:04:02 +00:00
|
|
|
#endif
|