---
name: "rbuf_new"
section: "3"
platform: "linux"
package: "libroy-dev"
version: "1.0.8-1"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/rbuf_new"
---

# rbuf\_new(3)

the rbuf allocation api

## NAME

rbuf\_new - the rbuf allocation api

## SYNOPSIS

\#include \<roy.h\>

RBuf \* rbuf\_new (void);

RBuf \* rbuf\_new\_sized (unsigned int *len*);

RBuf \* rbuf\_new\_with\_str (const char \**str*);

RBuf \* rbuf\_new\_with\_long (const long int *val*);

RBuf \* rbuf\_new\_with\_float (const float *val*);

RBuf \* rbuf\_new\_with\_static (char \**str*);

RBuf \* rbuf\_new\_with\_sprintf (const char \**format*, ...);

RBuf \* rbuf\_new\_with\_data (const char \**str*, unsigned int *len*);

RBuf \* rbuf\_new\_with\_rbuf (const RBuf \**buf*);

## DESCRIPTION

All these calls except *rbuf\_new\_with\_static*(3) create copies of the passed in initialiation data. For the calls that make copies you can free the initialiation data or the rbuf without side-effect.

A call to [*rbuf\_new*(3)](/rbuf_new/3.md) creates a new rbuf that is empty.

A call to *rbuf\_new\_sized*(3) creates a new rbuf which is *len* bytes long with the buffer set to all '\\0's.

A call to *rbuf\_new\_with\_str*(3) creates a new rbuf that starts with the buffer equal to *str*.

A call to *rbuf\_new\_with\_long*(3) creates a new rbuf using the ascii representation of *val*.

A call to *rbuf\_new\_with\_float*(3) creates a new rbuf using the ascii representation of *val*.

A call to *rbuf\_new\_with\_static*(3) creates a new rbuf with the *str*, but does not copy *str* out, instead, it just keeps a pointer to the string you passed in.  The returned rbuf is permanatly set read-only regardless of any other api calls made on the rbuf.  No attempt is ever made to free the passed in string. The programmer still needs to free the returned rbuf. See [*rbuf\_auto*(3)](/rbuf_auto/3.md) if you are interested in reducing performance impact even farther. The returned rbuf is marked read-only; see [*rbuf\_rdonly*(3)](/rbuf_rdonly/3.md) for more details.

A call to *ruf\_new\_with\_sprintf*(3) creates a new rbuf with the formatted string and arguments in the buffer.  The size of the rbuf will automatically expand to contain the length of the formatted string, so there is no worry about overflowing any buffers.

A call to *rbuf\_new\_with\_data*(3) creates a new rbuf which is *len* bytes long with the buffer [*memcpy*(3)](/memcpy/3.md)'ed from *str*.

A call to *rbuf\_new\_with\_rbuf*(3) creates a new rbuf that is a full clone of *buf*.

## RETURN VALUE

Each of these api calls return an rbuf struct for use with other rbuf calls.  The programmer should free the return value of these calls with a call to [*rbuf\_free*(3)](/rbuf_free/3.md) when he/she is done using the rbuf.

## ERRORS

These calls do not error.

## FUNCTION

All [*rbuf\_new*(3)](/rbuf_new/3.md) style api calls are implemented using functions.

## SEE ALSO

[*rbuf*(3)](/rbuf/3.md), [*rbuf\_append*(3)](/rbuf_append/3.md),  [*rbuf\_append\_char*(3)](/rbuf_append_char/3.md), [*rbuf\_append\_data*(3)](/rbuf_append_data/3.md),  [*rbuf\_append\_rbuf*(3)](/rbuf_append_rbuf/3.md), [*rbuf\_append\_sprintf*(3)](/rbuf_append_sprintf/3.md),  [*rbuf\_append\_str*(3)](/rbuf_append_str/3.md), [*rbuf\_append\_vsprintf*(3)](/rbuf_append_vsprintf/3.md),  [*rbuf\_auto*(3)](/rbuf_auto/3.md), [*rbuf\_down*(3)](/rbuf_down/3.md),  [*rbuf\_empty*(3)](/rbuf_empty/3.md), [*rbuf\_equal*(3)](/rbuf_equal/3.md),  [*rbuf\_equal\_data*(3)](/rbuf_equal_data/3.md), [*rbuf\_equal\_rbuf*(3)](/rbuf_equal_rbuf/3.md),  [*rbuf\_equal\_rbuf\_len*(3)](/rbuf_equal_rbuf_len/3.md), [*rbuf\_equal\_rbufcase*(3)](/rbuf_equal_rbufcase/3.md),  [*rbuf\_equal\_str*(3)](/rbuf_equal_str/3.md), [*rbuf\_equal\_str\_len*(3)](/rbuf_equal_str_len/3.md),  [*rbuf\_equal\_strcase*(3)](/rbuf_equal_strcase/3.md), [*rbuf\_erase*(3)](/rbuf_erase/3.md),  [*rbuf\_float*(3)](/rbuf_float/3.md), [*rbuf\_free*(3)](/rbuf_free/3.md),  [*rbuf\_hash*(3)](/rbuf_hash/3.md), [*rbuf\_insert*(3)](/rbuf_insert/3.md),  [*rbuf\_last*(3)](/rbuf_last/3.md), [*rbuf\_len*(3)](/rbuf_len/3.md),  [*rbuf\_long*(3)](/rbuf_long/3.md), [*rbuf\_new\_with\_sprintf*(3)](/rbuf_new_with_sprintf/3.md),  [*rbuf\_own*(3)](/rbuf_own/3.md), [*rbuf\_prepend*(3)](/rbuf_prepend/3.md),  [*rbuf\_prepend\_char*(3)](/rbuf_prepend_char/3.md), [*rbuf\_prepend\_data*(3)](/rbuf_prepend_data/3.md),  [*rbuf\_prepend\_rbuf*(3)](/rbuf_prepend_rbuf/3.md), [*rbuf\_prepend\_str*(3)](/rbuf_prepend_str/3.md),  [*rbuf\_rdonly*(3)](/rbuf_rdonly/3.md), [*rbuf\_set\_to*(3)](/rbuf_set_to/3.md),  [*rbuf\_split*(3)](/rbuf_split/3.md), [*rbuf\_sprintf*(3)](/rbuf_sprintf/3.md),  [*rbuf\_str*(3)](/rbuf_str/3.md), [*rbuf\_truncate*(3)](/rbuf_truncate/3.md),  [*rbuf\_up*(3)](/rbuf_up/3.md), [*roy*(3)](/roy/3.md)
