GRASS 8 Programmer's Manual
8.5.0(2026)-8d6ceba290
Toggle main menu visibility
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
** Copyright 1992 USA-CERL All rights reserved.
5
**
6
*/
7
8
#include <string.h>
9
#include <stdlib.h>
10
#include <grass/linkm.h>
11
12
VOID_T
*
link_new
(
struct
link_head *Head)
13
{
14
VOID_T
*tmp;
15
char
*ctmp, *p;
16
register
int
i;
17
18
if
(Head->Unused ==
NULL
) {
19
if
(Head->max_ptr >= Head->alloced) {
20
/*DEBUG fprintf (stderr, "REALLOCING PTR_ARRAY (%d -> %d)\n",
21
* Head->alloced, Head->alloced * 2); */
22
if
(
NULL
==
23
(tmp = (
VOID_T
*)realloc(
24
Head->ptr_array,
sizeof
(
VOID_T
*) * Head->alloced * 2))) {
25
if
(Head->exit_flag)
26
link_out_of_memory
();
27
return
NULL
;
28
}
29
Head->ptr_array = (
VOID_T
**)tmp;
30
Head->alloced *= 2;
31
}
32
33
/*DEBUG fprintf (stderr, "Mallocing another chunk: %d\n",
34
* Head->max_ptr); */
35
if
(
NULL
==
36
(tmp = (
VOID_T
*)malloc(Head->chunk_size * Head->unit_size))) {
37
if
(Head->exit_flag)
38
link_out_of_memory
();
39
return
NULL
;
40
}
41
42
Head->ptr_array[Head->max_ptr++] = (
VOID_T
*)tmp;
43
Head->Unused = (
VOID_T
*)tmp;
44
45
p = ctmp = (
char
*)tmp;
46
for
(i = 0; i < Head->chunk_size - 1; i++) {
47
link__set_next
((
VOID_T
*)p,
48
(
VOID_T
*)&(ctmp[(i + 1) * Head->unit_size]));
49
/* p->next = p+1 */
50
51
p = &(ctmp[(i + 1) * Head->unit_size]);
/* p = p->next */
52
}
53
link__set_next
((
VOID_T
*)p,
NULL
);
/* p->next = NULL */
54
}
55
56
tmp = Head->Unused;
57
58
/* Unused = Unused->next */
59
Head->Unused =
link__get_next
(Head->Unused);
60
61
return
tmp;
62
}
NULL
#define NULL
Definition
ccmath.h:32
link__get_next
VOID_T * link__get_next(VOID_T *list)
Definition
linkm/next.c:10
link__set_next
void link__set_next(VOID_T *a, VOID_T *b)
Definition
linkm/next.c:19
link_new
VOID_T * link_new(struct link_head *Head)
Definition
new.c:12
link_out_of_memory
int link_out_of_memory(void)
Definition
oom.c:4
VOID_T
#define VOID_T
Definition
qtree.h:28
linkm
new.c
Generated on
for GRASS 8 Programmer's Manual by
1.17.0