Chris Lattner | c1e20ac | 2002-03-08 23:20:52 +0000 | [diff] [blame] | 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 | // |
Misha Brukman | b49fa61 | 2003-12-16 22:57:30 +0000 | [diff] [blame] | 5 | //===---------------------------------------------------------------------===// |
Chris Lattner | c1e20ac | 2002-03-08 23:20:52 +0000 | [diff] [blame] | 6 | |
| 7 | #include <stdlib.h> |
| 8 | |
Misha Brukman | b49fa61 | 2003-12-16 22:57:30 +0000 | [diff] [blame] | 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__; |
Chris Lattner | c1e20ac | 2002-03-08 23:20:52 +0000 | [diff] [blame] | 28 | |
| 29 | void *calloc(size_t nelem, size_t elsize) { |
| 30 | void *Result = malloc(nelem*elsize); |
| 31 | return memset(Result, 0, nelem*elsize); |
| 32 | } |