memory/build/extraMallocFuncs.c
author Mike Hommey <mh+mozilla@glandium.org>
Sat, 31 Mar 2012 09:23:19 +0200
changeset 90774 c2a9fb6260384b17046911ddc5cafef4a23b2256
child 93145 b162f27251fbd43e91c137bbce3529b09c4821f4
permissions -rw-r--r--
Bug 736963 - Move jemalloc'ed strdup/strndup definitions. r=jlebar,r=ted

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#include <string.h>
#include "mozilla/Types.h"

#ifdef ANDROID
#define wrap(a) __wrap_ ## a
#endif

#if defined(XP_WIN) || defined(XP_MACOSX)
#define wrap(a) je_ ## a
#endif

#ifdef wrap
void *wrap(malloc)(size_t);

MOZ_EXPORT_API(char *)
wrap(strndup)(const char *src, size_t len)
{
  char* dst = (char*) wrap(malloc)(len + 1);
  if (dst)
    strncpy(dst, src, len + 1);
  return dst; 
}

MOZ_EXPORT_API(char *)
wrap(strdup)(const char *src)
{
  size_t len = strlen(src);
  return wrap(strndup)(src, len);
}
#endif