Ignore:
Timestamp:
Jul 1, 2005, 4:42:35 AM (20 years ago)
Author:
bird
Message:

o Added the strdupa() and strndupa() GLIBC extensions. These are macros

use alloca() to allocate the memory for the string.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/string.h

    • Property cvs2svn:cvs-rev changed from 1.15 to 1.16
    r2129 r2130  
    184184void    *__rawmemchr(const void *, int);
    185185
     186#define strdupa(psz) \
     187    (__extension__({ \
     188        __const__ char *__pszInput = (psz); \
     189        size_t          __cchInput = strlen(__pszInput) + 1; \
     190        char           *__pszReturn = __builtin_alloca(__cchInput); \
     191        (char *)memcpy(__pszReturn, __pszInput, __cchInput); \
     192    }))
     193
     194#define strndupa(psz, cch) \
     195    (__extension__({ \
     196        __const__ char *__pszInput = (psz); \
     197        size_t          __cchInput = strnlen(__pszInput, (cch)); \
     198        char           *__pszReturn = __builtin_alloca(__cchInput + 1); \
     199        __pszReturn[__cchInput] = '\0'; \
     200        (char *)memcpy(__pszReturn, __pszInput, __cchInput); \
     201    }))
     202
    186203#endif
    187204/* bird: GNU stuff - end */
Note: See TracChangeset for help on using the changeset viewer.