cfad47cfa3/src/missing.cc

4b825dc642cb6eb9a060e54bf8d69288fbee4904cfad47cfa334b206c65f22086bcc5d63e6f70944
1
#include "common.h"
2
3
#include "missing.h"
4
5
#include <ctype.h>
6
#include <string.h>
7
8
#ifndef HAVE_MEMICMP
9
int
10
memicmp( const void* s1, const void* s2, size_t len )
11
{
12
	char* x1 = new char[len];
13
	char* x2 = new char[len];
14
	const char* tmp1 = static_cast(const char*)(s1);
15
	const char* tmp2 = static_cast(const char*)(s2);
16
17
	for (size_t i = 0; i < len; ++i) {
18
		x1[i] = tolower(tmp1[i]);
19
		x2[i] = tolower(tmp2[i]);
20
	}
21
	int ret = memcmp(x1, x2, len);
22
	delete[] x1;
23
	delete[] x2;
24
	return ret;
25
}
26
#endif
27
28
29
#if !defined(HAVE_STRICMP) && !defined(HAVE_STRCASECMP)
30
int
31
stricmp( const char* s1, const char* s2 )
32
{
33
	char* x1 = new char[strlen(s1)];
34
	char* x2 = new char[strlen(s2)];
35
36
	for (size_t i = 0; s1[i] != '\0' and s2[i] != '\0'; ++i) {
37
		x1[i] = tolower(s1[i]);
38
		x2[i] = tolower(s2[i]);
39
	}
40
	int ret = strcmp(x1, x2);
41
	delete[] x1;
42
	delete[] x2;
43
	return ret;
44
}
45
#endif
46
47
48
#if !defined(HAVE_STRNICMP) && !defined(HAVE_STRNCASECMP)
49
int
50
strnicmp( const char* s1, const char* s2, size_t n )
51
{
52
	char* x1 = new char[n];
53
	char* x2 = new char[n];
54
55
	for (size_t i = 0; i < n and s1[i] != '\0' and s2[i] != '\0'; ++i) {
56
		x1[i] = tolower(s1[i]);
57
		x2[i] = tolower(s2[i]);
58
	}
59
	int ret = strncmp(s1, s2, n);
60
	delete[] x1;
61
	delete[] x2;
62
	return ret;
63
}
64
#endif
65
66
67
#ifndef HAVE_WCSLEN
68
size_t
69
wcslen( wchar_t* s )
70
{
71
	size_t len = 0;
72
	while (*s++)
73
		++len;
74
	return len;
75
}
76
#endif
77
78
/* Copy a wide character string.
79
 */
80
#ifndef HAVE_WCSCPY
81
wchar_t*
82
wcscpy( wchar_t* dest, const wchar_t* src )
83
{
84
	wchar_t *start = dest;
85
	while ((*dest++ = *src++) != 0)
86
		;
87
	return start;
88
}
89
#endif