KD System Rewrite:
[reactos.git] / reactos / ntoskrnl / rtl / string.c
1 /* $Id:$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/rtl/string.c
6 * PURPOSE: Ascii string functions
7 *
8 * PROGRAMMERS: Eric Kohl (ekohl@abo.rhein-zeitung.de)
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <internal/ctype.h>
14 #include <string.h>
15
16 /* FUNCTIONS *****************************************************************/
17
18 int _stricmp(const char *s1, const char *s2)
19 {
20 while (toupper(*s1) == toupper(*s2))
21 {
22 if (*s1 == 0)
23 return 0;
24 s1++;
25 s2++;
26 }
27 return toupper(*(unsigned const char *)s1) - toupper(*(unsigned const char *)(s2));
28 }
29
30
31 /*
32 * @implemented
33 */
34 char * _strlwr(char *x)
35 {
36 char *y=x;
37
38 while (*y)
39 {
40 *y=tolower(*y);
41 y++;
42 }
43 return x;
44 }
45
46
47 /*
48 * @implemented
49 */
50 int _strnicmp(const char *s1, const char *s2, size_t n)
51 {
52 if (n == 0)
53 return 0;
54 do
55 {
56 if (toupper(*s1) != toupper(*s2++))
57 return toupper(*(unsigned const char *)s1) - toupper(*(unsigned const char *)--s2);
58 if (*s1++ == 0)
59 break;
60 }
61 while (--n != 0);
62 return 0;
63 }
64
65 /*
66 * @implemented
67 */
68 char* _strnset(char* szToFill, int szFill, size_t sizeMaxFill)
69 {
70 char *t = szToFill;
71 int i = 0;
72 while (*szToFill != 0 && i < (int) sizeMaxFill)
73 {
74 *szToFill = szFill;
75 szToFill++;
76 i++;
77
78 }
79 return t;
80 }
81
82
83 /*
84 * @implemented
85 */
86 char * _strrev(char *s)
87 {
88 char *e;
89 char a;
90
91 e = s;
92 while (*e)
93 e++;
94
95 while (s<e)
96 {
97 a = *s;
98 *s = *e;
99 *e = a;
100 s++;
101 e--;
102 }
103 return s;
104 }
105
106
107 /*
108 * @implemented
109 */
110 char* _strset(char* szToFill, int szFill)
111 {
112 char *t = szToFill;
113 while (*szToFill != 0)
114 {
115 *szToFill = szFill;
116 szToFill++;
117
118 }
119 return t;
120 }
121
122
123 /*
124 * @implemented
125 */
126 char *_strupr(char *x)
127 {
128 char *y=x;
129
130 while (*y)
131 {
132 *y=toupper(*y);
133 y++;
134 }
135 return x;
136 }
137
138 /*
139 * @implemented
140 */
141 char *strstr(const char *s, const char *find)
142 {
143 char c, sc;
144 size_t len;
145
146 if ((c = *find++) != 0)
147 {
148 len = strlen(find);
149 do
150 {
151 do
152 {
153 if ((sc = *s++) == 0)
154 return 0;
155 }
156 while (sc != c);
157 }
158 while (strncmp(s, find, len) != 0);
159 s--;
160 }
161
162 return (char *)s;
163 }