home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / gd201.zip / gd-2.0.1 / gdhelpers.c < prev    next >
C/C++ Source or Header  |  2001-04-03  |  1KB  |  96 lines

  1. #include "gd.h"
  2. #include "gdhelpers.h"
  3. #include <stdlib.h>
  4.  
  5. /* TBB: gd_strtok_r is not portable; provide an implementation */
  6.  
  7. #define SEP_TEST (separators[*((unsigned char *) s)])
  8.  
  9. char *
  10. gd_strtok_r (char *s, char *sep, char **state)
  11. {
  12.   char separators[256];
  13.   char *start;
  14.   char *result = 0;
  15.   memset (separators, 0, sizeof (separators));
  16.   while (*sep)
  17.     {
  18.       separators[*((unsigned char *) sep)] = 1;
  19.       sep++;
  20.     }
  21.   if (!s)
  22.     {
  23.       /* Pick up where we left off */
  24.       s = *state;
  25.     }
  26.   start = s;
  27.   /* 1. EOS */
  28.   if (!(*s))
  29.     {
  30.       *state = s;
  31.       return 0;
  32.     }
  33.   /* 2. Leading separators, if any */
  34.   if (SEP_TEST)
  35.     {
  36.       do
  37.     {
  38.       s++;
  39.     }
  40.       while (SEP_TEST);
  41.       /* 2a. EOS after separators only */
  42.       if (!(*s))
  43.     {
  44.       *state = s;
  45.       return 0;
  46.     }
  47.     }
  48.   /* 3. A token */
  49.   result = s;
  50.   do
  51.     {
  52.       /* 3a. Token at end of string */
  53.       if (!(*s))
  54.     {
  55.       *state = s;
  56.       return result;
  57.     }
  58.       s++;
  59.     }
  60.   while (!SEP_TEST);
  61.   /* 4. Terminate token and skip trailing separators */
  62.   *s = '\0';
  63.   do
  64.     {
  65.       s++;
  66.     }
  67.   while (SEP_TEST);
  68.   /* 5. Return token */
  69.   *state = s;
  70.   return result;
  71. }
  72.  
  73. void *
  74. gdCalloc (size_t nmemb, size_t size)
  75. {
  76.   return calloc (nmemb, size);
  77. }
  78.  
  79. void *
  80. gdMalloc (size_t size)
  81. {
  82.   return malloc (size);
  83. }
  84.  
  85. void *
  86. gdRealloc (void *ptr, size_t size)
  87. {
  88.   return realloc (ptr, size);
  89. }
  90.  
  91. void
  92. gdFree (void *ptr)
  93. {
  94.   free (ptr);
  95. }
  96.