libsc  2.8.7
The SC library provides support for parallel scientific applications.
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Data Structures | Macros | Typedefs | Functions
sc_string.h File Reference

This file declares a simple string object that can be appended to. More...

#include <sc.h>
Include dependency graph for sc_string.h:

Go to the source code of this file.

Data Structures

struct  sc_string
 This is a simple type for growing a string by printf-like commands. More...
 

Macros

#define SC_STRING_SIZE   4088
 This defines the maximum string storage including the trailing '\0'.
 

Typedefs

typedef struct sc_string sc_string_t
 This is a simple type for growing a string by printf-like commands. More...
 

Functions

void sc_string_init (sc_string_t *scs)
 Initialize to an empty string. More...
 
int sc_string_putc (sc_string_t *scs, int c)
 Append a single character to the string buffer object. More...
 
int sc_string_puts (sc_string_t *scs, const char *s)
 Append a string to the string buffer object. More...
 
int sc_string_putf (sc_string_t *scs, const char *fmt,...)
 Append to the string object using a format string and arguments. More...
 
int sc_string_putv (sc_string_t *scs, const char *fmt, va_list ap)
 Append to the string object using a format string and a vararg pointer. More...
 
const char * sc_string_get_content (sc_string_t *scs, int *length)
 Access content of the string buffer. More...
 

Detailed Description

This file declares a simple string object that can be appended to.

Typedef Documentation

◆ sc_string_t

typedef struct sc_string sc_string_t

This is a simple type for growing a string by printf-like commands.

It is public so it can be declared on the stack to avoid malloc and free. This means that the length of the string is limited to SC_STRING_SIZE - 1. The current string can be accessed by sc_string_get_content. This is really an opaque object: its members shall not be accessed directly.

Function Documentation

◆ sc_string_get_content()

const char* sc_string_get_content ( sc_string_t scs,
int *  length 
)

Access content of the string buffer.

Parameters
[in]scsValid sc_string object.
[in]lengthIf not NULL, assign length without trailing '\0'.
Returns
Pointer to an internally allocated string, may not be used after scs goes out of scope.

◆ sc_string_init()

void sc_string_init ( sc_string_t scs)

Initialize to an empty string.

This function can be used to reset a non-empty string to be empty again.

Parameters
[out]scsAfter returning, a valid object containing the empty string.

◆ sc_string_putc()

int sc_string_putc ( sc_string_t scs,
int  c 
)

Append a single character to the string buffer object.

Parameters
[in,out]scsA valid string buffer object.
[in]cConverted to an unsigned char and appended.
Returns
Zero if the character has been appended and a negative value when the input was truncated.

◆ sc_string_putf()

int sc_string_putf ( sc_string_t scs,
const char *  fmt,
  ... 
)

Append to the string object using a format string and arguments.

The maximum length will not be exceeded. The string object will remain valid even on truncated input.

Parameters
[in,out]scsValid string object that is appended to.
[in]fmtFormat string as used with printf and friends.
Returns
Zero if everything has been appended and a negative value when the input was truncated.

◆ sc_string_puts()

int sc_string_puts ( sc_string_t scs,
const char *  s 
)

Append a string to the string buffer object.

Parameters
[in,out]scsA valid string buffer object.
[in]sThis string is appended to the string buffer.
Returns
Zero if the string has been appended and a negative value when the input was truncated.

◆ sc_string_putv()

int sc_string_putv ( sc_string_t scs,
const char *  fmt,
va_list  ap 
)

Append to the string object using a format string and a vararg pointer.

The maximum length will not be exceeded. The string object will remain valid even on truncated input.

Parameters
[in,out]scsValid string object that is appended to.
[in]fmtFormat string as used with printf and friends.
[in,out]apArgument list pointer as defined in stdarg.h.
Returns
Zero if everything has been appended and a negative value when the input was truncated.