Changeset 4667 for trunk/src/crtdll/crt_string.cpp
- Timestamp:
- Nov 22, 2000, 12:49:04 AM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/crtdll/crt_string.cpp
r2844 r4667 1 /* $Id: crt_string.cpp,v 1. 2 2000-02-21 10:34:01 sandervlExp $ */1 /* $Id: crt_string.cpp,v 1.3 2000-11-21 23:48:49 phaller Exp $ */ 2 2 3 3 /* … … 13 13 * Copyright 1999-2000 Jens Wiessner 14 14 * 15 * CRTDLL - string functions16 * 15 * Implementation Notes: 16 * MT Safe. 17 17 */ 18 18 … … 24 24 25 25 26 #include "crtdll.h" 27 28 29 DEFAULT_DEBUG_CHANNEL(crtdll); 30 26 31 /********************************************************************* 27 32 * _strcmpi (CRTDLL.280) … … 48 53 49 54 /********************************************************************* 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 55 * _stricmp (CRTDLL.285) 81 56 */ … … 99 74 dprintf2(("CRTDLL: _stricoll\n")); 100 75 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 76 } 112 77 … … 132 97 133 98 /********************************************************************* 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 99 * CRTDLL__strnicmp (CRTDLL.291) 157 100 */ … … 167 110 } 168 111 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 112 243 113 … … 348 218 349 219 /********************************************************************* 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 220 * strftime (CRTDLL.466) 361 221 */ … … 531 391 return strxfrm(s1, s2, n); 532 392 } 393 394 395 /* INTERNAL: CRTDLL_malloc() based strndup */ 396 LPSTR __CRTDLL__strndup(LPSTR buf, INT size); 397 LPSTR __CRTDLL__strndup(LPSTR buf, INT size) 398 { 399 char* ret; 400 int len = strlen(buf); 401 int max_len; 402 403 max_len = size <= len? size : len + 1; 404 405 ret = (char*)CRTDLL_malloc(max_len); 406 if (ret) 407 { 408 memcpy(ret,buf,max_len); 409 ret[max_len] = 0; 410 } 411 return ret; 412 } 413 414 415 /********************************************************************* 416 * _strdec (CRTDLL.282) 417 * 418 * Return the byte before str2 while it is >= to str1. 419 * 420 * PARAMS 421 * str1 [in] Terminating string 422 * 423 * sre2 [in] string to start searching from 424 * 425 * RETURNS 426 * The byte before str2, or str1, whichever is greater 427 * 428 * NOTES 429 * This function is implemented as tested with windows, which means 430 * it does not have a terminating condition. It always returns 431 * the byte before str2. Use with extreme caution! 432 */ 433 LPSTR CDECL CRTDLL__strdec(LPSTR str1, LPSTR str2) 434 { 435 /* Hmm. While the docs suggest that the following should work... */ 436 /* return (str2<=str1?0:str2-1); */ 437 /* ...Version 2.50.4170 (NT) from win98 constantly decrements! */ 438 return str2-1; 439 } 440 441 442 /********************************************************************* 443 * _strdup (CRTDLL.285) 444 * 445 * Duplicate a string. 446 */ 447 LPSTR CDECL CRTDLL__strdup(LPCSTR ptr) 448 { 449 LPSTR ret = (LPSTR)CRTDLL_malloc(strlen(ptr)+1); 450 if (ret) strcpy( ret, ptr ); 451 return ret; 452 } 453 454 455 /********************************************************************* 456 * _strinc (CRTDLL.287) 457 * 458 * Return a pointer to the next character in a string 459 */ 460 LPSTR CDECL CRTDLL__strinc(LPSTR str) 461 { 462 return str+1; 463 } 464 465 466 /********************************************************************* 467 * _strnextc (CRTDLL.290) 468 * 469 * Return an unsigned int from a string. 470 */ 471 UINT CDECL CRTDLL__strnextc(LPCSTR str) 472 { 473 return (UINT)*str; 474 } 475 476 477 /********************************************************************* 478 * _strninc (CRTDLL.292) 479 * 480 * Return a pointer to the 'n'th character in a string 481 */ 482 LPSTR CDECL CRTDLL__strninc(LPSTR str, INT n) 483 { 484 return str+n; 485 } 486 487 488 /********************************************************************* 489 * _strnset (CRTDLL.293) 490 * 491 * Fill a string with a character up to a certain length 492 */ 493 LPSTR CDECL CRTDLL__strnset(LPSTR str, INT c, INT len) 494 { 495 if (len > 0 && str) 496 while (*str && len--) 497 *str++ = c; 498 return str; 499 } 500 501 502 /********************************************************************* 503 * _strrev (CRTDLL.294) 504 * 505 * Reverse a string in place 506 */ 507 LPSTR CDECL CRTDLL__strrev (LPSTR str) 508 { 509 LPSTR p1; 510 LPSTR p2; 511 512 if (str && *str) 513 for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2) 514 { 515 *p1 ^= *p2; 516 *p2 ^= *p1; 517 *p1 ^= *p2; 518 } 519 520 return str; 521 } 522 523 /********************************************************************* 524 * _strset (CRTDLL.295) 525 * 526 * Fill a string with a value. 527 */ 528 LPSTR CDECL CRTDLL__strset (LPSTR str, INT set) 529 { 530 char *ptr = str; 531 532 while (*ptr) 533 *ptr++ = set; 534 535 return str; 536 } 537 538 539 /********************************************************************* 540 * _strncnt (CRTDLL.289) 541 * 542 * Return the length of a string or the maximum given length. 543 */ 544 LONG CDECL CRTDLL__strncnt(LPSTR str, LONG max) 545 { 546 LONG len = strlen(str); 547 return (len > max? max : len); 548 } 549 550 551 /********************************************************************* 552 * _strspnp (CRTDLL.296) 553 * 554 */ 555 LPSTR CDECL CRTDLL__strspnp(LPSTR str1, LPSTR str2) 556 { 557 str1 += strspn(str1,str2); 558 return *str1? str1 : 0; 559 } 560 561 562 /********************************************************************* 563 * _swab (CRTDLL.299) 564 * 565 * Copy from source to dest alternating bytes (i.e 16 bit big-to-little 566 * endian or vice versa). 567 */ 568 void CDECL CRTDLL__swab(LPSTR src, LPSTR dst, INT len) 569 { 570 //_swab(s1, s2, i); 571 572 if (len > 1) 573 { 574 len = (unsigned)len >> 1; 575 576 while (len--) { 577 *dst++ = src[1]; 578 *dst++ = *src++; 579 src++; 580 } 581 } 582 }
Note:
See TracChangeset
for help on using the changeset viewer.