GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
raster3d/alloc.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <unistd.h>
5 #include "raster3d_intern.h"
6 
7 /*---------------------------------------------------------------------------*/
8 
9 
10 /*!
11  * \brief
12  *
13  * Same as <em>malloc (nBytes)</em>, except that in case of error
14  * <tt>Rast3d_error()</tt> is invoked.
15  *
16  * \param nBytes
17  * \return void *: a pointer ... if successful,
18  * NULL ... otherwise.
19 
20  */
21 
22 void *Rast3d_malloc(int nBytes)
23 {
24  void *buf;
25 
26  if (nBytes <= 0)
27  nBytes = 1;
28  if ((buf = malloc(nBytes)) != NULL)
29  return buf;
30 
31  Rast3d_error("Rast3d_malloc: out of memory");
32  return (void *)NULL;
33 }
34 
35 
36 /*!
37  * \brief
38  *
39  * Same as <em>realloc (ptr, nBytes)</em>, except that in case of error
40  * <tt>Rast3d_error()</tt> is invoked.
41  *
42  * \param ptr
43  * \param nBytes
44  * \return void *: a pointer ... if successful,
45  * NULL ... otherwise.
46  */
47 
48 void *Rast3d_realloc(void *ptr, int nBytes)
49 {
50  if (nBytes <= 0)
51  nBytes = 1;
52  if ((ptr = realloc(ptr, nBytes)) != NULL)
53  return ptr;
54 
55  Rast3d_error("Rast3d_realloc: out of memory");
56  return (void *)NULL;
57 }
58 
59 
60 /*!
61  * \brief
62  *
63  * Same as <em>free (ptr)</em>.
64  *
65  * \param buf
66  * \return void
67  */
68 
69 void Rast3d_free(void *buf)
70 {
71  free(buf);
72 }
void * Rast3d_realloc(void *ptr, int nBytes)
Same as realloc (ptr, nBytes), except that in case of error Rast3d_error() is invoked.
void free(void *)
#define NULL
Definition: ccmath.h:32
void Rast3d_error(const char *,...) __attribute__((format(printf
void * malloc(YYSIZE_T)
void Rast3d_free(void *buf)
Same as free (ptr).
void * Rast3d_malloc(int nBytes)
Same as malloc (nBytes), except that in case of error Rast3d_error() is invoked.