/* @(#)osmemory.c 17.1.1.1 (ES0-DMD) 01/25/02 17:35:08 */ /*=========================================================================== Copyright (C) 1995 European Southern Observatory (ESO) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Massachusetss Ave, Cambridge, MA 02139, USA. Corresponding concerning ESO-MIDAS should be addressed as follows: Internet e-mail: midas@eso.org Postal address: European Southern Observatory Data Management Division Karl-Schwarzschild-Strasse 2 D 85748 Garching bei Muenchen GERMANY ===========================================================================*/ /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .TYPE Module .IDENTIFICATION osmemory .AUTHOR Marc Wenger [CDS], Francois Ochsenbein [ESO-IPG] .LANGUAGE C .KEYWORDS Memory Management .ENVIRONMENT UNIX .COMMENTS Simple interface to malloc / realloc / free, (osmalloc requires the full osm module and has badly designed parameters, realloc is missing...) .VERSION [1.1] 04-Oct-1987 Adapted by Francois Ochsenbein 28-Oct-1986 .VERSION [3.1] 21-Apr-1993 Posix compliant CG. ----------------------------------------------------------------------------*/ /* * Define _POSIX_SOURCE to indicate * that this is a POSIX program */ #define _POSIX_SOURCE 1 #include /* ANSI-C prototyping */ #include #include #include #ifdef FASTMEM_SET #include #endif #ifdef OSERROR_D /* oserror already defined (Silicon G)*/ #define oserror midaserror #endif extern int oserror; char *osmmget(nbytes) /*+++ .PURPOSE Allocate a zone .RETURNS Address of usable zone, or NULL (failed); oserror contains then the error code. .REMARKS ---*/ long nbytes ; /* IN: Required length (bytes) */ { register char *p; p = calloc(nbytes,1); if (!p) oserror = ENOMEM; return(p); } void osmmfree(address) /*+++ .PURPOSE Free a zone allocated via osmmget .RETURNS 0 / -1 if error. .REMARKS A null address to free returns 0 (no error). Unix implementation always returns 0. ---*/ void *address ; /* IN: adress to free */ { free(address); } char *osmmexp(address, nbytes) /*+++ .PURPOSE Reallocates a piece of memory allocated via osmmget .RETURNS Address of new zone, or NULL if failed. .REMARKS Values are copied to new zone. ---*/ char *address ; /* MOD: adress to realloc */ long nbytes; /* IN: New length */ { register char *p; if (address) p = realloc(address, nbytes); else p = malloc(nbytes); if (!p) oserror = ENOMEM; return(p); }