source: git/omalloc/omalloc.c @ f8a4cb

fieker-DuValspielwiese
Last change on this file since f8a4cb was d83977, checked in by Olaf Bachmann <obachman@…>, 23 years ago
Windows port git-svn-id: file:///usr/local/Singular/svn/trunk@5127 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*******************************************************************
2 *  File:    omalloc.c
3 *  Purpose: implementation of ANSI-C conforming malloc functions
4 *           -- the real version
5 *  Author:  obachman@mathematik.uni-kl.de (Olaf Bachmann)
6 *  Created: 11/99
7 *  Version: $Id: omalloc.c,v 1.6 2001-01-27 17:03:41 obachman Exp $
8 *******************************************************************/
9
10#include <stdlib.h>
11#include <stdio.h>
12
13#ifndef OMALLOC_C
14#define OMALLOC_C
15
16#include <omalloc.h>
17
18#ifdef OM_MALLOC_MARK_AS_STATIC
19#define OM_MARK_AS_STATIC(addr) omMarkAsStaticAddr(addr)
20#else
21#define OM_MARK_AS_STATIC(addr) ((void)0)
22#endif
23
24void* calloc(size_t nmemb, size_t size)
25{
26  void* addr;
27  if (size == 0) size = 1;
28  if (nmemb == 0) nmemb = 1;
29 
30  size = size*nmemb;
31  omTypeAlloc0Aligned(void*, addr, size);
32  OM_MARK_AS_STATIC(addr);
33  return addr;
34}
35 
36void* malloc(size_t size)
37{
38  void* addr;
39  if (size == 0) size = 1;
40 
41  omTypeAllocAligned(void*, addr, size);
42  OM_MARK_AS_STATIC(addr);
43  return addr;
44}
45
46void free(void* addr)
47{
48  omfree(addr);
49}
50
51void* valloc(size_t size)
52{
53  fprintf(stderr, "omalloc Warning: valloc not yet implemented\n");
54  fflush(NULL);
55  return NULL;
56}
57
58#if defined(sgi)
59void* memalign(size_t size_1, size_t size_2)
60#else
61void* memalign(void* alignment, size_t size)
62#endif
63{
64  fprintf(stderr, "omalloc Warning: memalign not yet implemented\n");
65  fflush(NULL);
66  return NULL;
67}
68
69void* realloc(void* old_addr, size_t new_size)
70{
71  if (old_addr && new_size)
72  {
73    void* new_addr;
74    omTypeReallocAligned(old_addr, void*, new_addr, new_size);
75    OM_MARK_AS_STATIC(new_addr);
76    return new_addr;
77  }
78  else 
79  {
80    free(old_addr);
81    return malloc(new_size);
82  }
83}
84
85/* on some systems strdup is a macro -- replace it unless OMALLOC_FUNC
86   is defined */
87#if !defined(OMALOC_FUNC)
88#undef strdup
89#endif
90char* strdup(const char* addr)
91{
92  char* n_s;
93  if (addr)
94  {
95    n_s = omStrDup(addr);
96    OM_MARK_AS_STATIC(n_s);
97    return n_s;
98  }
99  return NULL;
100}
101void freeSize(void* addr, size_t size)
102{
103  if (addr) omFreeSize(addr, size);
104}
105
106void* reallocSize(void* old_addr, size_t old_size, size_t new_size)
107{
108  if (old_addr && new_size)
109  {
110   void* new_addr;
111    omTypeReallocAlignedSize(old_addr, old_size, void*, new_addr, new_size);
112    OM_MARK_AS_STATIC(new_addr);
113    return new_addr;
114  }
115  else 
116  {
117    freeSize(old_addr, old_size);
118    return malloc(new_size);
119  }
120}
121
122#endif
Note: See TracBrowser for help on using the repository browser.