Disable __attribute__((weak)) on Mac OS X and other lame platforms.
[oota-llvm.git] / runtime / GCCLibraries / libc / memory.c
1 //===-- memory.c - String functions for the LLVM libc Library ----*- C -*-===//
2 // 
3 // A lot of this code is ripped gratuitously from glibc and libiberty.
4 //
5 //===---------------------------------------------------------------------===//
6
7 #include <stdlib.h>
8
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.
11 #ifndef __GNUC__
12 #define __attribute__(X)
13 #endif
14     
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))
20 #else
21 #define __ATTRIBUTE_WEAK__
22 #endif
23
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__;
28
29 void *calloc(size_t nelem, size_t elsize) {
30   void *Result = malloc(nelem*elsize);
31   return memset(Result, 0, nelem*elsize);
32 }