GRASS GIS 8 Programmer's Manual
8.5.0dev(2024)-d6dec75dd4
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_out_of_memory
int link_out_of_memory(void)
Definition:
oom.c:4
link__get_next
VOID_T * link__get_next(VOID_T *)
Definition:
linkm/next.c:10
link__set_next
void link__set_next(VOID_T *, VOID_T *)
Definition:
linkm/next.c:19
linkm.h
VOID_T
#define VOID_T
Definition:
linkm.h:8
link_new
VOID_T * link_new(struct link_head *Head)
Definition:
new.c:12
malloc
void * malloc(YYSIZE_T)
link_head
Definition:
linkm.h:12
link_head::alloced
int alloced
Definition:
linkm.h:15
link_head::chunk_size
int chunk_size
Definition:
linkm.h:16
link_head::exit_flag
int exit_flag
Definition:
linkm.h:19
link_head::unit_size
int unit_size
Definition:
linkm.h:17
link_head::max_ptr
int max_ptr
Definition:
linkm.h:14
link_head::ptr_array
VOID_T ** ptr_array
Definition:
linkm.h:13
link_head::Unused
VOID_T * Unused
Definition:
linkm.h:18
lib
linkm
new.c
Generated on Sun Dec 22 2024 07:38:17 for GRASS GIS 8 Programmer's Manual by
1.9.1