1
/*===========================================================================
2
Copyright (C) 1995-2009 European Southern Observatory (ESO)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with this program; if not, write to the Free
16
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
19
Correspondence concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
28
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
.IDENTIFICATION osmemory
31
.AUTHOR Marc Wenger [CDS], Francois Ochsenbein [ESO-IPG]
33
.KEYWORDS Memory Management
36
Simple interface to malloc / realloc / free,
37
(osmalloc requires the full osm module and has badly designed
38
parameters, realloc is missing...)
39
.VERSION [1.1] 04-Oct-1987 Adapted by Francois Ochsenbein 28-Oct-1986
40
.VERSION [3.1] 21-Apr-1993 Posix compliant CG.
43
----------------------------------------------------------------------------*/
46
* Define _POSIX_SOURCE to indicate
47
* that this is a POSIX program
49
#define _POSIX_SOURCE 1
52
#include <proto_os.h> /* ANSI-C prototyping */
59
#ifdef OSERROR_D /* oserror already defined (Silicon G)*/
60
#define oserror midaserror
66
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
67
.PURPOSE Allocate a zone
68
.RETURNS Address of usable zone, or NULL (failed); oserror contains
71
-------------------------------------------------------------*/
72
size_t nmemb; /* IN: Required length (bytes) */
78
p = (char *) calloc(nmemb,(size_t)1);
79
if (!p) oserror = ENOMEM;
84
void osmmfree(address)
86
.PURPOSE Free a zone allocated via osmmget
87
.RETURNS 0 / -1 if error.
88
.REMARKS A null address to free returns 0 (no error).
89
Unix implementation always returns 0.
91
void *address ; /* IN: adress to free */
96
char *osmmexp(address, nbytes)
97
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
98
.PURPOSE Reallocates a piece of memory allocated via osmmget
99
.RETURNS Address of new zone, or NULL if failed.
100
.REMARKS Values are copied to new zone.
101
------------------------------------------------------------*/
102
char *address ; /* MOD: adress to realloc */
103
size_t nbytes; /* IN: New length */
110
p = (char *) realloc((void *)address, nbytes);
112
p = (char *) malloc(nbytes);
114
if (!p) oserror = ENOMEM;