Sync with NetBSD -- sl_add() now returns an int.
This commit is contained in:
parent
684d26ea29
commit
0f38d8d9aa
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=109508
@ -49,7 +49,7 @@ typedef struct _stringlist {
|
||||
|
||||
__BEGIN_DECLS
|
||||
StringList *sl_init(void);
|
||||
void sl_add(StringList *, char *);
|
||||
int sl_add(StringList *, char *);
|
||||
void sl_free(StringList *, int);
|
||||
char *sl_find(StringList *, char *);
|
||||
__END_DECLS
|
||||
|
@ -1,6 +1,6 @@
|
||||
.\" $NetBSD: stringlist.3,v 1.2 1997/04/09 08:59:25 kleink Exp $
|
||||
.\" $NetBSD: stringlist.3,v 1.5 1999/03/22 19:44:46 garbled Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
|
||||
.\" Copyright (c) 1997, 1999 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
|
||||
@ -35,7 +35,7 @@
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd February 24, 1997
|
||||
.Dd November 28, 1999
|
||||
.Os
|
||||
.Dt STRINGLIST 3
|
||||
.Sh NAME
|
||||
@ -51,7 +51,7 @@
|
||||
.In stringlist.h
|
||||
.Ft StringList *
|
||||
.Fn sl_init
|
||||
.Ft void
|
||||
.Ft int
|
||||
.Fn sl_add "StringList *sl" "char *item"
|
||||
.Ft void
|
||||
.Fn sl_free "StringList *sl" "int freeall"
|
||||
@ -91,7 +91,10 @@ The following stringlist manipulation functions are available:
|
||||
.It Fn sl_init
|
||||
Create a stringlist.
|
||||
Returns a pointer to a
|
||||
.Vt StringList .
|
||||
.Vt StringList ,
|
||||
or
|
||||
.Dv NULL
|
||||
in case of failure.
|
||||
.It Fn sl_free
|
||||
Releases memory occupied by
|
||||
.Fa sl
|
||||
@ -111,7 +114,8 @@ to
|
||||
at
|
||||
.Fa sl->sl_cur ,
|
||||
extending the size of
|
||||
.Fa sl->sl_str
|
||||
.Fa sl->sl_str .
|
||||
Returns zero upon success, -1 upon failure.
|
||||
.It Fn sl_find
|
||||
Find
|
||||
.Fa item
|
||||
@ -122,3 +126,10 @@ returning NULL if it's not found.
|
||||
.Sh SEE ALSO
|
||||
.Xr free 3 ,
|
||||
.Xr malloc 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
functions appeared in
|
||||
.Fx 2.2.6
|
||||
and
|
||||
.Nx 1.3 .
|
||||
|
@ -51,7 +51,9 @@ __FBSDID("$FreeBSD$");
|
||||
StringList *
|
||||
sl_init()
|
||||
{
|
||||
StringList *sl = malloc(sizeof(StringList));
|
||||
StringList *sl;
|
||||
|
||||
sl = malloc(sizeof(StringList));
|
||||
if (sl == NULL)
|
||||
_err(1, "stringlist: %m");
|
||||
|
||||
@ -67,7 +69,7 @@ sl_init()
|
||||
/*
|
||||
* sl_add(): Add an item to the string list
|
||||
*/
|
||||
void
|
||||
int
|
||||
sl_add(sl, name)
|
||||
StringList *sl;
|
||||
char *name;
|
||||
@ -76,9 +78,10 @@ sl_add(sl, name)
|
||||
sl->sl_max += _SL_CHUNKSIZE;
|
||||
sl->sl_str = reallocf(sl->sl_str, sl->sl_max * sizeof(char *));
|
||||
if (sl->sl_str == NULL)
|
||||
_err(1, "stringlist: %m");
|
||||
return (-1);
|
||||
}
|
||||
sl->sl_str[sl->sl_cur++] = name;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user