Quake-III-Arena

Quake III Arena GPL Source Release
Log | Files | Refs

bg_lib.h (3649B)


      1 /*
      2 ===========================================================================
      3 Copyright (C) 1999-2005 Id Software, Inc.
      4 
      5 This file is part of Quake III Arena source code.
      6 
      7 Quake III Arena source code is free software; you can redistribute it
      8 and/or modify it under the terms of the GNU General Public License as
      9 published by the Free Software Foundation; either version 2 of the License,
     10 or (at your option) any later version.
     11 
     12 Quake III Arena source code is distributed in the hope that it will be
     13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 GNU General Public License for more details.
     16 
     17 You should have received a copy of the GNU General Public License
     18 along with Foobar; if not, write to the Free Software
     19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     20 ===========================================================================
     21 */
     22 // bg_lib.h -- standard C library replacement routines used by code
     23 // compiled for the virtual machine
     24 
     25 // This file is NOT included on native builds
     26 
     27 typedef int size_t;
     28 
     29 typedef char *  va_list;
     30 #define _INTSIZEOF(n)   ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
     31 #define va_start(ap,v)  ( ap = (va_list)&v + _INTSIZEOF(v) )
     32 #define va_arg(ap,t)    ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
     33 #define va_end(ap)      ( ap = (va_list)0 )
     34 
     35 #define CHAR_BIT      8         /* number of bits in a char */
     36 #define SCHAR_MIN   (-128)      /* minimum signed char value */
     37 #define SCHAR_MAX     127       /* maximum signed char value */
     38 #define UCHAR_MAX     0xff      /* maximum unsigned char value */
     39 
     40 #define SHRT_MIN    (-32768)        /* minimum (signed) short value */
     41 #define SHRT_MAX      32767         /* maximum (signed) short value */
     42 #define USHRT_MAX     0xffff        /* maximum unsigned short value */
     43 #define INT_MIN     (-2147483647 - 1) /* minimum (signed) int value */
     44 #define INT_MAX       2147483647    /* maximum (signed) int value */
     45 #define UINT_MAX      0xffffffff    /* maximum unsigned int value */
     46 #define LONG_MIN    (-2147483647L - 1) /* minimum (signed) long value */
     47 #define LONG_MAX      2147483647L   /* maximum (signed) long value */
     48 #define ULONG_MAX     0xffffffffUL  /* maximum unsigned long value */
     49 
     50 // Misc functions
     51 typedef int cmp_t(const void *, const void *);
     52 void qsort(void *a, size_t n, size_t es, cmp_t *cmp);
     53 void	srand( unsigned seed );
     54 int		rand( void );
     55 
     56 // String functions
     57 size_t strlen( const char *string );
     58 char *strcat( char *strDestination, const char *strSource );
     59 char *strcpy( char *strDestination, const char *strSource );
     60 int strcmp( const char *string1, const char *string2 );
     61 char *strchr( const char *string, int c );
     62 char *strstr( const char *string, const char *strCharSet );
     63 char *strncpy( char *strDest, const char *strSource, size_t count );
     64 int tolower( int c );
     65 int toupper( int c );
     66 
     67 double atof( const char *string );
     68 double _atof( const char **stringPtr );
     69 int atoi( const char *string );
     70 int _atoi( const char **stringPtr );
     71 
     72 int vsprintf( char *buffer, const char *fmt, va_list argptr );
     73 int sscanf( const char *buffer, const char *fmt, ... );
     74 
     75 // Memory functions
     76 void *memmove( void *dest, const void *src, size_t count );
     77 void *memset( void *dest, int c, size_t count );
     78 void *memcpy( void *dest, const void *src, size_t count );
     79 
     80 // Math functions
     81 double ceil( double x );
     82 double floor( double x );
     83 double sqrt( double x );
     84 double sin( double x );
     85 double cos( double x );
     86 double atan2( double y, double x );
     87 double tan( double x );
     88 int abs( int n );
     89 double fabs( double x );
     90 double acos( double x );
     91