1 //===-- memory.c - String functions for the LLVM libc Library ----*- C -*-===//
3 // A lot of this code is ripped gratuitously from glibc and libiberty.
5 //===---------------------------------------------------------------------===//
9 // If we're not being compiled with GCC, turn off attributes. Question is how
10 // to handle overriding of memory allocation functions in that case.
12 #define __attribute__(X)
15 // For now, turn off the weak linkage attribute on Mac OS X.
16 #if defined(__GNUC__) && defined(__APPLE_CC__)
17 #define __ATTRIBUTE_WEAK__
18 #elif defined(__GNUC__)
19 #define __ATTRIBUTE_WEAK__ __attribute__((weak))
21 #define __ATTRIBUTE_WEAK__
24 void *malloc(size_t) __ATTRIBUTE_WEAK__;
25 void free(void *) __ATTRIBUTE_WEAK__;
26 void *memset(void *, int, size_t) __ATTRIBUTE_WEAK__;
27 void *calloc(size_t nelem, size_t elsize) __ATTRIBUTE_WEAK__;
29 void *calloc(size_t nelem, size_t elsize) {
30 void *Result = malloc(nelem*elsize);
31 return memset(Result, 0, nelem*elsize);