ReactOS 0.4.15-dev-8131-g4988de4
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
4static 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
34EXPORT int ___mexval __PR((int exval));
35EXPORT void *___malloc __PR((size_t size, char *msg));
36EXPORT void *___realloc __PR((void *ptr, size_t size, char *msg));
37EXPORT char *___savestr __PR((const char *s));
38
40
41EXPORT int
43 int exval;
44{
45 int ret = mexval;
46
47 mexval = exval;
48
49 return (ret);
50}
51
52EXPORT 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
72EXPORT 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
96EXPORT char *
98 const char *s;
99{
100 char *ret = ___malloc(strlen(s)+1, "saved string");
101
102 strcpy(ret, s);
103 return (ret);
104}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define msg(x)
Definition: auth_time.c:54
#define UConst
Definition: ccomdefs.h:72
EXPORT void comexit(int err)
Definition: comerr.c:331
EXPORT int errmsg(char *msg, va_alist)
Definition: comerr.c:192
#define realloc
Definition: debug_ros.c:6
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
EXPORT int geterrno()
Definition: geterrno.c:34
GLdouble s
Definition: gl.h:2039
GLsizeiptr size
Definition: glext.h:5919
#define LOCAL(type)
Definition: jmorecfg.h:289
static PVOID ptr
Definition: dispmode.c:27
#define gettext(s)
Definition: nlsdefs.h:71
#define __PR(a)
Definition: prototyp.h:106
#define err(...)
#define ___realloc
Definition: schily.h:631
#define ___mexval
Definition: schily.h:629
#define ___malloc
Definition: schily.h:630
#define ___savestr
Definition: schily.h:632
static UConst char sccsid[]
Definition: mem.c:4
LOCAL int mexval
Definition: mem.c:39
int ret