diff options
Diffstat (limited to 'libs/libcurl/src/strdup.c')
| -rw-r--r-- | libs/libcurl/src/strdup.c | 28 | 
1 files changed, 26 insertions, 2 deletions
diff --git a/libs/libcurl/src/strdup.c b/libs/libcurl/src/strdup.c index 1008d94fe5..ee341ef27e 100644 --- a/libs/libcurl/src/strdup.c +++ b/libs/libcurl/src/strdup.c @@ -26,7 +26,7 @@  #include <curl/curl.h>
 -#ifdef WIN32
 +#ifdef _WIN32
  #include <wchar.h>
  #endif
 @@ -56,7 +56,7 @@ char *Curl_strdup(const char *str)  }
  #endif
 -#ifdef WIN32
 +#ifdef _WIN32
  /***************************************************************************
   *
   * Curl_wcsdup(source)
 @@ -101,6 +101,30 @@ void *Curl_memdup(const void *src, size_t length)  /***************************************************************************
   *
 + * Curl_strndup(source, length)
 + *
 + * Copies the 'source' string to a newly allocated buffer (that is returned).
 + * Copies not more than 'length' bytes (up to a null terminator) then adds a
 + * null terminator.
 + *
 + * Returns the new pointer or NULL on failure.
 + *
 + ***************************************************************************/
 +void *Curl_strndup(const char *src, size_t length)
 +{
 +  char *buf = memchr(src, '\0', length);
 +  if(buf)
 +    length = buf - src;
 +  buf = malloc(length + 1);
 +  if(!buf)
 +    return NULL;
 +  memcpy(buf, src, length);
 +  buf[length] = 0;
 +  return buf;
 +}
 +
 +/***************************************************************************
 + *
   * Curl_saferealloc(ptr, size)
   *
   * Does a normal realloc(), but will free the data pointer if the realloc
  | 
