GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
new.c
Go to the documentation of this file.
1/*
2 ** Written by David Gerdes US Army Construction Engineering Research Lab
3 ** April 1992
4 ** SPDX-FileCopyrightText: 1992 USA-CERL
5 ** SPDX-FileCopyrightText: GRASS Development Team
6 ** SPDX-License-Identifier: GPL-2.0-or-later
7 **
8 */
9
10#include <string.h>
11#include <stdlib.h>
12#include <grass/linkm.h>
13
15{
16 VOID_T *tmp;
17 char *ctmp, *p;
18 register int i;
19
20 if (Head->Unused == NULL) {
21 if (Head->max_ptr >= Head->alloced) {
22 /*DEBUG fprintf (stderr, "REALLOCING PTR_ARRAY (%d -> %d)\n",
23 * Head->alloced, Head->alloced * 2); */
24 if (NULL ==
25 (tmp = (VOID_T *)realloc(
26 Head->ptr_array, sizeof(VOID_T *) * Head->alloced * 2))) {
27 if (Head->exit_flag)
29 return NULL;
30 }
31 Head->ptr_array = (VOID_T **)tmp;
32 Head->alloced *= 2;
33 }
34
35 /*DEBUG fprintf (stderr, "Mallocing another chunk: %d\n",
36 * Head->max_ptr); */
37 if (NULL == (tmp = (VOID_T *)malloc((size_t)Head->chunk_size *
38 Head->unit_size))) {
39 if (Head->exit_flag)
41 return NULL;
42 }
43
44 Head->ptr_array[Head->max_ptr++] = (VOID_T *)tmp;
45 Head->Unused = (VOID_T *)tmp;
46
47 p = ctmp = (char *)tmp;
48 for (i = 0; i < Head->chunk_size - 1; i++) {
50 (VOID_T *)&(ctmp[(i + 1) * Head->unit_size]));
51 /* p->next = p+1 */
52
53 p = &(ctmp[(i + 1) * Head->unit_size]); /* p = p->next */
54 }
55 link__set_next((VOID_T *)p, NULL); /* p->next = NULL */
56 }
57
58 tmp = Head->Unused;
59
60 /* Unused = Unused->next */
61 Head->Unused = link__get_next(Head->Unused);
62
63 return tmp;
64}
#define NULL
Definition ccmath.h:32
int link_out_of_memory(void)
Definition oom.c:4
VOID_T * link__get_next(VOID_T *)
void link__set_next(VOID_T *, VOID_T *)
#define VOID_T
Definition linkm.h:8
char * link_new(struct link_head *Head)
Definition new.c:14
void * malloc(unsigned)