1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3
4#include <mos/mos_global.h>
5#include <mos/moslib_global.h>
6#include <stdarg.h>
7#include <stddef.h>
8
9/**
10 * @defgroup libs_stdio libs.Stdio
11 * @ingroup libs
12 * @brief Standard input/output functions.
13 * @{
14 */
15
16// defined in stdio.c & stdio_impl.c
17MOSAPI int __printf(2, 3) sprintf(char *__restrict str, const char *__restrict format, ...);
18MOSAPI int __printf(3, 4) snprintf(char *__restrict str, size_t size, const char *__restrict format, ...);
19MOSAPI int vsprintf(char *__restrict str, const char *__restrict format, va_list ap);
20MOSAPI int vsnprintf(char *__restrict buf, size_t size, const char *__restrict format, va_list args);
21
22#ifndef __MOS_KERNEL__ // for userspace only
23
24typedef struct _FILE FILE;
25MOSAPI FILE *stdin;
26MOSAPI FILE *stdout;
27MOSAPI FILE *stderr;
28
29// C standard says they are macros, make them happy.
30#define stdin stdin
31#define stdout stdout
32#define stderr stderr
33
34MOSAPI int __printf(1, 2) printf(const char *__restrict format, ...);
35MOSAPI int __printf(2, 3) fprintf(FILE *__restrict file, const char *__restrict format, ...);
36MOSAPI int __printf(2, 3) dprintf(int fd, const char *__restrict format, ...);
37MOSAPI int vprintf(const char *__restrict format, va_list ap);
38MOSAPI int vfprintf(FILE *__restrict file, const char *__restrict format, va_list ap);
39MOSAPI int vdprintf(int fd, const char *__restrict format, va_list ap);
40
41MOSAPI int getchar(void);
42MOSAPI int putchar(int c);
43MOSAPI int puts(const char *s);
44
45MOSAPI int fputs(const char *__restrict s, FILE *__restrict file);
46MOSAPI int fputc(int c, FILE *file);
47MOSAPI int fgetc(FILE *file);
48
49size_t fread(void *__restrict ptr, size_t size, size_t nmemb, FILE *__restrict stream);
50size_t fwrite(const void *__restrict ptr, size_t size, size_t nmemb, FILE *__restrict stream);
51int fseek(FILE *stream, long offset, io_seek_whence_t whence);
52off_t ftell(FILE *stream);
53FILE *fopen(const char *path, const char *mode);
54int fclose(FILE *stream);
55#endif
56
57/** @} */
58