• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Manage a list of processes. */
2 
3 /*
4  * Copyright (C) 2003-2006 IBM
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19  * 02111-1307, USA.
20  */
21 
22 #include <malloc.h>
23 #include "proclist.h"
24 
add_to_proclist(struct proclist_t * list,struct proclist_item_t * item)25 void add_to_proclist(struct proclist_t *list, struct proclist_item_t *item)
26 {
27 	struct proclist_item_t *curr;
28 
29 	if (list->head == NULL) {
30 		item->next = NULL;
31 		list->head = item;
32 		return;
33 	}
34 
35 	curr = list->head;
36 	while (curr->next != NULL) {
37 		curr = curr->next;
38 	}
39 
40 	item->next = NULL;
41 	curr->next = item;
42 }
43 
remove_from_proclist(struct proclist_t * list,struct proclist_item_t * item)44 void remove_from_proclist(struct proclist_t *list, struct proclist_item_t *item)
45 {
46 	struct proclist_item_t *curr, *prev;
47 
48 	if (list->head == NULL) {
49 		return;
50 	}
51 
52 	if (list->head == item) {
53 		list->head = item->next;
54 		item->next = NULL;
55 		return;
56 	}
57 
58 	prev = list->head;
59 	curr = list->head->next;
60 
61 	while (curr != NULL && curr != item) {
62 		prev = curr;
63 		curr = curr->next;
64 	}
65 
66 	if (curr == NULL) {
67 		return;
68 	}
69 
70 	prev->next = item->next;
71 	item->next = NULL;
72 }
73