sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
printf.h File Reference

Small stand-alone implementation of the printf family of functions ((v)printf, (v)s(n)printf etc., geared towards use on embedded systems with a very limited resources. More...

#include <stdarg.h>
#include <stddef.h>

Go to the source code of this file.

Macros

#define ATTR_PRINTF((one_based_format_index)
#define ATTR_VPRINTF(one_based_format_index)
#define PRINTF_ALIAS_STANDARD_FUNCTION_NAMES   0
#define PRINTF_VISIBILITY

Functions

PRINTF_VISIBILITY void putchar_ (char c)
PRINTF_VISIBILITY int fctprintf (void(*out)(char c, void *extra_arg), void *extra_arg, const char *format,...) ATTR_PRINTF(3
PRINTF_VISIBILITY int PRINTF_VISIBILITY int vfctprintf (void(*out)(char c, void *extra_arg), void *extra_arg, const char *format, va_list arg) ATTR_VPRINTF(3)
PRINTF_VISIBILITY int printf_ (const char *format,...) ATTR_PRINTF(1
PRINTF_VISIBILITY int PRINTF_VISIBILITY int vprintf_ (const char *format, va_list arg) ATTR_VPRINTF(1)
PRINTF_VISIBILITY int sprintf_ (char *s, const char *format,...) ATTR_PRINTF(2
PRINTF_VISIBILITY int PRINTF_VISIBILITY int vsprintf_ (char *s, const char *format, va_list arg) ATTR_VPRINTF(2)
PRINTF_VISIBILITY int snprintf_ (char *s, size_t count, const char *format,...) ATTR_PRINTF(3
PRINTF_VISIBILITY int PRINTF_VISIBILITY int vsnprintf_ (char *s, size_t count, const char *format, va_list arg) ATTR_VPRINTF(3)

Detailed Description

Small stand-alone implementation of the printf family of functions ((v)printf, (v)s(n)printf etc., geared towards use on embedded systems with a very limited resources.

Author
(c) Eyal Rozenberg eyalr.nosp@m.oz1@.nosp@m.gmx.c.nosp@m.om 2021-2022, Haifa, Palestine/Israel
(c) Marco Paland (info@.nosp@m.pala.nosp@m.nd.co.nosp@m.m) 2014-2019, PALANDesign Hannover, Germany
Note
Others have made smaller contributions to this file: see the contributors page at https://github.com/eyalroz/printf/graphs/contributors or ask one of the authors.
Note
the implementations are thread-safe; re-entrant; use no functions from the standard library; and do not dynamically allocate any memory.

@license The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition in file printf.h.

Macro Definition Documentation

◆ ATTR_PRINTF

#define ATTR_PRINTF ( )
Value:
, (first_arg))

Definition at line 60 of file printf.h.

Function Documentation

◆ fctprintf()

PRINTF_VISIBILITY int fctprintf ( void(* out )(char c, void *extra_arg),
void * extra_arg,
const char * format,
... )

printf/vprintf with user-specified output function

An alternative to printf_, in which the output function is specified dynamically (rather than putchar_ being used)

Parameters
outAn output function which takes one character and a type-erased additional parameters
extra_argThe type-erased argument to pass to the output function out with each call
formatA string specifying the format of the output, with %-marked specifiers of how to interpret additional arguments.
argAdditional arguments to the function, one for each specifier in format
Returns
The number of characters for which the output f unction was invoked, not counting the terminating null character

◆ printf_()

PRINTF_VISIBILITY int printf_ ( const char * format,
... )

An implementation of the C standard's printf/vprintf

Note
you must implement a putchar_ function for using this function - it invokes putchar_ rather than directly performing any I/O (which insulates it from any dependence on the operating system and external libraries).
Parameters
formatA string specifying the format of the output, with %-marked specifiers of how to interpret additional arguments.
argAdditional arguments to the function, one for each %-specifier in format string
Returns
The number of characters written into s, not counting the terminating null character

◆ snprintf_()

PRINTF_VISIBILITY int snprintf_ ( char * s,
size_t count,
const char * format,
... )

An implementation of the C standard's snprintf/vsnprintf

Parameters
sAn array in which to store the formatted string. It must be large enough to fit either the entire formatted output, or at least n characters. Alternatively, it can be NULL, in which case nothing will be printed, and only the number of characters which could have been printed is tallied and returned.
nThe maximum number of characters to write to the array, including a terminating null character
formatA string specifying the format of the output, with %-marked specifiers of how to interpret additional arguments.
argAdditional arguments to the function, one for each specifier in format
Returns
The number of characters that COULD have been written into s, not counting the terminating null character. A value equal or larger than n indicates truncation. Only when the returned value is non-negative and less than n, the null-terminated string has been fully and successfully printed.

◆ sprintf_()

PRINTF_VISIBILITY int sprintf_ ( char * s,
const char * format,
... )

An implementation of the C standard's sprintf/vsprintf

Note
For security considerations (the potential for exceeding the buffer bounds), please consider using the size-constrained variant, snprintf / vsnprintf , instead.
Parameters
sAn array in which to store the formatted string. It must be large enough to fit the formatted output!
formatA string specifying the format of the output, with %-marked specifiers of how to interpret additional arguments.
argAdditional arguments to the function, one for each specifier in format
Returns
The number of characters written into s, not counting the terminating null character

◆ vfctprintf()

PRINTF_VISIBILITY int PRINTF_VISIBILITY int vfctprintf ( void(* out )(char c, void *extra_arg),
void * extra_arg,
const char * format,
va_list arg )

Definition at line 1378 of file printf.c.

◆ vsnprintf_()

PRINTF_VISIBILITY int PRINTF_VISIBILITY int vsnprintf_ ( char * s,
size_t count,
const char * format,
va_list arg )

Definition at line 1367 of file printf.c.

◆ vsprintf_()

PRINTF_VISIBILITY int PRINTF_VISIBILITY int vsprintf_ ( char * s,
const char * format,
va_list arg )

Definition at line 1373 of file printf.c.