Nugget
Bare-metal libraries and examples for the original PlayStation
Loading...
Searching...
No Matches
stdio.h
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2026 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27// The subset of stdio libcester and the tests use. Output goes to the TTY
28// through the BIOS putchar, one character at a time.
29
30#pragma once
31
32#include <stdarg.h>
33#include <stddef.h>
34
35#include "common/libc/xprintf.h"
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41typedef struct FILE FILE;
42extern FILE *stdout, *stderr;
43
44int vdprintf(int fd, const char *fmt, va_list ap);
45int vfprintf(FILE *stream, const char *fmt, va_list ap);
46
47static inline int fprintf(FILE *stream, const char *fmt, ...) {
48 va_list ap;
49 va_start(ap, fmt);
50 int r = vfprintf(stream, fmt, ap);
51 va_end(ap);
52 return r;
53}
54
55static inline int vprintf(const char *fmt, va_list ap) { return vfprintf(stdout, fmt, ap); }
56
57static inline int printf(const char *fmt, ...) {
58 va_list ap;
59 va_start(ap, fmt);
60 int r = vfprintf(stdout, fmt, ap);
61 va_end(ap);
62 return r;
63}
64
65static inline int sprintf(char *buf, const char *fmt, ...) {
66 va_list ap;
67 va_start(ap, fmt);
68 int r = vsprintf(buf, fmt, ap);
69 va_end(ap);
70 return r;
71}
72
73static inline int snprintf(char *buf, size_t n, const char *fmt, ...) {
74 va_list ap;
75 va_start(ap, fmt);
76 int r = vsnprintf(buf, n, fmt, ap);
77 va_end(ap);
78 return r;
79}
80
81#ifdef __cplusplus
82}
83#endif
int vsprintf(char *buf, const char *fmt, va_list ap)
Prints a formatted string to a string.
Definition xprintf.c:723
int vsnprintf(char *buf, size_t n, const char *fmt, va_list ap)
Prints a formatted string to a length-limited string.
Definition xprintf.c:730
uint32_t r
Definition cpu.c:222
#define printf
Definition demo.c:35
Definition runtime.c:44
int fd
Definition runtime.c:45
static const void * buf
Definition syscalls.h:61
int vfprintf(FILE *stream, const char *fmt, va_list ap)
Definition runtime.c:58
FILE * stderr
Definition stdio.h:42
FILE * stdout
Definition runtime.c:50
int vdprintf(int fd, const char *fmt, va_list ap)
Definition runtime.c:57