Ziti C SDK
Loading...
Searching...
No Matches
ziti_buffer.h File Reference
#include <stdint.h>
#include "externs.h"
#include "ziti_log.h"
#include <unistd.h>

Go to the source code of this file.

Typedefs

typedef struct string_buf_s string_buf_t
 Growing string buffer.
 

Functions

string_buf_tnew_string_buf ()
 Create new string buffer.
 
string_buf_tnew_fixed_string_buf (char *outbuf, size_t max)
 Create buffer using passed in memory for output.
 
void delete_string_buf (string_buf_t *wb)
 Deallocate all memory associated with the given string buffer.
 
int string_buf_append (string_buf_t *wb, const char *str)
 Append \0 terminated string to the buffer.
 
int string_buf_append_urlsafe (string_buf_t *wb, const char *str)
 Appends [str] to [wb] converting to urlsafe encoding.
 
int string_buf_appendn (string_buf_t *wb, const char *str, size_t len)
 Append len bytes from str to the string buffer.
 
int string_buf_append_byte (string_buf_t *wb, char c)
 Append one byte to the string buffer.
 
int string_buf_fmt (string_buf_t *wb, const char *fmt,...)
 printf style append operation.
 
size_t string_buf_size (string_buf_t *wb)
 number of bytes written to the string buffer so far
 
char * string_buf_to_string (string_buf_t *wb, size_t *outlen)
 Allocate string big enough to hold the contents of the buffer with '\0at the end and copy contents into the result.
 

Typedef Documentation

◆ string_buf_t

typedef struct string_buf_s string_buf_t

Growing string buffer.

string_buf allocates memory internally as needed unless it was created with [new_fixed_string_buf()]

Function Documentation

◆ delete_string_buf()

void delete_string_buf ( string_buf_t wb)

Deallocate all memory associated with the given string buffer.

The passed in pointer is not valid after the function invocation.

Parameters
wb

◆ new_fixed_string_buf()

string_buf_t * new_fixed_string_buf ( char *  outbuf,
size_t  max 
)

Create buffer using passed in memory for output.

No new memory will be allocated.

Parameters
outbuf
max
Returns
new buffer instance

◆ new_string_buf()

string_buf_t * new_string_buf ( )

Create new string buffer.

Returns
new buffer instance

◆ string_buf_append()

int string_buf_append ( string_buf_t wb,
const char *  str 
)

Append \0 terminated string to the buffer.

Parameters
wbstring buffer
strstring
Returns
0 on success, -1 if wb is a fixed buffer and appending would go over its limit.

◆ string_buf_append_byte()

int string_buf_append_byte ( string_buf_t wb,
char  c 
)

Append one byte to the string buffer.

Parameters
wbstring buffer
cbyte to append
Returns
0 on success, -1 if wb is a fixed buffer and appending would go over its limit.

◆ string_buf_append_urlsafe()

int string_buf_append_urlsafe ( string_buf_t wb,
const char *  str 
)

Appends [str] to [wb] converting to urlsafe encoding.

◆ string_buf_appendn()

int string_buf_appendn ( string_buf_t wb,
const char *  str,
size_t  len 
)

Append len bytes from str to the string buffer.

Parameters
wbstring buffer
strstring
lennumber of bytes to append
Returns
0 on success, -1 if wb is a fixed buffer and appending would go over its limit.

◆ string_buf_fmt()

int string_buf_fmt ( string_buf_t wb,
const char *  fmt,
  ... 
)

printf style append operation.

Parameters
wbstring buffer
fmtprintf-style format string
...arguments to the fmt argument
Returns
0 on success, -1 if wb is a fixed buffer and appending would go over its limit.

◆ string_buf_size()

size_t string_buf_size ( string_buf_t wb)

number of bytes written to the string buffer so far

Parameters
wbstring buffer
Returns
number of bytes in the buffer

◆ string_buf_to_string()

char * string_buf_to_string ( string_buf_t wb,
size_t *  outlen 
)

Allocate string big enough to hold the contents of the buffer with '\0at the end and copy contents into the result.

String buffer is cleared after operation is complete. @param wb string buffer @param outlen size of the output not including final\0' terminator

Returns
allocated string filled with buffer content