---
name: "soldout_buffer"
section: "3"
platform: "linux"
package: "libsoldout-dev"
version: "1.4-7+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/soldout_buffer"
---

# soldout\_buffer(3)

buffer handling functions for soldout

## NAME

**soldout\_buffer**, **bufcasecmp**, **bufcmp**, **bufcmps**, **bufdup**, **bufgrow**, **bufnew**, **bufnullterm**, **bufprintf**, **bufput**, **bufputs**, **bufputc**, **bufrelease**, **bufreset**, **bufset**, **bufslurp**, **buftoi**, **vbufprintf** – buffer handling functions for soldout

## SYNOPSIS

**#include \<buffer.h\>**

**#define CONST\_BUF(name, string)**

**#define VOLATILE\_BUF(name, strname)**

**#define BUFPUTSL(output, literal)**

*int*\

**bufcasecmp**(*const struct buf \*a*, *const struct buf \*b*);

*int*\

**bufcmp**(*const struct buf \*a*, *const struct buf \*b*);

*int*\

**bufcmps**(*const struct buf \*a*, *const char \*b*);

*struct buf \**\

**bufdup**(*const struct buf \*src*, *size\_t dupunit*);

*int*\

**bufgrow**(*struct buf \*buf*, *size\_t sz*);

*struct buf \**\

**bufnew**(*size\_t unit*);

*void*\

**bufnullterm**(*struct buf \*buf*);

*void*\

**bufprintf**(*struct buf \*buf*, *const char \*fmt*, *...*);

*void*\

**bufput**(*struct buf \*buf*, *const void \*data*, *size\_t len*);

*void*\

**bufputs**(*struct buf \*buf*, *const char \*str*);

*void*\

**bufputc**(*struct buf \*buf*, *char c*);

*void*\

**bufrelease**(*struct buf \*buf*);

*void*\

**bufreset**(*struct buf \*buf*);

*void*\

**bufset**(*struct buf \*\*dest*, *struct buf \*src*);

*void*\

**bufslurp**(*struct buf \*buf*, *size\_t len*);

*int*\

**buftoi**(*struct buf \*buf*, *size\_t offset\_i*, *size\_t \*offset\_o*);

*void*\

**vbufprintf**(*struct buf \*buf*, *const char \*fmt*, *va\_list ap*);

*extern* *long* *buffer\_stat\_nb;* *extern* *size\_t* *buffer\_stat\_alloc\_bytes;*

## DESCRIPTION

### Variables

Compile time options. Statistics are kept about memory usage.

- *buffer\_stat\_nb*

  show how many buffers were created.

- *buffer\_stat\_alloc\_bytes*

  show how many bytes were allocated.

### Types

- *struct buf*

  character array buffer. Consists of the following fields:

  - *char \** *data*

    actual character data.

  - *size\_t* *size*

    size of the string.

  - *size\_t* *asize*

    allocated size (0 = volatile buffer).

  - *size\_t* *unit*

    reallocation unit size (0 = read-only buffer).

  - *int* *ref*

    reference count.

### Macros

- CONST\_BUF

  create a global buffer *name* from a string literal *string*.

- VOLATILE\_BUF

  create a volatile buffer *name* on the stack from a string *strname*.

- BUFPUTSL

  optimized **bufputs**() of a string literal.

### Functions

- **bufcasecmp**()

  compare two buffers ignoring case.

- **bufcmp**()

  compare two buffers.

- **bufcmps**()

  compare a buffer to a string.

- **bufdup**()

  duplicate a buffer *src*.

- **bufgrow**()

  increase the allocated size to the given value.

- **bufnew**()

  create a new buffer.

- **bufnullterm**()

  terminate the string array by NUL (making a C-string).

- **bufprintf**()

  print formatted output to a buffer *buf*.

- **bufput**()

  append raw data to a buffer *buf*.

- **bufputs**()

  append a NUL-terminated string *str* to a buffer *buf*.

- **bufputc**()

  append a single char *c* to a buffer *buf*.

- **bufrelease**()

  decrease the reference count and free the buffer *buf* if needed.

- **bufreset**()

  free internal data of the buffer *buf*.

- **bufset**()

  safely assign a buffer to another.

- **bufslurp**()

  remove a given number of bytes from the head of the array.

- **buftoi**()

  convert the numbers at the beginning of the buffer *buf* into an *int*.

- **vbufprintf**()

  [stdarg(3)](/stdarg/3.md) variant of formatted printing into a buffer *buf*.

## RETURN VALUES

The **bufcasecmp**(), **bufcmp**() and **bufcmps**() functions return an integer less than, equal to, or greater than zero if *a* is found, respectively, to be less than, to match, or be greater than *b*.

The **bufdup**() and **bufnew**() functions return a *struct buf \** on success; on error they return NULL.

The **bufgrow**() function returns on success 1; on error - 0.

The **bufnullterm**(), **bufprintf**(), **bufput**(), **bufputs**(), **bufputc**(), **bufrelease**(), **bufreset**(), **bufset**(), **bufslurp**() and **vbufprintf**() functions do not return a value.

The **buftoi**() function return the converted value.

## SEE ALSO

[soldout(3)](/soldout/3.md), [stdarg(3)](/stdarg/3.md)

## AUTHORS

The **soldout** library was written by Natasha "Kerensikova" Porte ⟨*natacha@instinctive.eu*⟩. Manual page was originally written by Massimo Manghi ⟨*mxmanghi@apache.org*⟩, and rewritten to mdoc format by Svyatoslav Mishyn ⟨*juef@openmailbox.org*⟩.
