GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-bea8435a9e
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  * \brief
11  *
12  * Same as <em>malloc (nBytes)</em>, except that in case of error
13  * <tt>Rast3d_error()</tt> is invoked.
14  *
15  * \param nBytes
16  * \return void *: a pointer ... if successful,
17  * NULL ... otherwise.
18 
19  */
20 
21 void *Rast3d_malloc(int nBytes)
22 {
23  void *buf;
24 
25  if (nBytes <= 0)
26  nBytes = 1;
27  if ((buf = malloc(nBytes)) != NULL)
28  return buf;
29 
30  Rast3d_error("Rast3d_malloc: out of memory");
31  return (void *)NULL;
32 }
33 
34 /*!
35  * \brief
36  *
37  * Same as <em>realloc (ptr, nBytes)</em>, except that in case of error
38  * <tt>Rast3d_error()</tt> is invoked.
39  *
40  * \param ptr
41  * \param nBytes
42  * \return void *: a pointer ... if successful,
43  * NULL ... otherwise.
44  */
45 
46 void *Rast3d_realloc(void *ptr, int nBytes)
47 {
48  if (nBytes <= 0)
49  nBytes = 1;
50  if ((ptr = realloc(ptr, nBytes)) != NULL)
51  return ptr;
52 
53  Rast3d_error("Rast3d_realloc: out of memory");
54  return (void *)NULL;
55 }
56 
57 /*!
58  * \brief
59  *
60  * Same as <em>free (ptr)</em>.
61  *
62  * \param buf
63  * \return void
64  */
65 
66 void Rast3d_free(void *buf)
67 {
68  free(buf);
69 }
#define NULL
Definition: ccmath.h:32
void Rast3d_error(const char *,...) __attribute__((format(printf
void * Rast3d_malloc(int nBytes)
Same as malloc (nBytes), except that in case of error Rast3d_error() is invoked.
void * Rast3d_realloc(void *ptr, int nBytes)
Same as realloc (ptr, nBytes), except that in case of error Rast3d_error() is invoked.
void Rast3d_free(void *buf)
Same as free (ptr).
void * malloc(YYSIZE_T)
void free(void *)