---
name: "stringlist"
section: "3"
platform: "linux"
package: "libbsd-dev"
version: "0.8.3-1"
release: "Debian 9 (Stretch)"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/stringlist"
---

# stringlist(3)

stringlist manipulation functions

## NAME

**stringlist**, **sl\_init**, **sl\_add**, **sl\_free**, **sl\_find**, **sl\_delete** – stringlist manipulation functions

## LIBRARY

library “libbsd”

## SYNOPSIS

**#include \<bsd/stringlist.h\>**

*StringList* *\**\

**sl\_init**(*void*);

*int*\

**sl\_add**(*StringList \*sl*, *char \*item*);

*void*\

**sl\_free**(*StringList \*sl*, *int freeall*);

*char* *\**\

**sl\_find**(*StringList \*sl*, *const char \*item*);

*int*\

**sl\_delete**(*StringList \*sl*, *const char \*item*, *int freeit*);

## DESCRIPTION

The **stringlist** functions manipulate stringlists, which are lists of strings that extend automatically if necessary.

The *StringList* structure has the following definition:

```
typedef struct _stringlist {
	char	**sl_str;
	size_t	  sl_max;
	size_t	  sl_cur;
} StringList;
```

where:

- *sl\_str*

  is a pointer to the base of the array containing the list,

- *sl\_max*

  is the size of *sl\_str*, and

- *sl\_cur*

  is the offset in *sl\_str* of the current element.

The following stringlist manipulation functions are available:

- **sl\_init**()

  Create a stringlist. Returns a pointer to a *StringList*, or NULL in case of failure.

- **sl\_free**()

  Releases memory occupied by *sl* and the *sl-sl\_str* array. If *freeall* is non-zero, then each of the items within *sl-sl\_str* is released as well.

- **sl\_add**()

  Add *item* to *sl-sl\_str* at *sl-sl\_cur*, extending the size of *sl-sl\_str*. Returns zero upon success, -1 upon failure.

- **sl\_find**()

  Find *item* in *sl*, returning NULL if it's not found.

- **sl\_delete**()

  Remove *item* from the list. If *freeit* is non-zero, the string is freed. Returns 0 if the name is found and -1 if the name is not found.

## SEE ALSO

[free(3)](/free/3.md), [malloc(3)](/malloc/3.md)

## HISTORY

The **stringlist** functions appeared in FreeBSD 2.2.6 and NetBSD 1.3.
