File: string.c

package info (click to toggle)
gammu 1.28.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 21,972 kB
  • ctags: 8,504
  • sloc: ansic: 104,965; pascal: 7,209; cpp: 4,023; python: 3,639; php: 1,622; sh: 1,534; sql: 450; cs: 260; makefile: 192; perl: 107; asm: 31
file content (115 lines) | stat: -rw-r--r-- 2,221 bytes parent folder | download
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "string.h"

#include <gammu-unicode.h>

#include <ctype.h>

#ifndef HAVE_STRCASESTR
/**
 * Find the first occurrence of find in s, ignore case.
 * Copyright (c) 1990, 1993 The Regents of the University of California.
 */
char *strcasestr(const char *s, const char *find)
{
	char c, sc;
	size_t len;

	if ((c = *find++) != 0) {
		c = tolower((unsigned char)c);
		len = strlen(find);
		do {
			do {
				if ((sc = *s++) == 0)
					return (NULL);
			} while ((char)tolower((unsigned char)sc) != c);
		} while (strncasecmp(s, find, len) != 0);
		s--;
	}
	return (char *)s;
}
#endif

#ifndef HAVE_STRCHRNUL
char *strchrnul(char *s, int find)
{
	char *ret;
	ret = strchr(s, find);
	if (ret == NULL) return s + strlen(s);
	return ret;
}
#endif


#ifndef HAVE_STRNCASECMP
#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
/**
 * Case insensitive string comparator
 * Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc.
 */
int strncasecmp (const char *s1, const char *s2, size_t n)
{
	register const unsigned char *p1 = (const unsigned char *) s1;
	register const unsigned char *p2 = (const unsigned char *) s2;
	unsigned char c1, c2;

	if (p1 == p2 || n == 0)
		return 0;

	do {
		c1 = TOLOWER (*p1);
		c2 = TOLOWER (*p2);

		if (--n == 0 || c1 == '\0')
			break;

		++p1;
		++p2;
	} while (c1 == c2);

	return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
}
#undef TOLOWER
#endif

#ifndef HAVE_STRCASECMP
#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
/**
 * Case insensitive string comparator
 * Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc.
 */
int strcasecmp (const char *s1, const char *s2)
{
	register const unsigned char *p1 = (const unsigned char *) s1;
	register const unsigned char *p2 = (const unsigned char *) s2;
	unsigned char c1, c2;

	if (p1 == p2)
		return 0;

	do {
		c1 = TOLOWER (*p1);
		c2 = TOLOWER (*p2);

		if (c1 == '\0')
			break;

		++p1;
		++p2;
	} while (c1 == c2);

	return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
}
#undef TOLOWER
#endif

#ifndef HAVE_TOWLOWER
/* FreeBSD boxes 4.7-STABLE does't have it, although it's ANSI standard */
wchar_t towlower(wchar_t c)
{
	unsigned char dest[10];

	DecodeWithUnicodeAlphabet(c, dest);
	return tolower(dest[0]);
}
#endif