ReactOS  0.4.14-dev-342-gdc047f9
mem.c
Go to the documentation of this file.
1 /* @(#)mem.c 1.11 15/05/10 Copyright 1998-2015 J. Schilling */
2 #include <schily/mconfig.h>
3 #ifndef lint
4 static UConst char sccsid[] =
5  "@(#)mem.c 1.11 15/05/10 Copyright 1998-2015 J. Schilling";
6 #endif
7 /*
8  * Memory handling with error checking
9  *
10  * Copyright (c) 1998-2015 J. Schilling
11  */
12 /*
13  * The contents of this file are subject to the terms of the
14  * Common Development and Distribution License, Version 1.0 only
15  * (the "License"). You may not use this file except in compliance
16  * with the License.
17  *
18  * See the file CDDL.Schily.txt in this distribution for details.
19  * A copy of the CDDL is also available via the Internet at
20  * http://www.opensource.org/licenses/cddl1.txt
21  *
22  * When distributing Covered Code, include this CDDL HEADER in each
23  * file and include the License file CDDL.Schily.txt from this distribution.
24  */
25 
26 #include <schily/stdio.h>
27 #include <schily/stdlib.h>
28 #include <schily/unistd.h>
29 #include <schily/string.h>
30 #include <schily/standard.h>
31 #include <schily/schily.h>
32 #include <schily/nlsdefs.h>
33 
34 EXPORT int ___mexval __PR((int exval));
35 EXPORT void *___malloc __PR((size_t size, char *msg));
36 EXPORT void *___realloc __PR((void *ptr, size_t size, char *msg));
37 EXPORT char *___savestr __PR((const char *s));
38 
40 
41 EXPORT int
42 ___mexval(exval)
43  int exval;
44 {
45  int ret = mexval;
46 
47  mexval = exval;
48 
49  return (ret);
50 }
51 
52 EXPORT void *
54  size_t size;
55  char *msg;
56 {
57  void *ret;
58 
59  ret = malloc(size);
60  if (ret == NULL) {
61  int err = geterrno();
62 
63  errmsg(gettext("Cannot allocate memory for %s.\n"), msg);
64  if (mexval)
65  err = mexval;
66  comexit(err);
67  /* NOTREACHED */
68  }
69  return (ret);
70 }
71 
72 EXPORT void *
74  void *ptr;
75  size_t size;
76  char *msg;
77 {
78  void *ret;
79 
80  if (ptr == NULL)
81  ret = malloc(size);
82  else
83  ret = realloc(ptr, size);
84  if (ret == NULL) {
85  int err = geterrno();
86 
87  errmsg(gettext("Cannot realloc memory for %s.\n"), msg);
88  if (mexval)
89  err = mexval;
90  comexit(err);
91  /* NOTREACHED */
92  }
93  return (ret);
94 }
95 
96 EXPORT char *
98  const char *s;
99 {
100  char *ret = ___malloc(strlen(s)+1, "saved string");
101 
102  strcpy(ret, s);
103  return (ret);
104 }
#define realloc
Definition: debug_ros.c:6
EXPORT void * ___malloc(size_t size, char *msg)
Definition: mem.c:53
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define UConst
Definition: ccomdefs.h:72
EXPORT char * ___savestr(char *s) const
Definition: mem.c:97
static PVOID ptr
Definition: dispmode.c:27
static UConst char sccsid[]
Definition: mem.c:4
smooth NULL
Definition: ftsmooth.c:416
EXPORT int errmsg(char *msg, va_alist)
Definition: comerr.c:192
#define LOCAL(type)
Definition: jmorecfg.h:289
EXPORT int ___mexval __PR((int exval))
GLsizeiptr size
Definition: glext.h:5919
LOCAL int mexval
Definition: mem.c:39
EXPORT int geterrno()
Definition: geterrno.c:34
int ret
EXPORT int ___mexval(int exval)
Definition: mem.c:42
GLdouble s
Definition: gl.h:2039
#define err(...)
EXPORT void comexit(int err)
Definition: comerr.c:331
#define msg(x)
Definition: auth_time.c:54
#define gettext(s)
Definition: nlsdefs.h:71
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define malloc
Definition: debug_ros.c:4
EXPORT void * ___realloc(void *ptr, size_t size, char *msg)
Definition: mem.c:73