Lely core libraries  2.3.4
print.h File Reference
#include <lely/libc/uchar.h>
#include <lely/util/util.h>
#include <stdarg.h>
#include <stddef.h>
Include dependency graph for print.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LENll   "ll"
 A cross-platform "ll" length modifier macro for format specifiers.
 
#define LENj   "j"
 A cross-platform "j" length modifier macro for format specifiers.
 
#define LENz   "z"
 A cross-platform "z" length modifier macro for format specifiers.
 
#define LENt   "t"
 A cross-platform "t" length modifier macro for format specifiers.
 

Functions

int otoc (int i)
 Returns the character corresponding to the octal digit i. More...
 
int xtoc (int i)
 Returns the character corresponding to the hexadecimal digit i. More...
 
size_t print_fmt (char **pbegin, char *end, const char *format,...)
 Prints a formatted string to a memory buffer. More...
 
size_t vprint_fmt (char **pbegin, char *end, const char *format, va_list ap)
 Prints a formatted string to a memory buffer. More...
 
size_t print_char (char **pbegin, char *end, int c)
 Prints a single character to a memory buffer. More...
 
size_t print_utf8 (char **pbegin, char *end, char32_t c32)
 Prints a UTF-8 encoded Unicode character to a memory buffer. More...
 
size_t print_c99_esc (char **pbegin, char *end, char32_t c32)
 Prints a UTF-8 encoded Unicode character to a memory buffer. More...
 
size_t print_c99_str (char **pbegin, char *end, const char *s, size_t n)
 Prints a UTF-8 encoded Unicode string to a memory buffer. More...
 
size_t print_c99_long (char **pbegin, char *end, long l)
 Prints a C99 long to a memory buffer. More...
 
size_t print_c99_ulong (char **pbegin, char *end, unsigned long ul)
 Prints a C99 unsigned long to a memory buffer. More...
 
size_t print_c99_llong (char **pbegin, char *end, long long ll)
 Prints a C99 long long to a memory buffer. More...
 
size_t print_c99_ullong (char **pbegin, char *end, unsigned long long ul)
 Prints a C99 unsigned long long to a memory buffer. More...
 
size_t print_c99_flt (char **pbegin, char *end, float f)
 Prints a C99 float to a memory buffer. More...
 
size_t print_c99_dbl (char **pbegin, char *end, double d)
 Prints a C99 double to a memory buffer. More...
 
size_t print_c99_ldbl (char **pbegin, char *end, long double ld)
 Prints a C99 long double to a memory buffer. More...
 
size_t print_c99_i8 (char **pbegin, char *end, int_least8_t i8)
 Prints a C99 int_least8_t to a memory buffer. More...
 
size_t print_c99_i16 (char **pbegin, char *end, int_least16_t i16)
 Prints a C99 int_least16_t to a memory buffer. More...
 
size_t print_c99_i32 (char **pbegin, char *end, int_least32_t i32)
 Prints a C99 int_least32_t to a memory buffer. More...
 
size_t print_c99_i64 (char **pbegin, char *end, int_least64_t i64)
 Prints a C99 int_least64_t to a memory buffer. More...
 
size_t print_c99_u8 (char **pbegin, char *end, uint_least8_t u8)
 Prints a C99 uint_least8_t to a memory buffer. More...
 
size_t print_c99_u16 (char **pbegin, char *end, uint_least16_t u16)
 Prints a C99 uint_least16_t to a memory buffer. More...
 
size_t print_c99_u32 (char **pbegin, char *end, uint_least32_t u32)
 Prints a C99 uint_least32_t to a memory buffer. More...
 
size_t print_c99_u64 (char **pbegin, char *end, uint_least64_t u64)
 Prints a C99 uint_least64_t to a memory buffer. More...
 
size_t print_base64 (char **pbegin, char *end, const void *ptr, size_t n)
 Prints the Base64 representation of binary data to a memory buffer. More...
 

Detailed Description

This header file is part of the utilities library; it contains the printing function declarations.

Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file print.h.

Function Documentation

◆ otoc()

int otoc ( int  i)
inline

Returns the character corresponding to the octal digit i.

See also
ctoo()

Definition at line 259 of file print.h.

◆ xtoc()

int xtoc ( int  i)
inline

Returns the character corresponding to the hexadecimal digit i.

See also
ctox()

Definition at line 265 of file print.h.

◆ print_fmt()

size_t print_fmt ( char **  pbegin,
char *  end,
const char *  format,
  ... 
)

Prints a formatted string to a memory buffer.

Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written.
formata printf-style format string.
...an optional list of arguments to be printed according to format.
Returns
the number of characters that would have been written had the buffer been sufficiently large, or 0 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 43 of file print.c.

◆ vprint_fmt()

size_t vprint_fmt ( char **  pbegin,
char *  end,
const char *  format,
va_list  ap 
)

Prints a formatted string to a memory buffer.

This function is equivalent to print_fmt(), except that it accepts a va_list instead of a variable number of arguments.

Definition at line 53 of file print.c.

◆ print_char()

size_t print_char ( char **  pbegin,
char *  end,
int  c 
)
inline

Prints a single character to a memory buffer.

Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written.
cthe character to be written.
Returns
1.

Definition at line 286 of file print.h.

◆ print_utf8()

size_t print_utf8 ( char **  pbegin,
char *  end,
char32_t  c32 
)

Prints a UTF-8 encoded Unicode character to a memory buffer.

Illegal Unicode code points are silently replaced by the Unicode replacement character (U+FFFD). Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
c32the Unicode character to be written.
Returns
the number of characters that would have been written had the buffer been sufficiently large.
See also
print_c99_esc()

Definition at line 87 of file print.c.

◆ print_c99_esc()

size_t print_c99_esc ( char **  pbegin,
char *  end,
char32_t  c32 
)

Prints a UTF-8 encoded Unicode character to a memory buffer.

Non-printable ASCII characters are printed using C99 escape sequences, illegal Unicode code points using hexadecimal escape sequences. Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
c32the Unicode character to be written.
Returns
the number of characters that would have been written had the buffer been sufficiently large.
See also
print_utf8()

Definition at line 109 of file print.c.

◆ print_c99_str()

size_t print_c99_str ( char **  pbegin,
char *  end,
const char *  s,
size_t  n 
)

Prints a UTF-8 encoded Unicode string to a memory buffer.

Non-printable ASCII characters are printed using C99 escape sequences, illegal Unicode code points using hexadecimal escape sequences. Note that the output is not delimited by double quotes and not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
sa pointer to the string to be written.
nthe number of characters at s.
Returns
the number of characters that would have been written had the buffer been sufficiently large.
See also
print_c99_esc()

Definition at line 193 of file print.c.

◆ print_c99_long()

size_t print_c99_long ( char **  pbegin,
char *  end,
long  l 
)

Prints a C99 long to a memory buffer.

Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
lthe value to be written.
Returns
the number of characters that would have been written had the buffer been sufficiently large, or 0 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 215 of file print.c.

◆ print_c99_ulong()

size_t print_c99_ulong ( char **  pbegin,
char *  end,
unsigned long  ul 
)

Prints a C99 unsigned long to a memory buffer.

Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
ulthe value to be written.
Returns
the number of characters that would have been written had the buffer been sufficiently large, or 0 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 216 of file print.c.

◆ print_c99_llong()

size_t print_c99_llong ( char **  pbegin,
char *  end,
long long  ll 
)

Prints a C99 long long to a memory buffer.

Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
llthe value to be written.
Returns
the number of characters that would have been written had the buffer been sufficiently large, or 0 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 217 of file print.c.

◆ print_c99_ullong()

size_t print_c99_ullong ( char **  pbegin,
char *  end,
unsigned long long  ul 
)

Prints a C99 unsigned long long to a memory buffer.

Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
ulthe value to be written.
Returns
the number of characters that would have been written had the buffer been sufficiently large, or 0 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 218 of file print.c.

◆ print_c99_flt()

size_t print_c99_flt ( char **  pbegin,
char *  end,
float  f 
)

Prints a C99 float to a memory buffer.

Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
fthe value to be written.
Returns
the number of characters that would have been written had the buffer been sufficiently large, or 0 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 228 of file print.c.

◆ print_c99_dbl()

size_t print_c99_dbl ( char **  pbegin,
char *  end,
double  d 
)

Prints a C99 double to a memory buffer.

Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
dthe value to be written.
Returns
the number of characters that would have been written had the buffer been sufficiently large, or 0 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 229 of file print.c.

◆ print_c99_ldbl()

size_t print_c99_ldbl ( char **  pbegin,
char *  end,
long double  ld 
)

Prints a C99 long double to a memory buffer.

Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
ldthe value to be written.
Returns
the number of characters that would have been written had the buffer been sufficiently large, or 0 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 231 of file print.c.

◆ print_c99_i8()

size_t print_c99_i8 ( char **  pbegin,
char *  end,
int_least8_t  i8 
)

Prints a C99 int_least8_t to a memory buffer.

Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
i8the value to be written.
Returns
the number of characters that would have been written had the buffer been sufficiently large, or 0 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 242 of file print.c.

◆ print_c99_i16()

size_t print_c99_i16 ( char **  pbegin,
char *  end,
int_least16_t  i16 
)

Prints a C99 int_least16_t to a memory buffer.

Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
i16the value to be written.
Returns
the number of characters that would have been written had the buffer been sufficiently large, or 0 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 243 of file print.c.

◆ print_c99_i32()

size_t print_c99_i32 ( char **  pbegin,
char *  end,
int_least32_t  i32 
)

Prints a C99 int_least32_t to a memory buffer.

Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
i32the value to be written.
Returns
the number of characters that would have been written had the buffer been sufficiently large, or 0 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 244 of file print.c.

◆ print_c99_i64()

size_t print_c99_i64 ( char **  pbegin,
char *  end,
int_least64_t  i64 
)

Prints a C99 int_least64_t to a memory buffer.

Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
i64the value to be written.
Returns
the number of characters that would have been written had the buffer been sufficiently large, or 0 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 248 of file print.c.

◆ print_c99_u8()

size_t print_c99_u8 ( char **  pbegin,
char *  end,
uint_least8_t  u8 
)

Prints a C99 uint_least8_t to a memory buffer.

Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
u8the value to be written.
Returns
the number of characters that would have been written had the buffer been sufficiently large, or 0 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 250 of file print.c.

◆ print_c99_u16()

size_t print_c99_u16 ( char **  pbegin,
char *  end,
uint_least16_t  u16 
)

Prints a C99 uint_least16_t to a memory buffer.

Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
u16the value to be written.
Returns
the number of characters that would have been written had the buffer been sufficiently large, or 0 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 251 of file print.c.

◆ print_c99_u32()

size_t print_c99_u32 ( char **  pbegin,
char *  end,
uint_least32_t  u32 
)

Prints a C99 uint_least32_t to a memory buffer.

Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
u32the value to be written.
Returns
the number of characters that would have been written had the buffer been sufficiently large, or 0 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 252 of file print.c.

◆ print_c99_u64()

size_t print_c99_u64 ( char **  pbegin,
char *  end,
uint_least64_t  u64 
)

Prints a C99 uint_least64_t to a memory buffer.

Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
u64the value to be written.
Returns
the number of characters that would have been written had the buffer been sufficiently large, or 0 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 256 of file print.c.

◆ print_base64()

size_t print_base64 ( char **  pbegin,
char *  end,
const void *  ptr,
size_t  n 
)

Prints the Base64 representation of binary data to a memory buffer.

This function implements the MIME variant of Base64 as specified in RFC 2045. Note that the output is not null-terminated.

Parameters
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
ptra pointer to the binary data to be encoded and written.
nthe number of bytes at ptr.
Returns
the number of characters that would have been written had the buffer been sufficiently large.

Definition at line 262 of file print.c.