2010-08-14 20:55:39 +00:00
|
|
|
/*
|
2013-09-25 17:01:40 +00:00
|
|
|
* q_stdinc.h - includes the minimum necessary stdc headers,
|
|
|
|
* defines common and / or missing types.
|
|
|
|
*
|
|
|
|
* NOTE: for net stuff use net_sys.h,
|
|
|
|
* for byte order use q_endian.h,
|
|
|
|
* for math stuff use mathlib.h,
|
|
|
|
* for locale-insensitive ctype.h functions use q_ctype.h.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
* Copyright (C) 2007-2011 O.Sezer <sezero@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* This program 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; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2010-08-14 20:55:39 +00:00
|
|
|
|
|
|
|
#ifndef __QSTDINC_H
|
|
|
|
#define __QSTDINC_H
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <limits.h>
|
2014-07-01 16:25:00 +00:00
|
|
|
#ifndef _WIN32 /* others we support without sys/param.h? */
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
2010-08-14 20:55:39 +00:00
|
|
|
|
2017-02-14 11:00:29 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2010-08-14 20:55:39 +00:00
|
|
|
/* NOTES on TYPE SIZES:
|
|
|
|
Quake/Hexen II engine relied on 32 bit int type size
|
|
|
|
with ILP32 (not LP32) model in mind. We now support
|
|
|
|
LP64 and LLP64, too. We expect:
|
|
|
|
sizeof (char) == 1
|
|
|
|
sizeof (short) == 2
|
|
|
|
sizeof (int) == 4
|
|
|
|
sizeof (float) == 4
|
|
|
|
sizeof (long) == 4 / 8
|
|
|
|
sizeof (pointer *) == 4 / 8
|
2011-06-11 13:20:13 +00:00
|
|
|
For this, we need stdint.h (or inttypes.h)
|
|
|
|
FIXME: On some platforms, only inttypes.h is available.
|
2010-08-14 20:55:39 +00:00
|
|
|
FIXME: Properly replace certain short and int usage
|
|
|
|
with int16_t and int32_t.
|
|
|
|
*/
|
2011-04-01 14:55:45 +00:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER < 1600)
|
|
|
|
/* MS Visual Studio provides stdint.h only starting with
|
|
|
|
* version 2010. Even in VS2010, there is no inttypes.h.. */
|
|
|
|
#include "msinttypes/stdint.h"
|
|
|
|
#else
|
|
|
|
#include <stdint.h>
|
|
|
|
#endif
|
2010-08-14 20:55:39 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/*==========================================================================*/
|
|
|
|
|
|
|
|
#ifndef NULL
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define NULL 0
|
|
|
|
#else
|
|
|
|
#define NULL ((void *)0)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define Q_MAXCHAR ((char)0x7f)
|
|
|
|
#define Q_MAXSHORT ((short)0x7fff)
|
|
|
|
#define Q_MAXINT ((int)0x7fffffff)
|
|
|
|
#define Q_MAXLONG ((int)0x7fffffff)
|
|
|
|
#define Q_MAXFLOAT ((int)0x7fffffff)
|
|
|
|
|
|
|
|
#define Q_MINCHAR ((char)0x80)
|
|
|
|
#define Q_MINSHORT ((short)0x8000)
|
|
|
|
#define Q_MININT ((int)0x80000000)
|
|
|
|
#define Q_MINLONG ((int)0x80000000)
|
|
|
|
#define Q_MINFLOAT ((int)0x7fffffff)
|
|
|
|
|
|
|
|
/* Make sure the types really have the right
|
|
|
|
* sizes: These macros are from SDL headers.
|
|
|
|
*/
|
|
|
|
#define COMPILE_TIME_ASSERT(name, x) \
|
|
|
|
typedef int dummy_ ## name[(x) * 2 - 1]
|
|
|
|
|
|
|
|
COMPILE_TIME_ASSERT(char, sizeof(char) == 1);
|
|
|
|
COMPILE_TIME_ASSERT(float, sizeof(float) == 4);
|
|
|
|
COMPILE_TIME_ASSERT(long, sizeof(long) >= 4);
|
|
|
|
COMPILE_TIME_ASSERT(int, sizeof(int) == 4);
|
|
|
|
COMPILE_TIME_ASSERT(short, sizeof(short) == 2);
|
|
|
|
|
|
|
|
/* make sure enums are the size of ints for structure packing */
|
|
|
|
typedef enum {
|
|
|
|
THE_DUMMY_VALUE
|
|
|
|
} THE_DUMMY_ENUM;
|
|
|
|
COMPILE_TIME_ASSERT(enum, sizeof(THE_DUMMY_ENUM) == sizeof(int));
|
|
|
|
|
|
|
|
|
|
|
|
/* Provide a substitute for offsetof() if we don't have one.
|
|
|
|
* This variant works on most (but not *all*) systems...
|
|
|
|
*/
|
|
|
|
#ifndef offsetof
|
|
|
|
#define offsetof(t,m) ((size_t)&(((t *)0)->m))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*==========================================================================*/
|
|
|
|
|
|
|
|
typedef unsigned char byte;
|
|
|
|
|
|
|
|
#undef true
|
|
|
|
#undef false
|
|
|
|
#if defined(__cplusplus)
|
2011-06-11 13:20:13 +00:00
|
|
|
/* some structures have qboolean members and the x86 asm code expect
|
|
|
|
* those members to be 4 bytes long. therefore, qboolean must be 32
|
|
|
|
* bits and it can NOT be binary compatible with the 8 bit C++ bool. */
|
2010-08-14 20:55:39 +00:00
|
|
|
typedef int qboolean;
|
2011-06-11 13:20:13 +00:00
|
|
|
COMPILE_TIME_ASSERT(falsehood, (0 == false));
|
|
|
|
COMPILE_TIME_ASSERT(truth, (1 == true));
|
2010-08-14 20:55:39 +00:00
|
|
|
#else
|
|
|
|
typedef enum {
|
|
|
|
false = 0,
|
|
|
|
true = 1
|
|
|
|
} qboolean;
|
2011-06-11 13:20:13 +00:00
|
|
|
COMPILE_TIME_ASSERT(falsehood, ((1 != 1) == false));
|
|
|
|
COMPILE_TIME_ASSERT(truth, ((1 == 1) == true));
|
2010-08-14 20:55:39 +00:00
|
|
|
#endif
|
2011-06-11 13:20:13 +00:00
|
|
|
COMPILE_TIME_ASSERT(qboolean, sizeof(qboolean) == 4);
|
2010-08-14 20:55:39 +00:00
|
|
|
|
|
|
|
/*==========================================================================*/
|
|
|
|
|
|
|
|
/* math */
|
|
|
|
typedef float vec_t;
|
|
|
|
typedef vec_t vec3_t[3];
|
2013-09-25 17:01:40 +00:00
|
|
|
typedef vec_t vec4_t[4];
|
2010-08-14 20:55:39 +00:00
|
|
|
typedef vec_t vec5_t[5];
|
|
|
|
typedef int fixed4_t;
|
|
|
|
typedef int fixed8_t;
|
|
|
|
typedef int fixed16_t;
|
|
|
|
|
|
|
|
|
2014-07-01 16:25:00 +00:00
|
|
|
/*==========================================================================*/
|
|
|
|
|
|
|
|
/* MAX_OSPATH (max length of a filesystem pathname, i.e. PATH_MAX)
|
|
|
|
* Note: See GNU Hurd and others' notes about brokenness of this:
|
|
|
|
* http://www.gnu.org/software/hurd/community/gsoc/project_ideas/maxpath.html
|
|
|
|
* http://insanecoding.blogspot.com/2007/11/pathmax-simply-isnt.html */
|
|
|
|
|
|
|
|
#if !defined(PATH_MAX)
|
|
|
|
/* equivalent values? */
|
|
|
|
#if defined(MAXPATHLEN)
|
|
|
|
#define PATH_MAX MAXPATHLEN
|
|
|
|
#elif defined(_WIN32) && defined(_MAX_PATH)
|
|
|
|
#define PATH_MAX _MAX_PATH
|
|
|
|
#elif defined(_WIN32) && defined(MAX_PATH)
|
|
|
|
#define PATH_MAX MAX_PATH
|
|
|
|
#else /* fallback */
|
|
|
|
#define PATH_MAX 1024
|
|
|
|
#endif
|
|
|
|
#endif /* PATH_MAX */
|
|
|
|
|
|
|
|
#define MAX_OSPATH PATH_MAX
|
|
|
|
|
2010-08-14 20:55:39 +00:00
|
|
|
/*==========================================================================*/
|
|
|
|
|
2018-11-03 09:50:53 +00:00
|
|
|
/* missing types: */
|
2010-08-14 20:55:39 +00:00
|
|
|
#if defined(_MSC_VER)
|
2018-11-03 09:50:53 +00:00
|
|
|
typedef ptrdiff_t ssize_t;
|
|
|
|
#endif
|
2010-08-14 20:55:39 +00:00
|
|
|
|
2014-10-31 13:03:20 +00:00
|
|
|
/*==========================================================================*/
|
2010-08-14 20:55:39 +00:00
|
|
|
|
2017-07-28 20:11:03 +00:00
|
|
|
/* function attributes, etc */
|
|
|
|
|
2017-07-28 12:50:10 +00:00
|
|
|
#if defined(__GNUC__)
|
|
|
|
#define FUNC_PRINTF(x,y) __attribute__((__format__(__printf__,x,y)))
|
|
|
|
#else
|
|
|
|
#define FUNC_PRINTF(x,y)
|
|
|
|
#endif
|
2010-08-14 20:55:39 +00:00
|
|
|
|
2017-07-28 12:50:10 +00:00
|
|
|
/* argument format attributes for function pointers are supported for gcc >= 3.1 */
|
2010-08-14 20:55:39 +00:00
|
|
|
#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0))
|
2017-07-28 12:50:10 +00:00
|
|
|
#define FUNCP_PRINTF FUNC_PRINTF
|
|
|
|
#else
|
|
|
|
#define FUNCP_PRINTF(x,y)
|
|
|
|
#endif
|
|
|
|
|
2017-10-01 18:11:29 +00:00
|
|
|
/* llvm's optnone function attribute started with clang-3.5.0 */
|
|
|
|
#if defined(__clang__) && \
|
|
|
|
(__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 5))
|
|
|
|
#define FUNC_NO_OPTIMIZE __attribute__((__optnone__))
|
2017-07-28 12:50:10 +00:00
|
|
|
/* function optimize attribute is added starting with gcc 4.4.0 */
|
2017-10-01 18:11:29 +00:00
|
|
|
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 3))
|
2017-07-28 12:50:10 +00:00
|
|
|
#define FUNC_NO_OPTIMIZE __attribute__((__optimize__("0")))
|
|
|
|
#else
|
|
|
|
#define FUNC_NO_OPTIMIZE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__GNUC__)
|
|
|
|
#define FUNC_NORETURN __attribute__((__noreturn__))
|
|
|
|
#elif defined(_MSC_VER) && (_MSC_VER >= 1200)
|
|
|
|
#define FUNC_NORETURN __declspec(noreturn)
|
2017-07-28 20:11:03 +00:00
|
|
|
#elif defined(__WATCOMC__)
|
|
|
|
#define FUNC_NORETURN /* use the 'aborts' aux pragma */
|
2017-07-28 12:50:10 +00:00
|
|
|
#else
|
|
|
|
#define FUNC_NORETURN
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
|
|
|
|
#define FUNC_NOINLINE __attribute__((__noinline__))
|
|
|
|
#elif defined(_MSC_VER) && (_MSC_VER >= 1300)
|
|
|
|
#define FUNC_NOINLINE __declspec(noinline)
|
|
|
|
#else
|
|
|
|
#define FUNC_NOINLINE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
|
|
|
|
#define FUNC_NOCLONE __attribute__((__noclone__))
|
2010-08-14 20:55:39 +00:00
|
|
|
#else
|
2017-07-28 12:50:10 +00:00
|
|
|
#define FUNC_NOCLONE
|
2010-08-14 20:55:39 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_MSC_VER) && !defined(__cplusplus)
|
|
|
|
#define inline __inline
|
|
|
|
#endif /* _MSC_VER */
|
|
|
|
|
|
|
|
/*==========================================================================*/
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* __QSTDINC_H */
|
|
|
|
|