1 | /* $Id: crt_string.cpp,v 1.2 2000-02-21 10:34:01 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * The C RunTime DLL
|
---|
5 | *
|
---|
6 | * Implements C run-time functionality as known from UNIX.
|
---|
7 | *
|
---|
8 | * Partialy based on Wine
|
---|
9 | *
|
---|
10 | * Copyright 1996,1998 Marcus Meissner
|
---|
11 | * Copyright 1996 Jukka Iivonen
|
---|
12 | * Copyright 1997 Uwe Bonnes
|
---|
13 | * Copyright 1999-2000 Jens Wiessner
|
---|
14 | *
|
---|
15 | * CRTDLL - string functions
|
---|
16 | *
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include <odin.h>
|
---|
20 | #include <os2win.h>
|
---|
21 | #include <ctype.h>
|
---|
22 | #include <heapstring.h>
|
---|
23 | #include <string.h>
|
---|
24 |
|
---|
25 |
|
---|
26 | /*********************************************************************
|
---|
27 | * _strcmpi (CRTDLL.280)
|
---|
28 | */
|
---|
29 | void CDECL CRTDLL__strcmpi( LPCSTR s1, LPCSTR s2 )
|
---|
30 | {
|
---|
31 | dprintf2(("CRTDLL: _strcmpi(%08xh, %08xh)\n",
|
---|
32 | s1,
|
---|
33 | s2));
|
---|
34 |
|
---|
35 | lstrcmpiA( s1, s2 );
|
---|
36 | }
|
---|
37 |
|
---|
38 |
|
---|
39 | /*********************************************************************
|
---|
40 | * CRTDLL__strdate (CRTDLL.281)
|
---|
41 | */
|
---|
42 | char * CDECL CRTDLL__strdate( char *buf )
|
---|
43 | {
|
---|
44 | dprintf2(("CRTDLL: _strdate\n"));
|
---|
45 | return(_strdate(buf));
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | /*********************************************************************
|
---|
50 | * CRTDLL__strdec (CRTDLL.282)
|
---|
51 | */
|
---|
52 | char * CDECL CRTDLL__strdec( const char *, const char *p )
|
---|
53 | {
|
---|
54 | dprintf2(("CRTDLL: _strdec\n"));
|
---|
55 | return( (char *)(p-1) );
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | /*********************************************************************
|
---|
60 | * CRTDLL__strdup (CRTDLL.283)
|
---|
61 | */
|
---|
62 | LPSTR CDECL CRTDLL__strdup(LPCSTR ptr)
|
---|
63 | {
|
---|
64 | dprintf2(("CRTDLL: _strdup\n"));
|
---|
65 | return HEAP_strdupA(GetProcessHeap(),0,ptr);
|
---|
66 | }
|
---|
67 |
|
---|
68 |
|
---|
69 | /*********************************************************************
|
---|
70 | * _strerror (CRTDLL.284)
|
---|
71 | */
|
---|
72 | char * CDECL CRTDLL__strerror(const char *s)
|
---|
73 | {
|
---|
74 | dprintf(("CRTDLL: _strerror\n"));
|
---|
75 | return (_strerror((char*)s));
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | /*********************************************************************
|
---|
80 | * _stricmp (CRTDLL.285)
|
---|
81 | */
|
---|
82 | int CDECL CRTDLL__stricmp(const LPSTR str1,
|
---|
83 | const LPSTR str2)
|
---|
84 | {
|
---|
85 | dprintf2(("CRTDLL: _stricmp(%s,%s)\n",
|
---|
86 | str1,
|
---|
87 | str2));
|
---|
88 |
|
---|
89 | return (stricmp(str1, str2));
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 |
|
---|
94 | /*********************************************************************
|
---|
95 | * CRTDLL__stricoll (CRTDLL.286)
|
---|
96 | */
|
---|
97 | int CDECL CRTDLL__stricoll( const char *s1, const char *s2 )
|
---|
98 | {
|
---|
99 | dprintf2(("CRTDLL: _stricoll\n"));
|
---|
100 | return stricmp(s1,s2);
|
---|
101 | }
|
---|
102 |
|
---|
103 |
|
---|
104 | /*********************************************************************
|
---|
105 | * CRTDLL__strinc (CRTDLL.287)
|
---|
106 | */
|
---|
107 | char * CDECL CRTDLL__strinc( const char *p )
|
---|
108 | {
|
---|
109 | dprintf2(("CRTDLL: _strinc\n"));
|
---|
110 | return( (char *)(p+1) );
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 | /*********************************************************************
|
---|
115 | * _strlwr (CRTDLL.288)
|
---|
116 | */
|
---|
117 | CHAR * CDECL CRTDLL__strlwr(char *x)
|
---|
118 | {
|
---|
119 | char *y =x;
|
---|
120 |
|
---|
121 | dprintf2(("CRTDLL: _strlwr got %s\n", x));
|
---|
122 | while (*y) {
|
---|
123 | if ((*y > 0x40) && (*y< 0x5b))
|
---|
124 | *y = *y + 0x20;
|
---|
125 | y++;
|
---|
126 | }
|
---|
127 | dprintf2((" returned %s\n", x));
|
---|
128 |
|
---|
129 | return x;
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 | /*********************************************************************
|
---|
134 | * CRTDLL__strncnt (CRTDLL.289)
|
---|
135 | */
|
---|
136 | size_t CDECL CRTDLL__strncnt( const char *p, size_t l )
|
---|
137 | {
|
---|
138 | dprintf2(("CRTDLL: _strncnt\n"));
|
---|
139 | size_t i;
|
---|
140 | i = strlen(p);
|
---|
141 | return( (i>l) ? l : i );
|
---|
142 | }
|
---|
143 |
|
---|
144 |
|
---|
145 | /*********************************************************************
|
---|
146 | * CRTDLL__strnextc (CRTDLL.290)
|
---|
147 | */
|
---|
148 | unsigned int CDECL CRTDLL__strnextc( const char *p )
|
---|
149 | {
|
---|
150 | dprintf2(("CRTDLL: _strnextc\n"));
|
---|
151 | return( (unsigned int)*p );
|
---|
152 | }
|
---|
153 |
|
---|
154 |
|
---|
155 | /*********************************************************************
|
---|
156 | * CRTDLL__strnicmp (CRTDLL.291)
|
---|
157 | */
|
---|
158 | int CDECL CRTDLL__strnicmp( LPCSTR s1, LPCSTR s2, INT n )
|
---|
159 | {
|
---|
160 | dprintf2(("CRTDLL: _strnicmp (%s,%s,%d)\n",
|
---|
161 | s1,
|
---|
162 | s2,
|
---|
163 | n));
|
---|
164 |
|
---|
165 | // @@@PH: sure it's not a UNICODE API?
|
---|
166 | return (lstrncmpiA(s1,s2,n));
|
---|
167 | }
|
---|
168 |
|
---|
169 |
|
---|
170 | /*********************************************************************
|
---|
171 | * CRTDLL__strninc (CRTDLL.292)
|
---|
172 | */
|
---|
173 | char * CDECL CRTDLL__strninc( const char *p, size_t l )
|
---|
174 | {
|
---|
175 | dprintf2(("CRTDLL: _strninc\n"));
|
---|
176 | return( (char *)(p+l) );
|
---|
177 | }
|
---|
178 |
|
---|
179 |
|
---|
180 | /*********************************************************************
|
---|
181 | * CRTDLL__strnset (CRTDLL.293)
|
---|
182 | */
|
---|
183 | char * CDECL CRTDLL__strnset(char *string, int c, size_t count)
|
---|
184 | {
|
---|
185 | dprintf2(("CRTDLL: _strnset\n"));
|
---|
186 | char *dst;
|
---|
187 |
|
---|
188 | dst = string;
|
---|
189 | while (count > 0 && *dst != 0)
|
---|
190 | {
|
---|
191 | *dst++ = (char)c;
|
---|
192 | --count;
|
---|
193 | }
|
---|
194 | return string;
|
---|
195 | }
|
---|
196 |
|
---|
197 |
|
---|
198 | /*********************************************************************
|
---|
199 | * CRTDLL__strrev (CRTDLL.294)
|
---|
200 | */
|
---|
201 | char * CDECL CRTDLL__strrev( char *string )
|
---|
202 | {
|
---|
203 | dprintf2(("CRTDLL: _strrev\n"));
|
---|
204 | char *p, *q, c;
|
---|
205 |
|
---|
206 | p = q = string;
|
---|
207 | while (*q != 0)
|
---|
208 | ++q;
|
---|
209 | --q; /* Benign, as string must be != 0 */
|
---|
210 | while ((size_t)q > (size_t)p)
|
---|
211 | {
|
---|
212 | c = *p; *p = *q; *q = c;
|
---|
213 | ++p; --q;
|
---|
214 | }
|
---|
215 | return string;
|
---|
216 | }
|
---|
217 |
|
---|
218 |
|
---|
219 | /*********************************************************************
|
---|
220 | * CRTDLL__strset (CRTDLL.295)
|
---|
221 | */
|
---|
222 | char * CDECL CRTDLL__strset(char *string, int c)
|
---|
223 | {
|
---|
224 | dprintf2(("CRTDLL: _strset\n"));
|
---|
225 | char *dst;
|
---|
226 |
|
---|
227 | dst = string;
|
---|
228 | while (*dst != 0)
|
---|
229 | *dst++ = (char)c;
|
---|
230 | return string;
|
---|
231 | }
|
---|
232 |
|
---|
233 |
|
---|
234 | /*********************************************************************
|
---|
235 | * CRTDLL__strspnp (CRTDLL.296)
|
---|
236 | */
|
---|
237 | char * CDECL CRTDLL__strspnp( const char *p1, const char *p2 )
|
---|
238 | {
|
---|
239 | dprintf2(("CRTDLL: _strspnp\n"));
|
---|
240 | return( (*(p1 += strspn(p1,p2))!='\0') ? (char*)p1 : NULL );
|
---|
241 | }
|
---|
242 |
|
---|
243 |
|
---|
244 | /*********************************************************************
|
---|
245 | * CRTDLL__strtime (CRTDLL.297)
|
---|
246 | */
|
---|
247 | char * CDECL CRTDLL__strtime( char *buf )
|
---|
248 | {
|
---|
249 | dprintf2(("CRTDLL: _strtime\n"));
|
---|
250 | return (_strtime(buf));
|
---|
251 | }
|
---|
252 |
|
---|
253 |
|
---|
254 | /*********************************************************************
|
---|
255 | * _strupr (CRTDLL.298)
|
---|
256 | */
|
---|
257 | LPSTR CDECL CRTDLL__strupr(LPSTR x)
|
---|
258 | {
|
---|
259 | dprintf2(("CRTDLL: _strupr(%s)\n",
|
---|
260 | x));
|
---|
261 |
|
---|
262 | LPSTR y=x;
|
---|
263 |
|
---|
264 | while (*y)
|
---|
265 | {
|
---|
266 | *y=toupper(*y);
|
---|
267 | y++;
|
---|
268 | }
|
---|
269 | return x;
|
---|
270 | }
|
---|
271 |
|
---|
272 |
|
---|
273 | /*********************************************************************
|
---|
274 | * strcat (CRTDLL.459)
|
---|
275 | */
|
---|
276 | LPSTR CDECL CRTDLL_strcat( LPSTR str1,
|
---|
277 | const LPSTR str2)
|
---|
278 | {
|
---|
279 | dprintf2(("CRTDLL: strcat\n"));
|
---|
280 |
|
---|
281 | return (strcat(str1, str2));
|
---|
282 | }
|
---|
283 |
|
---|
284 |
|
---|
285 | /*********************************************************************
|
---|
286 | * strchr (CRTDLL.460)
|
---|
287 | */
|
---|
288 | LPSTR CDECL CRTDLL_strchr(const LPSTR str,
|
---|
289 | int i)
|
---|
290 | {
|
---|
291 | dprintf2(("CRTDLL: strchr(%s,%08xh)\n",
|
---|
292 | str,
|
---|
293 | i));
|
---|
294 |
|
---|
295 | return (strchr(str, i));
|
---|
296 | }
|
---|
297 |
|
---|
298 |
|
---|
299 | /*********************************************************************
|
---|
300 | * strcmp (CRTDLL.461)
|
---|
301 | */
|
---|
302 | int CDECL CRTDLL_strcmp(const LPSTR str1,
|
---|
303 | const LPSTR str2)
|
---|
304 | {
|
---|
305 | dprintf2(("CRTDLL: strcmp(%s,%s)\n",
|
---|
306 | str1,
|
---|
307 | str2));
|
---|
308 |
|
---|
309 | return (strcmp(str1, str2));
|
---|
310 | }
|
---|
311 |
|
---|
312 |
|
---|
313 | /*********************************************************************
|
---|
314 | * strcoll (CRTDLL.462)
|
---|
315 | */
|
---|
316 | int CDECL CRTDLL_strcoll( const char *s1, const char *s2 )
|
---|
317 | {
|
---|
318 | dprintf2(("CRTDLL: strcoll\n"));
|
---|
319 | return strcoll(s1, s2);
|
---|
320 | }
|
---|
321 |
|
---|
322 |
|
---|
323 | /*********************************************************************
|
---|
324 | * strcpy (CRTDLL.463)
|
---|
325 | */
|
---|
326 | LPSTR CDECL CRTDLL_strcpy( LPSTR str1,
|
---|
327 | const LPSTR str2)
|
---|
328 | {
|
---|
329 | dprintf2(("CRTDLL: strcpy\n"));
|
---|
330 |
|
---|
331 | return (strcpy(str1, str2));
|
---|
332 | }
|
---|
333 |
|
---|
334 |
|
---|
335 | /*********************************************************************
|
---|
336 | * strcspn (CRTDLL.464)
|
---|
337 | */
|
---|
338 | size_t CDECL CRTDLL_strcspn(const LPSTR str1,
|
---|
339 | LPSTR str2)
|
---|
340 | {
|
---|
341 | dprintf2(("CRTDLL: strcspn(%s,%s)\n",
|
---|
342 | str1,
|
---|
343 | str2));
|
---|
344 |
|
---|
345 | return (strcspn(str1, str2));
|
---|
346 | }
|
---|
347 |
|
---|
348 |
|
---|
349 | /*********************************************************************
|
---|
350 | * strerror (CRTDLL.465)
|
---|
351 | */
|
---|
352 | char * CDECL CRTDLL_strerror( int errnum )
|
---|
353 | {
|
---|
354 | dprintf2(("CRTDLL: strerror\n"));
|
---|
355 | return strerror(errnum);
|
---|
356 | }
|
---|
357 |
|
---|
358 |
|
---|
359 | /*********************************************************************
|
---|
360 | * strftime (CRTDLL.466)
|
---|
361 | */
|
---|
362 | size_t CDECL CRTDLL_strftime( char *s, size_t maxsiz, const char *fmt, const struct tm *tp )
|
---|
363 | {
|
---|
364 | dprintf2(("CRTDLL: strftime\n"));
|
---|
365 | return strftime(s, maxsiz, fmt, tp);
|
---|
366 | }
|
---|
367 |
|
---|
368 |
|
---|
369 | /*********************************************************************
|
---|
370 | * strlen (CRTDLL.467)
|
---|
371 | */
|
---|
372 | size_t CDECL CRTDLL_strlen(const LPSTR str)
|
---|
373 | {
|
---|
374 | dprintf2(("CRTDLL: strlen(%s)\n",
|
---|
375 | str));
|
---|
376 |
|
---|
377 | return (strlen(str));
|
---|
378 | }
|
---|
379 |
|
---|
380 |
|
---|
381 | /*********************************************************************
|
---|
382 | * strncat (CRTDLL.468)
|
---|
383 | */
|
---|
384 | LPSTR CDECL CRTDLL_strncat( LPSTR str1,
|
---|
385 | const LPSTR str2,
|
---|
386 | size_t i)
|
---|
387 | {
|
---|
388 | dprintf2(("CRTDLL: strncat(%s,%s,%08xh)\n",
|
---|
389 | str1,
|
---|
390 | str2,
|
---|
391 | i));
|
---|
392 |
|
---|
393 | return (strncat(str1, str2, i));
|
---|
394 | }
|
---|
395 |
|
---|
396 |
|
---|
397 | /*********************************************************************
|
---|
398 | * strncmp (CRTDLL.469)
|
---|
399 | */
|
---|
400 | int CDECL CRTDLL_strncmp(const LPSTR str1,
|
---|
401 | const LPSTR str2,
|
---|
402 | size_t i)
|
---|
403 | {
|
---|
404 | dprintf2(("CRTDLL: strncmp(%s,%s,%08xh)\n",
|
---|
405 | str1,
|
---|
406 | str2,
|
---|
407 | i));
|
---|
408 |
|
---|
409 | return (strncmp(str1, str2, i));
|
---|
410 | }
|
---|
411 |
|
---|
412 |
|
---|
413 | /*********************************************************************
|
---|
414 | * strncpy (CRTDLL.470)
|
---|
415 | */
|
---|
416 | LPSTR CDECL CRTDLL_strncpy(const LPSTR str1,
|
---|
417 | const LPSTR str2,
|
---|
418 | size_t i)
|
---|
419 | {
|
---|
420 | dprintf2(("CRTDLL: strncpy(%s,%s,%08xh)\n",
|
---|
421 | str1,
|
---|
422 | str2,
|
---|
423 | i));
|
---|
424 |
|
---|
425 | return (strncpy(str1, str2, i));
|
---|
426 | }
|
---|
427 |
|
---|
428 |
|
---|
429 | /*********************************************************************
|
---|
430 | * strpbrk (CRTDLL.471)
|
---|
431 | */
|
---|
432 | LPSTR CDECL CRTDLL_strpbrk(const LPSTR str1,
|
---|
433 | const LPSTR str2)
|
---|
434 | {
|
---|
435 | dprintf2(("CRTDLL: strpbrk(%s,%s)\n",
|
---|
436 | str1,
|
---|
437 | str2));
|
---|
438 |
|
---|
439 | return (strpbrk(str1, str2));
|
---|
440 | }
|
---|
441 |
|
---|
442 |
|
---|
443 | /*********************************************************************
|
---|
444 | * strrchr (CRTDLL.472)
|
---|
445 | */
|
---|
446 | LPSTR CDECL CRTDLL_strrchr(const LPSTR str,
|
---|
447 | size_t i)
|
---|
448 | {
|
---|
449 | dprintf2(("CRTDLL: strrchr(%s,%08xh)\n",
|
---|
450 | str,
|
---|
451 | i));
|
---|
452 |
|
---|
453 | return (strrchr(str, i));
|
---|
454 | }
|
---|
455 |
|
---|
456 |
|
---|
457 | /*********************************************************************
|
---|
458 | * strspn (CRTDLL.473)
|
---|
459 | */
|
---|
460 | size_t CDECL CRTDLL_strspn(const LPSTR str1,
|
---|
461 | const LPSTR str2)
|
---|
462 | {
|
---|
463 | dprintf2(("CRTDLL: strspn(%s,%s)\n",
|
---|
464 | str1,
|
---|
465 | str2));
|
---|
466 |
|
---|
467 | return (strspn(str1, str2));
|
---|
468 | }
|
---|
469 |
|
---|
470 |
|
---|
471 | /*********************************************************************
|
---|
472 | * strstr (CRTDLL.474)
|
---|
473 | */
|
---|
474 | LPSTR CDECL CRTDLL_strstr(const LPSTR str1,
|
---|
475 | const LPSTR str2)
|
---|
476 | {
|
---|
477 | dprintf2(("CRTDLL: strstr(%s,%s)\n",
|
---|
478 | str1,
|
---|
479 | str2));
|
---|
480 |
|
---|
481 | return (strstr(str1, str2));
|
---|
482 | }
|
---|
483 |
|
---|
484 |
|
---|
485 | /*********************************************************************
|
---|
486 | * strtod (CRTDLL.475)
|
---|
487 | */
|
---|
488 | double CDECL CRTDLL_strtod( const char *nptr, char **endptr )
|
---|
489 | {
|
---|
490 | dprintf2(("CRTDLL: strtod\n"));
|
---|
491 | return strtod(nptr, endptr);
|
---|
492 | }
|
---|
493 |
|
---|
494 |
|
---|
495 | /*********************************************************************
|
---|
496 | * strtok (CRTDLL.476)
|
---|
497 | */
|
---|
498 | char * CDECL CRTDLL_strtok( char *s1, const char *s2 )
|
---|
499 | {
|
---|
500 | dprintf2(("CRTDLL: strtok\n"));
|
---|
501 | return strtok(s1, s2);
|
---|
502 | }
|
---|
503 |
|
---|
504 |
|
---|
505 | /*********************************************************************
|
---|
506 | * strtol (CRTDLL.477)
|
---|
507 | */
|
---|
508 | long int CDECL CRTDLL_strtol( const char *nptr, char **endptr, int base )
|
---|
509 | {
|
---|
510 | dprintf2(("CRTDLL: strtol\n"));
|
---|
511 | return strtol(nptr, endptr, base);
|
---|
512 | }
|
---|
513 |
|
---|
514 |
|
---|
515 | /*********************************************************************
|
---|
516 | * strtoul (CRTDLL.478)
|
---|
517 | */
|
---|
518 | unsigned long CDECL CRTDLL_strtoul( const char *nptr, char **endptr, int base )
|
---|
519 | {
|
---|
520 | dprintf2(("CRTDLL: strtoul\n"));
|
---|
521 | return strtoul(nptr, endptr, base);
|
---|
522 | }
|
---|
523 |
|
---|
524 |
|
---|
525 | /*********************************************************************
|
---|
526 | * strxfrm (CRTDLL.479)
|
---|
527 | */
|
---|
528 | size_t CDECL CRTDLL_strxfrm( char *s1, const char *s2, size_t n )
|
---|
529 | {
|
---|
530 | dprintf2(("CRTDLL: strxfrm\n"));
|
---|
531 | return strxfrm(s1, s2, n);
|
---|
532 | }
|
---|