UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / src / lib / apclist.c
blob0cebbcd7cf8620f233f7a2a8f69573bc807c5bac
1 /*
2 * apclist.c
4 * UPS linked list functions.
5 */
7 /*
8 * Copyright (C) 1996-99 Andre M. Hedrick <andre@suse.com>
9 * Copyright (C) 1999-2001 Riccardo Facchetti <riccardo@master.oasi.gpa.it>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General
13 * Public License as published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the Free
22 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 * MA 02111-1307, USA.
26 #include "apc.h"
28 static UPSINFO *upshead = NULL;
31 * The linked list need to be defined in _all_ the forked processes.
32 * The syncronization of data into this structure is done with the shared
33 * memory area so this is made reentrant by the shm mechanics.
36 int insertUps(UPSINFO *ups)
38 UPSINFO *ptr = upshead;
40 if (ptr == NULL) {
41 upshead = ups;
42 } else {
43 while (ptr->next)
44 ptr = ptr->next;
45 ptr->next = ups;
48 return SUCCESS;
51 UPSINFO *getNextUps(UPSINFO *ups)
53 if (ups == NULL)
54 return upshead;
56 return ups->next;
59 UPSINFO *getUpsByname(char *name)
61 UPSINFO *ups = NULL;
63 for (ups = NULL; (ups = getNextUps(ups)) != NULL;) {
64 if (strncmp(name, ups->upsname, strlen(ups->upsname)) == 0)
65 return ups;
68 return NULL;