GRASS 8 Programmer's Manual 8.6.0dev(2026)-1d1e47ad9d
Loading...
Searching...
No Matches
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 */
21{
22 void *buf;
23
24 if (nBytes <= 0)
25 nBytes = 1;
26 if ((buf = malloc(nBytes)) != NULL)
27 return buf;
28
29 Rast3d_error("Rast3d_malloc: out of memory");
30 return (void *)NULL;
31}
32
33/*!
34 * \brief
35 *
36 * Same as <em>realloc (ptr, nBytes)</em>, except that in case of error
37 * <tt>Rast3d_error()</tt> is invoked.
38 *
39 * \param ptr
40 * \param nBytes
41 * \return void *: a pointer ... if successful,
42 * NULL ... otherwise.
43 */
44void *Rast3d_realloc(void *ptr, int nBytes)
45{
46 if (nBytes <= 0)
47 nBytes = 1;
48 if ((ptr = realloc(ptr, nBytes)) != NULL)
49 return ptr;
50
51 Rast3d_error("Rast3d_realloc: out of memory");
52 return (void *)NULL;
53}
54
55/*!
56 * \brief
57 *
58 * Same as <em>free (ptr)</em>.
59 *
60 * \param buf
61 * \return void
62 */
63void Rast3d_free(void *buf)
64{
65 free(buf);
66}
#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(unsigned)
void free(void *)