File: omAllocEmulate.c

package info (click to toggle)
singular 1%3A4.0.3-p3%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 33,040 kB
  • ctags: 19,347
  • sloc: cpp: 271,589; ansic: 13,500; lisp: 4,242; yacc: 1,656; lex: 1,377; makefile: 1,264; perl: 632; sh: 467; python: 233; xml: 182
file content (43 lines) | stat: -rw-r--r-- 1,043 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*******************************************************************
 *  File:    omAllocEmulate.c
 *  Purpose: implementation of emulated omalloc routines
 *  Author:  obachman (Olaf Bachmann)
 *  Created: 11/99
 *******************************************************************/
#include <stdlib.h>
#include <string.h>

#include "omMalloc.h"

#ifdef OM_EMULATE_OMALLOC

void* omEmulateAlloc0(size_t size)
{
  void* addr = OM_MALLOC_MALLOC(size);
  memset(addr, 0, size);
  return addr;
}

void* omEmulateRealloc0Size(void* o_addr, size_t o_size, size_t n_size)
{
  void* addr = OM_MALLOC_REALLOC(o_addr, n_size);

  if (n_size > o_size)
    memset((char *)addr + o_size, 0, n_size - o_size);

  return addr;
}

void* omEmulateRealloc0(void* o_addr, size_t n_size)
{
#ifdef OM_MALLOC_SIZEOF_ADDR
  size_t o_size = OM_MALLOC_SIZEOF_ADDR(o_addr);
#endif
  void* addr = OM_MALLOC_REALLOC(o_addr, n_size);
#ifdef OM_MALLOC_SIZEOF_ADDR
  if (n_size > o_size)
    memset((char *)addr + o_size, 0, n_size - o_size);
#endif
  return addr;
}
#endif