File: nonstandard.C

package info (click to toggle)
xshisen 1:1.51-4.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 1,124 kB
  • sloc: cpp: 4,007; sh: 152; perl: 146; makefile: 114
file content (64 lines) | stat: -rw-r--r-- 1,409 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "components.h"

#ifndef HAVE_STRDUP
char *strdup(const char *s)
{
    char *p = malloc((strlen(s)+1)*sizeof(char));
    if (p)
        strcpy(p, s);
    return p;
}
#endif /* HAVE_STRDUP */

#ifndef HAVE_STRSTR
char *strstr(const char *s1, const char *s2)
{
    char *p;
    int  l1 = strlen(s1);
    int  l2 = strlen(s2);
    if (l1 < l2)
        return NULL;
    for(p = s1; p <= s1+l1-l2; p++)
        if (strncmp(p, s2, l2) == 0)
            return p;
    return NULL;
}
#endif /* HAVE_STRSTR */

#ifndef HAVE_STRNCASECMP
# if STDC_HEADERS
#  define Toupper(c) (toupper(c))
# else /* STDC_HEADERS */
#  define Toupper(c) ((c)&50)
# endif /* STDC_HEADERS */
int strncasecmp(const char *s1, const char *s2, size_t n)
{
    register int i;
    for(i=0; i<n; i++) {
        register char p1 = toupper(s1[i]), p2 = toupper(s2[i]);
        if (p1 == '\0') {
            if (p2 == '\0')
                return 0;
            else
                return 1;
        } else if (p2 == '\0') {
            return -1;
        } else if (p1 < p2) {
            return 1;
        } else if (p1 > p2) {
            return -1;
        }
    }
    return 0;
}
#endif /* HAVE_STRNCASECMP */

#ifndef HAVE_STRCASECMP
#ifndef INT_MAX
# define INT_MAX (sizeof(int)==4 ? 2147483647 : 32767)
#endif
int strcasecmp(const char *s1, const char *s2)
{
    return strncasecmp(s1, s2, INT_MAX);
}
#endif /* HAVE_STRCASECMP */