10.5. std — Standard functions¶
Source code: src/text/std.h, src/text/std.c
Test code: tst/text/std/main.c
Test coverage: src/text/std.c
Functions
-
int
std_module_init(void)¶
-
ssize_t std_sprintf(char * dst_p, FAR const char * fmt_p, ...) Format and write data to destination buffer. The buffer must be big enough to fit the formatted string. The output is null terminated.
A format specifier has this format:
%[flags][width][length]specifier
where
- flags:
0or- - width:
0..127 - length:
lfor long or nothing - specifier:
c,s,d,i,u,xorf
- Return
- Length of the string written to the destination buffer, not inclusing the null termination, or negative error code.
- Parameters
dst_p: Destination buffer. The formatted string is written to this buffer.fmt_p: Format string....: Variable arguments list.
- flags:
-
ssize_t std_snprintf(char * dst_p, size_t size, FAR const char * fmt_p, ...) Format and write data to given buffer. The output is null terminated.
- Return
- Length of the string written to the destination buffer, not inclusing the null termination, or negative error code.
- Parameters
dst_p: Destination buffer. The formatted string is written to this buffer.size: Size of the destination buffer.fmt_p: Format string....: Variable arguments list.
-
ssize_t std_vsprintf(char * dst_p, FAR const char * fmt_p, va_list * ap_p) Format and write data to given buffer. The output is null terminated.
- Return
- Length of the string written to the destination buffer, not inclusing the null termination, or negative error code.
- Parameters
dst_p: Destination buffer. The formatted string is written to this buffer.fmt_p: Format string.ap_p: Variable arguments list.
-
ssize_t std_vsnprintf(char * dst_p, size_t size, FAR const char * fmt_p, va_list * ap_p) Format and write data to given buffer. The output is null terminated.
- Return
- Length of the string written to the destination buffer, not inclusing the null termination, or negative error code.
- Parameters
dst_p: Destination buffer. The formatted string is written to this buffer.size: Size of the destination buffer.fmt_p: Format string.ap_p: Variable arguments list.
-
ssize_t
std_printf(far_string_t fmt_p, ...)¶ Format and print data to standard output. The output is not null terminated.
See
std_sprintf()for the the format string specification.- Return
- Number of characters written to standard output, or negative error code.
- Parameters
fmt_p: Format string....: Variable arguemnts list.
-
ssize_t std_vprintf(FAR const char * fmt_p, va_list * ap_p) Format and print data to standard output. The output is not null terminated.
See
std_sprintf()for the the format string specification.- Return
- Number of characters written to standard output, or negative error code.
- Parameters
fmt_p: Format string.ap_p: Variable arguemnts list.
-
ssize_t std_fprintf(void * chan_p, FAR const char * fmt_p, ...) Format and print data to channel. The output is not null terminated.
See
std_sprintf()for the the format string specification.- Return
- Number of characters written to given channel, or negative error code.
- Parameters
chan_p: Output channel.fmt_p: Format string....: Variable arguemnts list.
-
ssize_t std_vfprintf(void * chan_p, FAR const char * fmt_p, va_list * ap_p) Format and print data to channel. The output is not null terminated.
See
std_sprintf()for the the format string specification.- Return
- Number of characters written to given channel, or negative error code.
- Parameters
chan_p: Output channel.fmt_p: Format string....: Variable arguemnts list.
-
const char *
std_strtol(const char *str_p, long *value_p)¶ Convert string to integer.
- Return
- Pointer to the next byte or NULL on failure.
- Parameters
str_p: Integer string.value_p: Integer value.
-
const char *
std_strtod(const char *str_p, double *value_p)¶ Convert string to double.
- Return
- Pointer to the next byte or NULL on failure.
- Parameters
str_p: Double string.value_p: Double value.
-
int std_strcpy(char * dst_p, FAR const char * src_p) Copy string from far memory to memory.
- Return
- String length or negative error code.
- Parameters
dst_p: Normal memory string.src_p: Far memory string.
-
int std_strcmp(const char * str_p, FAR const char * fstr_p) Compare a string with a far string.
- Return
- zero(0) if match, otherwise the difference of the mismatched characters
- Parameters
str_p: Normal memory string.fstr_p: Far memory string.
-
int std_strcmp_f(FAR const char * fstr0_p, FAR const char * fstr1_p) Compare two far strings.
- Return
- zero(0) if match, otherwise the difference of the mismatched characters.
- Parameters
fstr0_p: Far memory string.fstr1_p: Far memory string.
-
int std_strncmp(FAR const char * fstr_p, const char * str_p, size_t size) Compare at most
sizebytes of one far string and one string.- Return
- zero(0) if match, otherwise the difference of the mismatched characters.
- Parameters
fstr_p: Far memory string.str_p: String.size: Compare at most size number of bytes.
-
int std_strncmp_f(FAR const char * fstr0_p, FAR const char * fstr1_p, size_t size) Compare at most
sizebytes of two far strings.- Return
- zero(0) if match, otherwise the difference of the mismatched characters.
- Parameters
fstr0_p: Far memory string.fstr1_p: Far memory string.size: Compare at most size number of bytes.
-
int std_strlen(FAR const char * fstr_p) Get the length in bytes of given far string, not including null termination.
- Return
- String length in number of bytes (not including the null termination).
- Parameters
fstr_p: Far memory string.
-
char *
std_strip(char *str_p, const char *strip_p)¶ Strip leading and trailing characters from a string. The characters to strip are given by
strip_p.- Return
- Pointer to the stripped string.
- Parameters
str_p: String to strip characters from.strip_p: Characters to strip or NULL for whitespace characters. Must be null-terminated.