blob: 64aef89094a4d5e03358f7f420808fc5d5740cae [file] [log] [blame]
Chris Lattnerc1e20ac2002-03-08 23:20:52 +00001//===-- 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 Brukmanb49fa612003-12-16 22:57:30 +00005//===---------------------------------------------------------------------===//
Chris Lattnerc1e20ac2002-03-08 23:20:52 +00006
7#include <stdlib.h>
8
Misha Brukmanb49fa612003-12-16 22:57:30 +00009// 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
24void *malloc(size_t) __ATTRIBUTE_WEAK__;
25void free(void *) __ATTRIBUTE_WEAK__;
26void *memset(void *, int, size_t) __ATTRIBUTE_WEAK__;
27void *calloc(size_t nelem, size_t elsize) __ATTRIBUTE_WEAK__;
Chris Lattnerc1e20ac2002-03-08 23:20:52 +000028
29void *calloc(size_t nelem, size_t elsize) {
30 void *Result = malloc(nelem*elsize);
31 return memset(Result, 0, nelem*elsize);
32}