~reviczky/luatex/texlive-bin-git

« back to all changes in this revision

Viewing changes to libs/gd/libgd-2.1.0/src/gdhelpers.c

  • Committer: Adam Reviczky
  • Date: 2015-04-26 22:40:47 UTC
  • Revision ID: adam.reviczky@kclalumni.net-20150426224047-i2p26n3wqphupq6z
TeX Live 2015 import (rev. 37052)

Show diffs side-by-side

added added

removed removed

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