Subversion Repositories Games.Carmageddon

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #include "brstdlib.h"
  2. #include "harness/trace.h"
  3.  
  4. #include <ctype.h>
  5. #include <errno.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8.  
  9. // Global variables
  10. // DOSPICK has "$Id: stdlib.c 2.4 1996/12/06 21:18:39 sam Exp $" for this. Do we want to implement these?
  11.  
  12. int BrMemCmp(void* s1, void* s2, size_t n) {
  13.     return memcmp(s1, s2, n);
  14. }
  15.  
  16. void* BrMemCpy(void* s1, void* s2, size_t n) {
  17.     return memcpy(s1, s2, n);
  18. }
  19.  
  20. void* BrMemSet(void* s, int c, size_t n) {
  21.     if (s == NULL) {
  22.         // Passing a null target pointer is undefined behavior
  23.         return NULL;
  24.     }
  25.     return memset(s, c, n);
  26. }
  27.  
  28. char* BrStrCat(char* s1, char* s2) {
  29.     return strcat(s1, s2);
  30. }
  31.  
  32. int BrStrCmp(char* s1, char* s2) {
  33.     return strcmp(s1, s2);
  34. }
  35.  
  36. int BrStrICmp(char* s1, char* s2) {
  37.     // Windows is stricmp, while posix is strcasecmp
  38. #ifdef _WIN32
  39.     return _stricmp(s1, s2); // Pierre-Marie Baty -- ISO C name conformance fix
  40. #else
  41.     return strcasecmp(s1, s2);
  42. #endif
  43. }
  44.  
  45. char* BrStrCpy(char* s1, const char* s2) {
  46.     return strcpy(s1, s2);
  47. }
  48.  
  49. br_size_t BrStrLen(char* s) {
  50.     return strlen(s);
  51. }
  52.  
  53. int BrStrNCmp(char* s1, char* s2, size_t n) {
  54.     return strncmp(s1, s2, n);
  55. }
  56.  
  57. int BrStrNICmp(char* s1, char* s2, size_t n) {
  58.     // Windows is strnicmp, while posix is strncasecmp
  59. #ifdef _WIN32
  60.     return _strnicmp(s1, s2, n); // Pierre-Marie Baty -- ISO C name conformance fix
  61. #else
  62.     return strncasecmp(s1, s2, n);
  63. #endif
  64. }
  65.  
  66. char* BrStrNCpy(char* s1, char* s2, size_t n) {
  67.     return strncpy(s1, s2, n);
  68. }
  69.  
  70. char* BrStrRChr(char* s1, char c) {
  71.     return strrchr(s1, c);
  72. }
  73.  
  74. void BrAbort(void) {
  75.     abort();
  76. }
  77.  
  78. char* BrGetEnv(char* name) {
  79.     return getenv(name);
  80. }
  81.  
  82. float BrStrToF(char* nptr, char** endptr) {
  83.     return strtof(nptr, endptr);
  84. }
  85.  
  86. double BrStrToD(char* nptr, char** endptr) {
  87.     return strtod(nptr, endptr);
  88. }
  89.  
  90. long BrStrToL(char* nptr, char** endptr, int base) {
  91.     return strtol(nptr, endptr, base);
  92. }
  93.  
  94. unsigned long BrStrToUL(char* nptr, char** endptr, int base) {
  95.     return strtoul(nptr, endptr, base);
  96. }
  97.  
  98. br_boolean BrIsAlpha(int c) {
  99.     return isalpha(c);
  100. }
  101.  
  102. br_boolean BrIsDigit(int c) {
  103.     return isdigit(c);
  104. }
  105.  
  106. br_boolean BrIsSpace(int c) {
  107.     return isspace(c);
  108. }
  109.  
  110. br_boolean BrIsPrint(int c) {
  111.     return isprint(c);
  112. }
  113.  
  114. br_int_32 BrVSprintf(char* buf, const char* fmt, va_list args) {
  115.     return vsprintf(buf, fmt, args);
  116. }
  117.  
  118. br_int_32 BrVSprintfN(char* buf, br_size_t buf_size, const char* fmt, va_list args) {
  119.     // Most C libs have vsnprintf these days that can replace this.
  120.     unsigned int n;
  121.     char tmp[512];
  122.  
  123.     n = vsprintf(tmp, fmt, args);
  124.  
  125.     if (buf_size - 1 < n) {
  126.         n = buf_size - 1;
  127.     }
  128.  
  129.     strncpy(buf, tmp, n);
  130.     buf[n] = '\0';
  131.     return n;
  132. }
  133.  
  134. br_int_32 BrVSScanf(char* buf, const char* fmt, va_list args) {
  135.     return vsscanf(buf, fmt, args);
  136. }
  137.