Updated include-file define name to match file name.
[AROS.git] / compiler / arossupport / removeslist.c
blob6285a639869cc4d36f74bb3532255181305b24a3
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Remove a node from a single linked list
6 Lang: english
7 */
9 #include <aros/system.h>
10 #include <proto/arossupport.h>
12 /*****************************************************************************
14 NAME */
15 #include <proto/arossupport.h>
17 APTR RemoveSList (
19 /* SYNOPSIS */
20 APTR * list,
21 APTR node)
23 /* FUNCTION
24 Remove the node from a single linked list.
26 INPUTS
27 list - Pointer to the pointer which contains the first element
28 of the single linked list.
29 node - The node which is to be removed.
31 RESULT
32 Returns the node if it was in the list.
34 NOTES
35 This function is not part of a library and may thus be called
36 any time.
38 EXAMPLE
39 @atend
41 BUGS
43 SEE ALSO
45 INTERNALS
47 HISTORY
48 24-12-95 digulla created
50 ******************************************************************************/
52 while (*list && *list != node)
53 list = (APTR *)(*list);
55 if (*list)
57 *list = *((APTR *)node);
58 *((APTR *)node) = NULL;
60 return node;
63 return NULL;
64 } /* RemoveSList */
66 #ifdef TEST
67 #include <stdio.h>
69 /* A single linked list looks like this: */
70 struct SNode
72 /* No data before this entry ! */
73 struct SNode * Next;
74 int data;
77 struct SNode * List;
78 struct SNode node1, node2;
80 int main (int argc, char ** argv)
82 struct SNode * ptr;
84 List = &node1;
85 node1.Next = &node2;
86 node2.Next = NULL;
88 ptr = RemoveSList ((APTR *)&List, &node2);
89 if (ptr != &node2)
90 fprintf (stderr, "Error: Couldn't find node2\n");
91 else
92 printf ("node2 removed.\n");
94 ptr = RemoveSList ((APTR *)&List, &node1);
95 if (ptr != &node1)
96 fprintf (stderr, "Error: Couldn't find node1\n");
97 else
98 printf ("node1 removed.\n");
100 if (List)
101 fprintf (stderr, "Error: List is not empty\n");
102 else
103 printf ("List is now empty.\n");
105 printf ("End.\n");
107 #endif