Ignore:
Timestamp:
Nov 1, 2001, 6:43:18 PM (24 years ago)
Author:
umoeller
Message:

More updates.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/stringh.c

    r108 r116  
    9595
    9696PSZ strhdupDebug(const char *pszSource,
     97                 unsigned long *pulLength,
    9798                 const char *pcszSourceFile,
    9899                 unsigned long ulLine,
    99100                 const char *pcszFunction)
    100101{
    101     if (pszSource)
    102     {
    103         PSZ p = (PSZ)memdMalloc(strlen(pszSource) + 1,
    104                                 pcszSourceFile,
    105                                 ulLine,
    106                                 pcszFunction);
    107         strcpy(p,  pszSource);
    108         return (p);
    109     }
    110     else
    111         return (0);
     102    PSZ     pszReturn = NULL;
     103    ULONG   ulLength = 0;
     104
     105    if (    (pcszSource)
     106         && (ulLength = strlen(pcszSource))
     107       )
     108    {
     109        if (pszReturn = (PSZ)memdMalloc(ulLength + 1,
     110                                        pcszSourceFile,
     111                                        ulLine,
     112                                        pcszFunction))
     113            memcpy(pszReturn, pcszSource, ulLength + 1);
     114    }
     115
     116    if (pulLength)
     117        *pulLength = ulLength;
     118
     119    return (pszReturn);
    112120}
    113121
     
    116124/*
    117125 *@@ strhdup:
    118  *      like strdup, but this one doesn't crash if pszSource is NULL,
    119  *      but returns NULL also.
     126 *      like strdup, but this one doesn't crash if pszSource
     127 *      is NULL, but returns NULL also. In addition, this
     128 *      can report the length of the string (V0.9.16).
    120129 *
    121130 *@@added V0.9.0 [umoeller]
    122  */
    123 
    124 PSZ strhdup(const char *pszSource)
    125 {
    126     if (pszSource)
    127         return (strdup(pszSource));
    128     else
    129         return (0);
     131 *@@changed V0.9.16 (2001-10-25) [umoeller]: added pulLength
     132 */
     133
     134PSZ strhdup(const char *pcszSource,
     135            unsigned long *pulLength)       // out: length of string excl. null terminator (ptr can be NULL)
     136{
     137    PSZ     pszReturn = NULL;
     138    ULONG   ulLength = 0;
     139
     140    if (    (pcszSource)
     141         && (ulLength = strlen(pcszSource))
     142       )
     143    {
     144        if (pszReturn = (PSZ)malloc(ulLength + 1))
     145            memcpy(pszReturn, pcszSource, ulLength + 1);
     146    }
     147
     148    if (pulLength)
     149        *pulLength = ulLength;
     150
     151    return (pszReturn);
    130152}
    131153
Note: See TracChangeset for help on using the changeset viewer.