Debian Codegraph @

common/links.c

raw symbols SCIP
1 /*
2 * Crossfire -- cooperative multi-player graphical RPG and adventure game
3 *
4 * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5 * Copyright (c) 1992 Frank Tore Johansen
6 *
7 * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8 * welcome to redistribute it under certain conditions. For details, please
9 * see COPYING and LICENSE.
10 *
11 * The authors can be reached via e-mail at <[email protected]>.
12 */
13
14 /**
15 * @file links.c
16 * Utility functions for links between objects.
17 */
18
19 #include "global.h"
20
21 #include <stdlib.h>
22
23 /**
24 * Allocates a new objectlink structure, initialises it, and returns
25 * a pointer to it.
26 *
27 * @note
28 * will call fatal() if memory allocation failure, thus never return NULL.
29 *
30 * @return
31 * new link object, cleared.
32 */
33 objectlink *get_objectlink(void) {
34 // Calloc will set these to 0
35 objectlink *ol = (objectlink *)calloc(1, sizeof(objectlink));
36 if (!ol)
37 fatal(OUT_OF_MEMORY);
38 return ol;
39 }
40
41 /**
42 * Allocates a new oblinkpt structure, initialises it, and returns
43 * a pointer to it.
44 *
45 * @note
46 * will call fatal() if memory allocation failure, thus never return NULL.
47 *
48 * @return
49 * new link pointer.
50 */
51 oblinkpt *get_objectlinkpt(void) {
52 // Calloc sets the values to 0 already
53 oblinkpt *obp = (oblinkpt *)calloc(1, sizeof(oblinkpt));
54
55 if (!obp)
56 fatal(OUT_OF_MEMORY);
57 return obp;
58 }
59
60 /**
61 * Recursively frees all objectlinks.
62 *
63 * @param ol
64 * object link to free.
65 */
66
67 void free_objectlink(objectlink *ol) {
68 if (ol->next)
69 free_objectlink(ol->next);
70 free(ol);
71 }
72
73 /**
74 * Recursively frees all linked list of objectlink pointers
75 *
76 * @param obp
77 * pointer to free.
78 */
79 void free_objectlinkpt(oblinkpt *obp) {
80 if (obp->next)
81 free_objectlinkpt(obp->next);
82 if (obp->link)
83 free_objectlink(obp->link);
84 free(obp);
85 }