VirtualBox

Changeset 96045 in vbox


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
Files:
4 added
2 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r96043 r96045  
    17141714#
    17151715UNIT_VBoxNoCrtAliases = CRT symbol alias for the rtnocr_xxx implementations
     1716
     1717# Only adding the VBOX_NOCRT_ALIASES property to library targets for now:
     1718PROPS_ACCUMULATE_L           += VBOX_NOCRT_ALIASES
     1719PROPS_ACCUMULATE_L_LNK       += VBOX_NOCRT_ALIASES
     1720PROPS_LIBRARIES_ACCUMULATE_L += VBOX_NOCRT_ALIASES
     1721PROPS_ALL                    += VBOX_NOCRT_ALIASES
     1722
    17161723define def_unit_VBoxNoCrtAliases_double_expansion
    17171724$$($(target)_2_VBOX_NOCRT_ALIAS_KMK_FILE): \
     
    17371744        $$(QUIET)$$(MKDIR) -p -- "$$($(target)_0_OUTDIR)/genalias/"
    17381745        $$(QUIET)$$(VBOX_GENALIAS) -f $$(if-expr "$(bld_trg)" == "win",coff,$$(if-expr "$(bld_trg)" == "darwin",macho,omf)) \
    1739                 -D "$$($(target)_0_OUTDIR)/genalias/" $$($(target)_2_VBOX_NOCRT_ALIASES)
     1746                -D "$$($(target)_0_OUTDIR)/genalias/" $$($(target)_2_VBOX_NOCRT_ALIASES) \
     1747                $$($(target)_VBOX_NOCRT_ALIASES) \
     1748                $$($(target)_VBOX_NOCRT_ALIASES.$(bld_trg)) \
     1749                $$($(target)_VBOX_NOCRT_ALIASES.$(bld_trg).$(bld_type)) \
     1750                $$($(target)_VBOX_NOCRT_ALIASES.$(bld_trg).$(bld_trg_arch)) \
     1751                $$($(target)_VBOX_NOCRT_ALIASES.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
     1752                $$($(target)_VBOX_NOCRT_ALIASES.$(bld_trg_arch)) \
     1753                $$($(target)_VBOX_NOCRT_ALIASES.$(bld_trg_cpu)) \
     1754                $$($(target)_VBOX_NOCRT_ALIASES.$(bld_type))
    17401755        $$(QUIET)$$(APPEND) -tn "$$($(target)_0_OUTDIR)/genalias/genalias.ts" "$$($(target)_2_VBOX_NOCRT_ALIASES))"
    17411756
     
    17481763  $(target)_2_VBOX_NOCRT_ALIAS_KMK_FILE := $(PATH_OUT)/nocrt-aliases-$(target).kmk
    17491764  include $($(target)_2_VBOX_NOCRT_ALIAS_KMK_FILE)
    1750   $(target)_2_VBOX_NOCRT_ALIAS_FILES := \
    1751         $(foreach alias,$($(target)_2_VBOX_NOCRT_ALIASES), $($(target)_0_OUTDIR)/genalias/$(firstword $(subst =, $(SPACE),$(alias))).o)
     1765  $(target)_2_VBOX_NOCRT_ALIAS_FILES := $(foreach alias,$($(target)_2_VBOX_NOCRT_ALIASES) \
     1766        $($(target)_VBOX_NOCRT_ALIASES) \
     1767        $($(target)_VBOX_NOCRT_ALIASES.$(bld_trg)) \
     1768        $($(target)_VBOX_NOCRT_ALIASES.$(bld_trg).$(bld_type)) \
     1769        $($(target)_VBOX_NOCRT_ALIASES.$(bld_trg).$(bld_trg_arch)) \
     1770        $($(target)_VBOX_NOCRT_ALIASES.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
     1771        $($(target)_VBOX_NOCRT_ALIASES.$(bld_trg_arch)) \
     1772        $($(target)_VBOX_NOCRT_ALIASES.$(bld_trg_cpu)) \
     1773        $($(target)_VBOX_NOCRT_ALIASES.$(bld_type)) \
     1774        , $($(target)_0_OUTDIR)/genalias/$(firstword $(subst =, $(SPACE),$(alias))).o)
    17521775  $(eval $(def_unit_VBoxNoCrtAliases_double_expansion))
    17531776 endif
     
    17751798        generic/RTLogWriteStdErr-generic.cpp \
    17761799        generic/RTLogWriteStdOut-generic.cpp \
    1777         ,$(RuntimeBaseR3_SOURCES))
     1800        ,$(RuntimeBaseR3_SOURCES)) \
     1801       \
     1802        common/string/nocrt-strdup.cpp \
     1803        common/string/nocrt-stricmp.cpp \
     1804        common/string/strtok_r.cpp
    17781805  RuntimeR3_SOURCES.x86 = $(RuntimeBaseR3_SOURCES.x86) \
    17791806        common/misc/setjmp.asm \
     
    17841811        common/string/memset.asm \
    17851812        common/string/strlen.asm \
     1813        common/string/strnlen.cpp \
    17861814        common/string/strchr.asm \
    17871815        common/string/strcmp.asm \
    17881816        common/string/strncmp.asm \
    17891817        common/string/strcpy.asm \
     1818        common/string/strncpy.asm \
     1819        common/string/strcat.cpp \
     1820        common/string/strncat.cpp \
    17901821        common/string/strrchr.cpp \
    17911822        common/string/strstr.cpp \
     
    18001831        common/string/memset.asm \
    18011832        common/string/strlen.asm \
     1833        common/string/strnlen.cpp \
    18021834        common/string/strchr.asm \
    18031835        common/string/strcmp.asm \
    18041836        common/string/strncmp.asm \
    18051837        common/string/strcpy.asm \
     1838        common/string/strncpy.asm \
     1839        common/string/strcat.cpp \
     1840        common/string/strncat.cpp \
    18061841        common/string/strrchr.cpp \
    18071842        common/string/strstr.cpp \
     
    18381873        common/compiler/vcc/guard-vcc.asm \
    18391874        common/compiler/vcc/stack-vcc.asm
     1875  RuntimeR3_VBOX_NOCRT_ALIASES.win = strtok_s=nocrt_strtok_r _strtok_s=nocrt_strtok_r nocrt_strtok_s=nocrt_strtok_r
    18401876 endif
    18411877endif
  • 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