VirtualBox

Ignore:
Timestamp:
Aug 5, 2022 12:26:04 AM (2 years ago)
Author:
vboxsync
Message:

IPRT/nocrt: Added strdup, stricmp, strtok, strcat, strncat, strnlen and strtok_r implementations. bugref:10261

Location:
trunk/src/VBox/Runtime/common/string
Files:
4 added
1 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/string/strcat.cpp

    r96044 r96045  
    11/* $Id$ */
    22/** @file
    3  * IPRT - CRT Strings, strcpy().
     3 * IPRT - CRT Strings, strcat().
    44 */
    55
     
    3434
    3535/**
    36  * Copy a string
     36 * Append one string to another.
    3737 *
    3838 * @returns Pointer to destination string
    39  * @param   pszDst      Will contain a copy of pszSrc.
     39 * @param   pszDst      String to append @a pszSrc to.
    4040 * @param   pszSrc      Zero terminated string.
    4141 */
    42 #ifdef IPRT_NO_CRT
    43 # undef strcpy
    44 char *RT_NOCRT(strcpy)(char *pszDst, const char *pszSrc)
    45 #else
    46 char *strcpy(char *pszDst, const char *pszSrc)
    47 #endif
     42#undef strcat
     43char *RT_NOCRT(strcat)(char *pszDst, const char *pszSrc)
    4844{
    4945    char * const pszRet = pszDst;
     46    pszDst = RTStrEnd(pszDst, RTSTR_MAX);
    5047    while ((*pszDst = *pszSrc++) != '\0')
    5148        pszDst++;
     
    5350    return pszRet;
    5451}
    55 RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(strcpy);
     52RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(strcat);
    5653
  • trunk/src/VBox/Runtime/common/string/strlen.cpp

    r96043 r96045  
    4141#ifdef IPRT_NO_CRT
    4242# undef strlen
    43 size_t strlen(const char *pszString)
     43size_t RT_NOCRT(strlen)(const char *pszString)
    4444#elif RT_MSC_PREREQ(RT_MSC_VER_VS2005)
    4545__checkReturn size_t  __cdecl strlen(__in_z  const char *pszString)
  • trunk/src/VBox/Runtime/common/string/strncat.cpp

    r96044 r96045  
    11/* $Id$ */
    22/** @file
    3  * IPRT - CRT Strings, strcpy().
     3 * IPRT - No-CRT Strings, strncat().
    44 */
    55
     
    3434
    3535/**
    36  * Copy a string
     36 * Append a substring to an existing string.
    3737 *
    3838 * @returns Pointer to destination string
    39  * @param   pszDst      Will contain a copy of pszSrc.
     39 * @param   pszDst      String to append @a cchMaxSrc chars from @a pszSrc to,
     40 *                      plus a zero terminator.
    4041 * @param   pszSrc      Zero terminated string.
     42 * @param   cchMaxSrc   Maximum number of chars to copy from @a pszSrc.
    4143 */
    42 #ifdef IPRT_NO_CRT
    43 # undef strcpy
    44 char *RT_NOCRT(strcpy)(char *pszDst, const char *pszSrc)
    45 #else
    46 char *strcpy(char *pszDst, const char *pszSrc)
    47 #endif
     44#undef strncat
     45char *RT_NOCRT(strncat)(char *pszDst, const char *pszSrc, size_t cchMaxSrc)
    4846{
    4947    char * const pszRet = pszDst;
    50     while ((*pszDst = *pszSrc++) != '\0')
    51         pszDst++;
     48
     49    pszDst = RTStrEnd(pszDst, RTSTR_MAX);
     50
     51    char ch;
     52    while (cchMaxSrc-- > 0 && (ch = *pszSrc++) != '\0')
     53        *pszDst++ = ch;
     54    *pszDst = '\0';
    5255
    5356    return pszRet;
    5457}
    55 RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(strcpy);
     58RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(strncat);
    5659
  • trunk/src/VBox/Runtime/common/string/strnlen.cpp

    r96043 r96045  
    11/* $Id$ */
    22/** @file
    3  * IPRT - CRT Strings, strlen().
     3 * IPRT - CRT Strings, strnlen().
    44 */
    55
     
    3434
    3535/**
    36  * Find the length of a zeroterminated byte string.
     36 * Find the length of a zeroterminated byte string, but only up to a given
     37 * limit.
    3738 *
    38  * @returns String length in bytes.
     39 * @returns String length in bytes, or cchMax if too long.
    3940 * @param   pszString   Zero terminated string.
     41 * @param   cchMax      Max number of chars to search for the end.
    4042 */
    41 #ifdef IPRT_NO_CRT
    42 # undef strlen
    43 size_t strlen(const char *pszString)
    44 #elif RT_MSC_PREREQ(RT_MSC_VER_VS2005)
    45 __checkReturn size_t  __cdecl strlen(__in_z  const char *pszString)
    46 #else
    47 size_t strlen(const char *pszString)
    48 #endif
     43#undef strnlen
     44size_t RT_NOCRT(strnlen)(const char *pszString, size_t cchMax)
    4945{
    50     const char *psz = pszString;
    51     while (*psz)
    52         psz++;
    53     return psz - pszString;
     46    const char * const pszStart = pszString;
     47    while (cchMax-- > 0 && *pszString)
     48        pszString++;
     49    return pszString - pszStart;
    5450}
    55 RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(strlen);
     51RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(strnlen);
    5652
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette