string.c 21 KB
Newer Older
1 2 3 4
/*
 * NTDLL string functions
 *
 * Copyright 2000 Alexandre Julliard
5
 * Copyright 2000 Jon Griffiths
6
 * Copyright 2003 Thomas Mertes
7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 22 23
 */

#include "config.h"
24
#include "wine/port.h"
25 26

#include <ctype.h>
27
#include <stdarg.h>
28 29
#include <stdlib.h>
#include <stdio.h>
30
#include <string.h>
31
#include <search.h>
32 33

#include "windef.h"
34 35
#include "winternl.h"

36

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
/*********************************************************************
 *                  memchr   (NTDLL.@)
 */
void * __cdecl NTDLL_memchr( const void *ptr, int c, size_t n )
{
    return memchr( ptr, c, n );
}


/*********************************************************************
 *                  memcmp   (NTDLL.@)
 */
int __cdecl NTDLL_memcmp( const void *ptr1, const void *ptr2, size_t n )
{
    return memcmp( ptr1, ptr2, n );
}


/*********************************************************************
 *                  memcpy   (NTDLL.@)
 *
 * NOTES
 *  Behaves like memmove.
 */
void * __cdecl NTDLL_memcpy( void *dst, const void *src, size_t n )
{
    return memmove( dst, src, n );
}


/*********************************************************************
 *                  memmove   (NTDLL.@)
 */
void * __cdecl NTDLL_memmove( void *dst, const void *src, size_t n )
{
    return memmove( dst, src, n );
}


/*********************************************************************
 *                  memset   (NTDLL.@)
 */
void * __cdecl NTDLL_memset( void *dst, int c, size_t n )
{
    return memset( dst, c, n );
}


/*********************************************************************
 *                  bsearch   (NTDLL.@)
 */
void * __cdecl NTDLL_bsearch( const void *key, const void *base, size_t nmemb,
                              size_t size, int (*compar)(const void *, const void *) )
{
    return bsearch( key, base, nmemb, size, compar );
}


/*********************************************************************
 *                  qsort   (NTDLL.@)
 */
void __cdecl NTDLL_qsort( void *base, size_t nmemb, size_t size,
                          int(*compar)(const void *, const void *) )
{
101
    qsort( base, nmemb, size, compar );
102 103 104 105 106 107
}


/*********************************************************************
 *                  _lfind   (NTDLL.@)
 */
108
void * __cdecl _lfind( const void *key, const void *base, unsigned int *nmemb,
109
                       size_t size, int(*compar)(const void *, const void *) )
110
{
111 112
    size_t n = *nmemb;
    return lfind( key, base, &n, size, compar );
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
}


/*********************************************************************
 *                  strcat   (NTDLL.@)
 */
char * __cdecl NTDLL_strcat( char *dst, const char *src )
{
    return strcat( dst, src );
}


/*********************************************************************
 *                  strchr   (NTDLL.@)
 */
char * __cdecl NTDLL_strchr( const char *str, int c )
{
    return strchr( str, c );
}


/*********************************************************************
 *                  strcmp   (NTDLL.@)
 */
int __cdecl NTDLL_strcmp( const char *str1, const char *str2 )
{
    return strcmp( str1, str2 );
}


/*********************************************************************
 *                  strcpy   (NTDLL.@)
 */
char * __cdecl NTDLL_strcpy( char *dst, const char *src )
{
    return strcpy( dst, src );
}


/*********************************************************************
 *                  strcspn   (NTDLL.@)
 */
size_t __cdecl NTDLL_strcspn( const char *str, const char *reject )
{
    return strcspn( str, reject );
}


/*********************************************************************
 *                  strlen   (NTDLL.@)
 */
size_t __cdecl NTDLL_strlen( const char *str )
{
    return strlen( str );
}


/*********************************************************************
 *                  strncat   (NTDLL.@)
 */
char * __cdecl NTDLL_strncat( char *dst, const char *src, size_t len )
{
    return strncat( dst, src, len );
}


/*********************************************************************
 *                  strncmp   (NTDLL.@)
 */
int __cdecl NTDLL_strncmp( const char *str1, const char *str2, size_t len )
{
    return strncmp( str1, str2, len );
}


/*********************************************************************
 *                  strncpy   (NTDLL.@)
 */
char * __cdecl NTDLL_strncpy( char *dst, const char *src, size_t len )
{
    return strncpy( dst, src, len );
}


/*********************************************************************
 *                  strpbrk   (NTDLL.@)
 */
char * __cdecl NTDLL_strpbrk( const char *str, const char *accept )
{
    return strpbrk( str, accept );
}


/*********************************************************************
 *                  strrchr   (NTDLL.@)
 */
char * __cdecl NTDLL_strrchr( const char *str, int c )
{
    return strrchr( str, c );
}


/*********************************************************************
 *                  strspn   (NTDLL.@)
 */
size_t __cdecl NTDLL_strspn( const char *str, const char *accept )
{
    return strspn( str, accept );
}


/*********************************************************************
 *                  strstr   (NTDLL.@)
 */
char * __cdecl NTDLL_strstr( const char *haystack, const char *needle )
{
    return strstr( haystack, needle );
}


/*********************************************************************
 *                  _memccpy   (NTDLL.@)
 */
void * __cdecl _memccpy( void *dst, const void *src, int c, size_t n )
{
    return memccpy( dst, src, c, n );
}


242
/*********************************************************************
243
 *                  _memicmp   (NTDLL.@)
Jon Griffiths's avatar
Jon Griffiths committed
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
 *
 * Compare two blocks of memory as strings, ignoring case.
 *
 * PARAMS
 *  s1  [I] First string to compare to s2
 *  s2  [I] Second string to compare to s1
 *  len [I] Number of bytes to compare
 *
 * RETURNS
 *  An integer less than, equal to, or greater than zero indicating that
 *  s1 is less than, equal to or greater than s2 respectively.
 *
 * NOTES
 *  Any Nul characters in s1 or s2 are ignored. This function always
 *  compares up to len bytes or the first place where s1 and s2 differ.
259
 */
260
INT __cdecl _memicmp( LPCSTR s1, LPCSTR s2, DWORD len )
261 262 263 264 265 266 267 268 269 270 271
{
    int ret = 0;
    while (len--)
    {
        if ((ret = tolower(*s1) - tolower(*s2))) break;
        s1++;
        s2++;
    }
    return ret;
}

272

273
/*********************************************************************
274 275
 *                  _stricmp   (NTDLL.@)
 *                  _strcmpi   (NTDLL.@)
276
 */
277
int __cdecl _stricmp( LPCSTR str1, LPCSTR str2 )
278
{
279 280 281 282 283 284 285 286 287 288
    return strcasecmp( str1, str2 );
}


/*********************************************************************
 *                  _strnicmp   (NTDLL.@)
 */
int __cdecl _strnicmp( LPCSTR str1, LPCSTR str2, size_t n )
{
    return strncasecmp( str1, str2, n );
289 290 291
}


292
/*********************************************************************
293
 *                  _strupr   (NTDLL.@)
Jon Griffiths's avatar
Jon Griffiths committed
294 295 296 297 298 299 300 301 302
 *
 * Convert a string to upper case.
 *
 * PARAMS
 *  str [I/O] String to convert
 *
 * RETURNS
 *  str. There is no error return, if str is NULL or invalid, this
 *  function will crash.
303 304 305 306 307 308 309 310
 */
LPSTR __cdecl _strupr( LPSTR str )
{
    LPSTR ret = str;
    for ( ; *str; str++) *str = toupper(*str);
    return ret;
}

311

312
/*********************************************************************
313
 *                  _strlwr   (NTDLL.@)
314
 *
Jon Griffiths's avatar
Jon Griffiths committed
315 316 317 318 319 320 321 322
 * Convert a string to lowercase
 *
 * PARAMS
 *  str [I/O] String to convert
 *
 * RETURNS
 *  str. There is no error return, if str is NULL or invalid, this
 *  function will crash.
323 324 325 326 327 328 329 330 331
 */
LPSTR __cdecl _strlwr( LPSTR str )
{
    LPSTR ret = str;
    for ( ; *str; str++) *str = tolower(*str);
    return ret;
}


332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
/*********************************************************************
 *                  tolower   (NTDLL.@)
 */
int __cdecl NTDLL_tolower( int c )
{
    return tolower( c );
}


/*********************************************************************
 *                  toupper   (NTDLL.@)
 */
int __cdecl NTDLL_toupper( int c )
{
    return toupper( c );
}


/*********************************************************************
 *                  isalnum   (NTDLL.@)
 */
int __cdecl NTDLL_isalnum( int c )
{
    return isalnum( c );
}


/*********************************************************************
 *                  isalpha   (NTDLL.@)
 */
int __cdecl NTDLL_isalpha( int c )
{
    return isalpha( c );
}


/*********************************************************************
 *                  iscntrl   (NTDLL.@)
 */
int __cdecl NTDLL_iscntrl( int c )
{
    return iscntrl( c );
}


/*********************************************************************
 *                  isdigit   (NTDLL.@)
 */
int __cdecl NTDLL_isdigit( int c )
{
    return isdigit( c );
}


/*********************************************************************
 *                  isgraph   (NTDLL.@)
 */
int __cdecl NTDLL_isgraph( int c )
{
    return isgraph( c );
}


/*********************************************************************
 *                  islower   (NTDLL.@)
 */
int __cdecl NTDLL_islower( int c )
{
    return islower( c );
}


/*********************************************************************
 *                  isprint   (NTDLL.@)
 */
int __cdecl NTDLL_isprint( int c )
{
    return isprint( c );
}


/*********************************************************************
 *                  ispunct   (NTDLL.@)
 */
int __cdecl NTDLL_ispunct( int c )
{
    return ispunct( c );
}


/*********************************************************************
 *                  isspace   (NTDLL.@)
 */
int __cdecl NTDLL_isspace( int c )
{
    return isspace( c );
}


/*********************************************************************
 *                  isupper   (NTDLL.@)
 */
int __cdecl NTDLL_isupper( int c )
{
    return isupper( c );
}


/*********************************************************************
 *                  isxdigit   (NTDLL.@)
 */
int __cdecl NTDLL_isxdigit( int c )
{
    return isxdigit( c );
}


/*********************************************************************
 *                  strtol   (NTDLL.@)
 */
452
LONG __cdecl NTDLL_strtol( const char *nptr, char **endptr, int base )
453 454 455 456 457 458 459 460
{
    return strtol( nptr, endptr, base );
}


/*********************************************************************
 *                  strtoul   (NTDLL.@)
 */
461
ULONG __cdecl NTDLL_strtoul( const char *nptr, char **endptr, int base )
462 463 464 465 466
{
    return strtoul( nptr, endptr, base );
}


467
/*********************************************************************
468 469
 *      _ultoa   (NTDLL.@)
 *
Jon Griffiths's avatar
Jon Griffiths committed
470
 * Convert an unsigned long integer to a string.
471
 *
472
 * RETURNS
Jon Griffiths's avatar
Jon Griffiths committed
473
 *  str.
474 475
 *
 * NOTES
Jon Griffiths's avatar
Jon Griffiths committed
476 477 478 479
 *  - Converts value to a Nul terminated string which is copied to str.
 *  - The maximum length of the copied str is 33 bytes.
 *  - Does not check if radix is in the range of 2 to 36.
 *  - If str is NULL it crashes, as the native function does.
480
 */
481
char * __cdecl _ultoa(
482
    ULONG value,         /* [I] Value to be converted */
483 484
    char *str,           /* [O] Destination for the converted value */
    int radix)           /* [I] Number base for conversion */
485
{
486 487 488
    char buffer[33];
    char *pos;
    int digit;
489

490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
    pos = &buffer[32];
    *pos = '\0';

    do {
	digit = value % radix;
	value = value / radix;
	if (digit < 10) {
	    *--pos = '0' + digit;
	} else {
	    *--pos = 'a' + digit - 10;
	} /* if */
    } while (value != 0L);

    memcpy(str, pos, &buffer[32] - pos + 1);
    return str;
505 506 507 508
}


/*********************************************************************
509 510
 *      _ltoa   (NTDLL.@)
 *
Jon Griffiths's avatar
Jon Griffiths committed
511
 * Convert a long integer to a string.
512
 *
513
 * RETURNS
Jon Griffiths's avatar
Jon Griffiths committed
514
 *  str.
515 516
 *
 * NOTES
Jon Griffiths's avatar
Jon Griffiths committed
517 518
 *  - Converts value to a Nul terminated string which is copied to str.
 *  - The maximum length of the copied str is 33 bytes. If radix
519
 *  is 10 and value is negative, the value is converted with sign.
Jon Griffiths's avatar
Jon Griffiths committed
520 521
 *  - Does not check if radix is in the range of 2 to 36.
 *  - If str is NULL it crashes, as the native function does.
522
 */
523
char * __cdecl _ltoa(
524
    LONG value, /* [I] Value to be converted */
525 526
    char *str,  /* [O] Destination for the converted value */
    int radix)  /* [I] Number base for conversion */
527
{
528
    ULONG val;
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
    int negative;
    char buffer[33];
    char *pos;
    int digit;

    if (value < 0 && radix == 10) {
	negative = 1;
        val = -value;
    } else {
	negative = 0;
        val = value;
    } /* if */

    pos = &buffer[32];
    *pos = '\0';

    do {
	digit = val % radix;
	val = val / radix;
	if (digit < 10) {
	    *--pos = '0' + digit;
	} else {
	    *--pos = 'a' + digit - 10;
	} /* if */
    } while (val != 0L);

    if (negative) {
	*--pos = '-';
    } /* if */

    memcpy(str, pos, &buffer[32] - pos + 1);
    return str;
}


/*********************************************************************
 *      _itoa    (NTDLL.@)
 *
 * Converts an integer to a string.
 *
569
 * RETURNS
Jon Griffiths's avatar
Jon Griffiths committed
570
 *  str.
571 572
 *
 * NOTES
Jon Griffiths's avatar
Jon Griffiths committed
573 574
 *  - Converts value to a '\0' terminated string which is copied to str.
 *  - The maximum length of the copied str is 33 bytes. If radix
575
 *  is 10 and value is negative, the value is converted with sign.
Jon Griffiths's avatar
Jon Griffiths committed
576 577
 *  - Does not check if radix is in the range of 2 to 36.
 *  - If str is NULL it crashes, as the native function does.
578
 */
579 580 581 582
char * __cdecl _itoa(
    int value, /* [I] Value to be converted */
    char *str, /* [O] Destination for the converted value */
    int radix) /* [I] Number base for conversion */
583 584 585 586 587 588 589 590 591 592
{
    return _ltoa(value, str, radix);
}


/*********************************************************************
 *      _ui64toa   (NTDLL.@)
 *
 * Converts a large unsigned integer to a string.
 *
593
 * RETURNS
Jon Griffiths's avatar
Jon Griffiths committed
594
 *  str.
595 596
 *
 * NOTES
Jon Griffiths's avatar
Jon Griffiths committed
597 598 599 600
 *  - Converts value to a '\0' terminated string which is copied to str.
 *  - The maximum length of the copied str is 65 bytes.
 *  - Does not check if radix is in the range of 2 to 36.
 *  - If str is NULL it crashes, as the native function does.
601
 */
602 603 604 605
char * __cdecl _ui64toa(
    ULONGLONG value, /* [I] Value to be converted */
    char *str,       /* [O] Destination for the converted value */
    int radix)       /* [I] Number base for conversion */
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
{
    char buffer[65];
    char *pos;
    int digit;

    pos = &buffer[64];
    *pos = '\0';

    do {
	digit = value % radix;
	value = value / radix;
	if (digit < 10) {
	    *--pos = '0' + digit;
	} else {
	    *--pos = 'a' + digit - 10;
	} /* if */
    } while (value != 0L);

    memcpy(str, pos, &buffer[64] - pos + 1);
    return str;
}


/*********************************************************************
 *      _i64toa   (NTDLL.@)
 *
 * Converts a large integer to a string.
 *
634
 * RETURNS
Jon Griffiths's avatar
Jon Griffiths committed
635
 *  str.
636
 *
637
 * NOTES
Jon Griffiths's avatar
Jon Griffiths committed
638 639
 *  - Converts value to a Nul terminated string which is copied to str.
 *  - The maximum length of the copied str is 65 bytes. If radix
640
 *  is 10 and value is negative, the value is converted with sign.
Jon Griffiths's avatar
Jon Griffiths committed
641 642
 *  - Does not check if radix is in the range of 2 to 36.
 *  - If str is NULL it crashes, as the native function does.
643 644
 *
 * DIFFERENCES
645
 * - The native DLL converts negative values (for base 10) wrong:
Jon Griffiths's avatar
Jon Griffiths committed
646 647 648 649
 *|                     -1 is converted to -18446744073709551615
 *|                     -2 is converted to -18446744073709551614
 *|   -9223372036854775807 is converted to  -9223372036854775809
 *|   -9223372036854775808 is converted to  -9223372036854775808
650 651
 *   The native msvcrt _i64toa function and our ntdll _i64toa function
 *   do not have this bug.
652
 */
653 654 655 656
char * __cdecl _i64toa(
    LONGLONG value, /* [I] Value to be converted */
    char *str,      /* [O] Destination for the converted value */
    int radix)      /* [I] Number base for conversion */
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
{
    ULONGLONG val;
    int negative;
    char buffer[65];
    char *pos;
    int digit;

    if (value < 0 && radix == 10) {
	negative = 1;
        val = -value;
    } else {
	negative = 0;
        val = value;
    } /* if */

    pos = &buffer[64];
    *pos = '\0';

    do {
	digit = val % radix;
	val = val / radix;
	if (digit < 10) {
	    *--pos = '0' + digit;
	} else {
	    *--pos = 'a' + digit - 10;
	} /* if */
    } while (val != 0L);

    if (negative) {
	*--pos = '-';
    } /* if */

    memcpy(str, pos, &buffer[64] - pos + 1);
    return str;
691 692 693 694
}


/*********************************************************************
695 696
 *      _atoi64   (NTDLL.@)
 *
Jon Griffiths's avatar
Jon Griffiths committed
697
 * Convert a string to a large integer.
698
 *
699
 * PARAMS
Jon Griffiths's avatar
Jon Griffiths committed
700
 *  str [I] String to be converted
701 702
 *
 * RETURNS
Jon Griffiths's avatar
Jon Griffiths committed
703 704 705
 *  Success: The integer value represented by str.
 *  Failure: 0. Note that this cannot be distinguished from a successful
 *           return, if the string contains "0".
706 707
 *
 * NOTES
Jon Griffiths's avatar
Jon Griffiths committed
708 709 710
 *  - Accepts: {whitespace} [+|-] {digits}
 *  - No check is made for value overflow, only the lower 64 bits are assigned.
 *  - If str is NULL it crashes, as the native function does.
711
 */
712
LONGLONG __cdecl _atoi64( const char *str )
713
{
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
    ULONGLONG RunningTotal = 0;
    char bMinus = 0;

    while (*str == ' ' || (*str >= '\011' && *str <= '\015')) {
	str++;
    } /* while */

    if (*str == '+') {
	str++;
    } else if (*str == '-') {
	bMinus = 1;
	str++;
    } /* if */

    while (*str >= '0' && *str <= '9') {
	RunningTotal = RunningTotal * 10 + *str - '0';
	str++;
    } /* while */

    return bMinus ? -RunningTotal : RunningTotal;
734
}
735 736


737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
/*********************************************************************
 *                  atoi   (NTDLL.@)
 */
int __cdecl NTDLL_atoi( const char *nptr )
{
    return _atoi64( nptr );
}


/*********************************************************************
 *                  atol   (NTDLL.@)
 */
LONG __cdecl NTDLL_atol( const char *nptr )
{
    return _atoi64( nptr );
}


755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814
/*********************************************************************
 *                  sprintf   (NTDLL.@)
 */
int __cdecl NTDLL_sprintf( char *str, const char *format, ... )
{
    int ret;
    va_list valist;
    va_start( valist, format );
    ret = vsprintf( str, format, valist );
    va_end( valist );
    return ret;
}


/*********************************************************************
 *                  vsprintf   (NTDLL.@)
 */
int __cdecl NTDLL_vsprintf( char *str, const char *format, va_list args )
{
    return vsprintf( str, format, args );
}


/*********************************************************************
 *                  _snprintf   (NTDLL.@)
 */
int __cdecl _snprintf( char *str, size_t len, const char *format, ... )
{
    int ret;
    va_list valist;
    va_start( valist, format );
    ret = vsnprintf( str, len, format, valist );
    va_end( valist );
    return ret;
}


/*********************************************************************
 *                  _vsnprintf   (NTDLL.@)
 */
int __cdecl _vsnprintf( char *str, size_t len, const char *format, va_list args )
{
    return vsnprintf( str, len, format, args );
}


/*********************************************************************
 *                  sscanf   (NTDLL.@)
 */
int __cdecl NTDLL_sscanf( const char *str, const char *format, ... )
{
    int ret;
    va_list valist;
    va_start( valist, format );
    ret = vsscanf( str, format, valist );
    va_end( valist );
    return ret;
}


815
/*********************************************************************
816
 *		_splitpath (NTDLL.@)
Jon Griffiths's avatar
Jon Griffiths committed
817 818 819 820 821 822 823 824 825
 *
 * Split a path into its component pieces.
 *
 * PARAMS
 *  inpath [I] Path to split
 *  drv    [O] Destination for drive component (e.g. "A:"). Must be at least 3 characters.
 *  dir    [O] Destination for directory component. Should be at least MAX_PATH characters.
 *  fname  [O] Destination for File name component. Should be at least MAX_PATH characters.
 *  ext    [O] Destination for file extension component. Should be at least MAX_PATH characters.
826 827 828
 *
 * RETURNS
 *  Nothing.
829 830 831 832
 */
void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
                        char* fname, char * ext )
{
833 834 835
    const char *p, *end;

    if (inpath[0] && inpath[1] == ':')
836
    {
837 838 839 840 841 842 843
        if (drv)
        {
            drv[0] = inpath[0];
            drv[1] = inpath[1];
            drv[2] = 0;
        }
        inpath += 2;
844
    }
845 846 847 848 849 850 851
    else if (drv) drv[0] = 0;

    /* look for end of directory part */
    end = NULL;
    for (p = inpath; *p; p++) if (*p == '/' || *p == '\\') end = p + 1;

    if (end)  /* got a directory */
852
    {
853 854 855 856 857 858
        if (dir)
        {
            memcpy( dir, inpath, end - inpath );
            dir[end - inpath] = 0;
        }
        inpath = end;
859
    }
860 861
    else if (dir) dir[0] = 0;

862 863 864 865 866
    /* look for extension: what's after the last dot */
    end = NULL;
    for (p = inpath; *p; p++) if (*p == '.') end = p;

    if (!end) end = p; /* there's no extension */
867 868 869

    if (fname)
    {
870 871
        memcpy( fname, inpath, end - inpath );
        fname[end - inpath] = 0;
872
    }
873
    if (ext) strcpy( ext, end );
874
}