codemp/game/bg_lib.h

Go to the documentation of this file.
00001 // bg_lib.h -- standard C library replacement routines used by code
00002 // compiled for the virtual machine
00003 
00004 // This file is NOT included on native builds
00005 
00006 typedef int size_t;
00007 
00008 typedef char *  va_list;
00009 #define _INTSIZEOF(n)   ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
00010 #define va_start(ap,v)  ( ap = (va_list)&v + _INTSIZEOF(v) )
00011 #define va_arg(ap,t)    ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
00012 #define va_end(ap)      ( ap = (va_list)0 )
00013 
00014 #define CHAR_BIT      8         /* number of bits in a char */
00015 #define SCHAR_MIN   (-128)      /* minimum signed char value */
00016 #define SCHAR_MAX     127       /* maximum signed char value */
00017 #define UCHAR_MAX     0xff      /* maximum unsigned char value */
00018 
00019 #define SHRT_MIN    (-32768)        /* minimum (signed) short value */
00020 #define SHRT_MAX      32767         /* maximum (signed) short value */
00021 #define USHRT_MAX     0xffff        /* maximum unsigned short value */
00022 #define INT_MIN     (-2147483647 - 1) /* minimum (signed) int value */
00023 #define INT_MAX       2147483647    /* maximum (signed) int value */
00024 #define UINT_MAX      0xffffffff    /* maximum unsigned int value */
00025 #define LONG_MIN    (-2147483647L - 1) /* minimum (signed) long value */
00026 #define LONG_MAX      2147483647L   /* maximum (signed) long value */
00027 #define ULONG_MAX     0xffffffffUL  /* maximum unsigned long value */
00028 
00029 // Misc functions
00030 typedef int cmp_t(const void *, const void *);
00031 void qsort(void *a, size_t n, size_t es, cmp_t *cmp);
00032 void    srand( unsigned seed );
00033 int             rand( void );
00034 
00035 // String functions
00036 size_t strlen( const char *string );
00037 char *strcat( char *strDestination, const char *strSource );
00038 char *strcpy( char *strDestination, const char *strSource );
00039 int strcmp( const char *string1, const char *string2 );
00040 char *strchr( const char *string, int c );
00041 char *strstr( const char *string, const char *strCharSet );
00042 char *strncpy( char *strDest, const char *strSource, size_t count );
00043 int tolower( int c );
00044 int toupper( int c );
00045 
00046 double atof( const char *string );
00047 double _atof( const char **stringPtr );
00048 int atoi( const char *string );
00049 int _atoi( const char **stringPtr );
00050 
00051 int vsprintf( char *buffer, const char *fmt, va_list argptr );
00052 int sscanf( const char *buffer, const char *fmt, ... );
00053 
00054 // Memory functions
00055 void *memmove( void *dest, const void *src, size_t count );
00056 void *memset( void *dest, int c, size_t count );
00057 void *memcpy( void *dest, const void *src, size_t count );
00058 
00059 // Math functions
00060 double ceil( double x );
00061 double floor( double x );
00062 double sqrt( double x );
00063 double sin( double x );
00064 double cos( double x );
00065 double atan2( double y, double x );
00066 double tan( double x );
00067 int abs( int n );
00068 double fabs( double x );
00069 double acos( double x );
00070