summaryrefslogtreecommitdiffstats
path: root/lib/list.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/list.c (renamed from libmisc/list.c)50
1 files changed, 23 insertions, 27 deletions
diff --git a/libmisc/list.c b/lib/list.c
index 9d7ec77..9fc6608 100644
--- a/libmisc/list.c
+++ b/lib/list.c
@@ -11,6 +11,8 @@
#ident "$Id$"
#include <assert.h>
+
+#include "alloc.h"
#include "prototypes.h"
#include "defines.h"
/*
@@ -20,7 +22,8 @@
* name, and if not present it is added to a freshly allocated
* list of users.
*/
-/*@only@*/ /*@out@*/char **add_list (/*@returned@*/ /*@only@*/char **list, const char *member)
+/*@only@*/char **
+add_list(/*@returned@*/ /*@only@*/char **list, const char *member)
{
int i;
char **tmp;
@@ -33,7 +36,7 @@
* pointer if it is present.
*/
- for (i = 0; list[i] != (char *) 0; i++) {
+ for (i = 0; list[i] != NULL; i++) {
if (strcmp (list[i], member) == 0) {
return list;
}
@@ -44,7 +47,7 @@
* old entries, and the new entries as well.
*/
- tmp = (char **) xmalloc ((i + 2) * sizeof member);
+ tmp = XMALLOC(i + 2, char *);
/*
* Copy the original list to the new list, then append the
@@ -52,12 +55,12 @@
* is returned to the invoker.
*/
- for (i = 0; list[i] != (char *) 0; i++) {
+ for (i = 0; list[i] != NULL; i++) {
tmp[i] = list[i];
}
tmp[i] = xstrdup (member);
- tmp[i+1] = (char *) 0;
+ tmp[i+1] = NULL;
return tmp;
}
@@ -70,7 +73,8 @@
* list of users.
*/
-/*@only@*/ /*@out@*/char **del_list (/*@returned@*/ /*@only@*/char **list, const char *member)
+/*@only@*/char **
+del_list(/*@returned@*/ /*@only@*/char **list, const char *member)
{
int i, j;
char **tmp;
@@ -83,7 +87,7 @@
* pointer if it is not present.
*/
- for (i = j = 0; list[i] != (char *) 0; i++) {
+ for (i = j = 0; list[i] != NULL; i++) {
if (strcmp (list[i], member) != 0) {
j++;
}
@@ -98,7 +102,7 @@
* old entries.
*/
- tmp = (char **) xmalloc ((j + 1) * sizeof member);
+ tmp = XMALLOC(j + 1, char *);
/*
* Copy the original list except the deleted members to the
@@ -106,14 +110,14 @@
* is returned to the invoker.
*/
- for (i = j = 0; list[i] != (char *) 0; i++) {
+ for (i = j = 0; list[i] != NULL; i++) {
if (strcmp (list[i], member) != 0) {
tmp[j] = list[i];
j++;
}
}
- tmp[j] = (char *) 0;
+ tmp[j] = NULL;
return tmp;
}
@@ -124,7 +128,8 @@
* function with list of members, the list elements are not enforced to be
* constant strings here.
*/
-/*@only@*/ /*@out@*/char **dup_list (char *const *list)
+/*@only@*/char **
+dup_list(char *const *list)
{
int i;
char **tmp;
@@ -133,7 +138,7 @@
for (i = 0; NULL != list[i]; i++);
- tmp = (char **) xmalloc ((i + 1) * sizeof (char *));
+ tmp = XMALLOC(i + 1, char *);
i = 0;
while (NULL != *list) {
@@ -142,7 +147,7 @@
list++;
}
- tmp[i] = (char *) 0;
+ tmp[i] = NULL;
return tmp;
}
@@ -210,14 +215,14 @@ bool is_on_list (char *const *list, const char *member)
* Allocate the array we're going to store the pointers into.
*/
- array = (char **) xmalloc (sizeof (char *) * i);
+ array = XMALLOC(i, char *);
/*
* Empty list is special - 0 members, not 1 empty member. --marekm
*/
if ('\0' == *members) {
- *array = (char *) 0;
+ *array = NULL;
free (members);
return array;
}
@@ -227,18 +232,9 @@ bool is_on_list (char *const *list, const char *member)
* array of pointers.
*/
- for (cp = members, i = 0;; i++) {
- array[i] = cp;
- cp2 = strchr (cp, ',');
- if (NULL != cp2) {
- *cp2 = '\0';
- cp2++;
- cp = cp2;
- } else {
- array[i + 1] = (char *) 0;
- break;
- }
- }
+ for (cp = members, i = 0; cp != NULL; i++)
+ array[i] = strsep(&cp, ",");
+ array[i] = NULL;
/*
* Return the new array of pointers