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.
|
|
|
|
*/
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
#ifndef _NETSURF_UTILS_UTILS_H_
|
|
|
|
#define _NETSURF_UTILS_UTILS_H_
|
2002-08-12 03:04:02 +04:00
|
|
|
|
2010-08-03 01:44:35 +04:00
|
|
|
#include <inttypes.h>
|
2003-11-08 02:47:55 +03:00
|
|
|
#include <stdbool.h>
|
2002-08-12 03:04:02 +04:00
|
|
|
|
2014-11-09 18:28:03 +03:00
|
|
|
/** Rectangle coordinates */
|
2014-11-02 23:10:32 +03:00
|
|
|
struct rect {
|
2014-11-09 18:28:03 +03:00
|
|
|
int x0, y0; /**< Top left */
|
|
|
|
int x1, y1; /**< Bottom right */
|
2014-11-02 23:10:32 +03:00
|
|
|
};
|
|
|
|
|
2013-11-15 01:01:51 +04:00
|
|
|
struct dirent;
|
|
|
|
|
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
|
|
|
|
2008-08-13 21:37:59 +04:00
|
|
|
#ifndef PRIxPTR
|
|
|
|
#define PRIxPTR "x"
|
|
|
|
#endif
|
2012-08-13 20:00:43 +04:00
|
|
|
|
2010-08-03 01:44:35 +04:00
|
|
|
#ifndef PRId64
|
|
|
|
#define PRId64 "lld"
|
|
|
|
#endif
|
2008-08-13 21:37:59 +04:00
|
|
|
|
2016-03-18 00:55:12 +03:00
|
|
|
/* Windows does not have sizet formating codes or 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 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 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
|
|
|
/** 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 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
|
|
|
|
|
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
|
|
|
|
2013-11-15 01:01:51 +04:00
|
|
|
|
2016-04-26 01:11:55 +03:00
|
|
|
/**
|
|
|
|
* Warn the user of an event.
|
|
|
|
*
|
|
|
|
* \warning depricated interface, this calls the warning entry in the
|
|
|
|
* miscellaneous gui table and discards the return code.
|
|
|
|
*
|
|
|
|
* \param[in] message A warning looked up in the message translation table
|
|
|
|
* \param[in] detail Additional text to be displayed or NULL.
|
|
|
|
*/
|
|
|
|
void warn_user(const char *message, const char *detail);
|
2014-01-16 04:52:17 +04:00
|
|
|
|
2002-08-12 03:04:02 +04:00
|
|
|
#endif
|