Sagui library v3.5.0
Cross-platform library which helps to develop web servers or frameworks.
Loading...
Searching...
No Matches
Data Structures | Functions

Data Structures

struct  sg_str
 

Functions

struct sg_strsg_str_new (void) __attribute__((malloc))
 
void sg_str_free (struct sg_str *str)
 
int sg_str_write (struct sg_str *str, const char *val, size_t len)
 
int sg_str_printf_va (struct sg_str *str, const char *fmt, va_list ap)
 
int sg_str_printf (struct sg_str *str, const char *fmt,...) __attribute__((format(printf
 
int const char * sg_str_content (struct sg_str *str)
 
size_t sg_str_length (struct sg_str *str)
 
int sg_str_clear (struct sg_str *str)
 

Detailed Description

String handle and its related functions.

Function Documentation

◆ sg_str_new()

struct sg_str * sg_str_new ( void  )

Creates a new zero-initialized string handle.

Returns
String handle.
Return values
NULLIf no memory space is available.
Examples
example_httpreq_form.c, example_httpuplds.c, example_router_srv.c, and example_str.c.

◆ sg_str_free()

void sg_str_free ( struct sg_str str)

Frees the string handle previously allocated by sg_str_new().

Parameters
[in]strPointer of the string handle to be freed.
Examples
example_httpreq_form.c, example_httpuplds.c, example_router_srv.c, and example_str.c.

◆ sg_str_write()

int sg_str_write ( struct sg_str str,
const char *  val,
size_t  len 
)

Writes a null-terminated string to the string handle str. All strings previously written are kept.

Parameters
[in]strString handle.
[in]valString to be written.
[in]lenLength of the string to be written.
Return values
0Success.
EINVALInvalid argument.

◆ sg_str_printf_va()

int sg_str_printf_va ( struct sg_str str,
const char *  fmt,
va_list  ap 
)

Prints a null-terminated formatted string from the argument list to the string handle str.

Parameters
[in]strString handle.
[in]fmtFormatted string (following the same printf() format specification).
[in]apArguments list (handled by va_start()/ va_end()).
Return values
0Success.
EINVALInvalid argument.

◆ sg_str_printf()

int sg_str_printf ( struct sg_str str,
const char *  fmt,
  ... 
)

Prints a null-terminated formatted string to the string handle str. All strings previously written are kept.

Parameters
[in]strString handle.
[in]fmtFormatted string (following the same printf() format specification).
[in]...Additional arguments (following the same printf() arguments specification).
Return values
0Success.
EINVALInvalid argument.
Examples
example_httpreq_form.c, example_httpuplds.c, example_router_srv.c, and example_str.c.

◆ sg_str_content()

int const char * sg_str_content ( struct sg_str str)

Returns the null-terminated string content from the string handle str.

Parameters
[in]strString handle.
Returns
Content as a null-terminated string.
Return values
NULLIf the str is null and set the errno to EINVAL.
Examples
example_httpreq_form.c, example_httpreq_payload.c, example_httpuplds.c, example_router_srv.c, and example_str.c.

◆ sg_str_length()

size_t sg_str_length ( struct sg_str str)

Returns the total string length from the handle str.

Parameters
[in]strString handle.
Returns
Total string length.
Return values
EINVALInvalid argument.

◆ sg_str_clear()

int sg_str_clear ( struct sg_str str)

Clears all existing content in the string handle str.

Parameters
[in]strString handle.
Return values
0Success.
EINVALInvalid argument.
Examples
example_httpuplds.c.