2002-03-08 23:20:52 +00:00
|
|
|
//===-- memory.c - String functions for the LLVM libc Library ----*- C -*-===//
|
|
|
|
//
|
|
|
|
// A lot of this code is ripped gratuitously from glibc and libiberty.
|
|
|
|
//
|
2003-12-16 22:57:30 +00:00
|
|
|
//===---------------------------------------------------------------------===//
|
2002-03-08 23:20:52 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2003-12-16 22:57:30 +00:00
|
|
|
// If we're not being compiled with GCC, turn off attributes. Question is how
|
|
|
|
// to handle overriding of memory allocation functions in that case.
|
|
|
|
#ifndef __GNUC__
|
|
|
|
#define __attribute__(X)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// For now, turn off the weak linkage attribute on Mac OS X.
|
|
|
|
#if defined(__GNUC__) && defined(__APPLE_CC__)
|
|
|
|
#define __ATTRIBUTE_WEAK__
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
#define __ATTRIBUTE_WEAK__ __attribute__((weak))
|
|
|
|
#else
|
|
|
|
#define __ATTRIBUTE_WEAK__
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void *malloc(size_t) __ATTRIBUTE_WEAK__;
|
|
|
|
void free(void *) __ATTRIBUTE_WEAK__;
|
|
|
|
void *memset(void *, int, size_t) __ATTRIBUTE_WEAK__;
|
|
|
|
void *calloc(size_t nelem, size_t elsize) __ATTRIBUTE_WEAK__;
|
2002-03-08 23:20:52 +00:00
|
|
|
|
|
|
|
void *calloc(size_t nelem, size_t elsize) {
|
|
|
|
void *Result = malloc(nelem*elsize);
|
2004-10-06 23:08:03 +00:00
|
|
|
if (Result) memset(Result, 0, nelem*elsize);
|
|
|
|
return Result;
|
2002-03-08 23:20:52 +00:00
|
|
|
}
|