Nugget
Loading...
Searching...
No Matches
Functions
xprintf.h File Reference
#include <stdarg.h>
#include <stddef.h>
#include "common/syscalls/syscalls.h"
Include dependency graph for xprintf.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int vxprintf (void(*func)(const char *, int, void *), void *opaque, const char *fmt, va_list ap)
 Prints a formatted string to a callback.
 
int vsprintf (char *buf, const char *fmt, va_list ap)
 Prints a formatted string to a string.
 
int vsnprintf (char *buf, size_t n, const char *fmt, va_list ap)
 Prints a formatted string to a length-limited string.
 
int vasprintf (char **out, const char *fmt, va_list ap)
 Prints a formatted string to a newly allocated string.
 

Function Documentation

◆ vasprintf()

int vasprintf ( char **  out,
const char *  fmt,
va_list  ap 
)

Prints a formatted string to a newly allocated string.

This function is a helper around vxprintf, which will print to a string, and otherwise behaves the same as normal glibc (v)asprintf. The string will be allocated using psyqo_malloc(), and must be freed using psyqo_free().

Parameters
outThe pointer to the string to allocate.
fmtThe format string.
apThe vararg list of arguments.
Returns
int The number of bytes written.

◆ vsnprintf()

int vsnprintf ( char *  buf,
size_t  n,
const char *  fmt,
va_list  ap 
)

Prints a formatted string to a length-limited string.

This function is a helper around vxprintf, which will print to a string, and otherwise behaves the same as normal libc (v)snprintf.

Parameters
bufThe buffer to print to.
nThe maximum number of bytes to write, including the terminating null byte.
fmtThe format string.
apThe vararg list of arguments.
Returns
int The number of bytes written.

◆ vsprintf()

int vsprintf ( char *  buf,
const char *  fmt,
va_list  ap 
)

Prints a formatted string to a string.

This function is a helper around vxprintf, which will print to a string, and otherwise behaves the same as normal libc (v)sprintf.

Parameters
bufThe buffer to print to.
fmtThe format string.
apThe vararg list of arguments.
Returns
int The number of bytes written.

◆ vxprintf()

int vxprintf ( void(*)(const char *, int, void *)  func,
void opaque,
const char *  fmt,
va_list  ap 
)

Prints a formatted string to a callback.

This function behaves mostly as you'd expect from a typical printf, with some extra formatting options: The '=' flag (similar to '-') causes the output to be centered in the appropriately sized field. The b field outputs an integer in binary notation. The c field now accepts a precision. The character output is repeated by the number of times the precision specifies. The ' field works like c, but takes as its character the next character of the format string, instead of the next. This is useful for when using the precision modifier. For example, ‘printf("%.78&rsquo;-")` prints 78 minus signs, the same as `printf("%.78c", '-')would. S will display a string that has its control characters escaped using the caret notation. For example, character 26, also known as EOF, will be displayed as ^Z. z will display a string, and immediately dispose of it using psyqo_free()‘. r will display a number as an English ordinal. For example, 1 will be displayed as "1st", 2 as "2nd", etc... Another difference with normal printf, is that %#x will output "0x0" instead of "0" for the value 0. Last but not least, the f, e, and a format specifiers are expecting fixed point values. The scale of the fixed point value will default to 4096 for f and e, and 1024 for a, making it suitable for displaying angles. The scale can be specified using the ’/' sign. For instance, "%8.3/255f" will render a fixed point number using 8 characters, with 3 decimal places, and a scale of 255. The f and a format specifiers will render the fixed point number as a signed number, while the e format specifier will render it as an unsigned one. Finally, the callback function will be called with the string to print, and the length of the string. The third argument will be the opaque pointer passed through. The xprintf variant is also available.

Parameters
funcThe callback function to use.
opaqueThe opaque pointer to pass to the callback.
fmtThe format string.
apThe vararg list of arguments.
Returns
int The number of bytes written.