~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to libsrc/os/unix/osmemory.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*===========================================================================
 
2
  Copyright (C) 1995-2009 European Southern Observatory (ESO)
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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, 
 
17
  MA 02139, USA.
 
18
 
 
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 
 
25
                        GERMANY
 
26
===========================================================================*/
 
27
 
 
28
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
29
.TYPE           Module
 
30
.IDENTIFICATION osmemory
 
31
.AUTHOR         Marc Wenger [CDS], Francois Ochsenbein [ESO-IPG]
 
32
.LANGUAGE       C
 
33
.KEYWORDS       Memory Management
 
34
.ENVIRONMENT    UNIX
 
35
.COMMENTS
 
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.
 
41
 
 
42
 090324         last modif
 
43
----------------------------------------------------------------------------*/
 
44
 
 
45
/*
 
46
 * Define _POSIX_SOURCE to indicate
 
47
 * that this is a POSIX program
 
48
 */
 
49
#define _POSIX_SOURCE 1
 
50
 
 
51
#include <fcntl.h>
 
52
#include <proto_os.h>           /* ANSI-C prototyping */
 
53
#include <stdio.h>
 
54
#include <stdlib.h>
 
55
#include <errno.h>
 
56
 
 
57
 
 
58
 
 
59
#ifdef OSERROR_D                        /* oserror already defined (Silicon G)*/
 
60
#define oserror midaserror
 
61
#endif
 
62
 
 
63
extern int oserror;
 
64
 
 
65
char    *osmmget(nmemb)
 
66
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
67
.PURPOSE Allocate a zone
 
68
.RETURNS Address of usable zone, or NULL (failed); oserror contains
 
69
        then the error code.
 
70
.REMARKS 
 
71
-------------------------------------------------------------*/
 
72
size_t  nmemb;          /* IN: Required length (bytes)  */
 
73
 
 
74
{
 
75
char *p;
 
76
        
 
77
 
 
78
p = (char *) calloc(nmemb,(size_t)1);
 
79
if (!p) oserror = ENOMEM;
 
80
 
 
81
return(p);
 
82
}
 
83
 
 
84
void osmmfree(address) 
 
85
/*+++
 
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.
 
90
---*/
 
91
void *address ;         /* IN: adress to free   */
 
92
{
 
93
  free(address);
 
94
}
 
95
 
 
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               */
 
104
 
 
105
{
 
106
register char *p;
 
107
 
 
108
 
 
109
if (address)
 
110
   p = (char *) realloc((void *)address, nbytes);
 
111
else
 
112
   p = (char *) malloc(nbytes);
 
113
 
 
114
if (!p) oserror = ENOMEM;
 
115
return(p);
 
116
}