-
Notifications
You must be signed in to change notification settings - Fork 4
/
rtl.c
50 lines (46 loc) · 926 Bytes
/
rtl.c
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
#include "rtl.h"
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
char *rtl_strdup(const char *str)
{
return str ? strcpy(malloc(strlen(str)+1), str) : 0;
}
char *rtl_strlwr(char *str)
{
char *s;
for (s = str; *s; ++s) {
*s = (char) tolower(*s);
}
return str;
}
int rtl_memicmp(const char *a, const char *b, size_t size)
{
int ca = tolower(*a);
int cb = tolower(*b);
if (size == 0)
return 0;
if (ca < cb)
return -1;
if (ca > cb)
return 1;
return rtl_memicmp(a + 1, b + 1, size - 1);
}
int rtl_strcmpl(const char *a, const char *b)
{
for (; *a && *b; ++a, ++b) {
int ca = tolower(*a);
int cb = tolower(*b);
if (ca < cb) {
return -1;
} else if (ca > cb) {
return 1;
}
}
if (*b)
return -1;
if (*a)
return 1;
return 0;
}