posix-next API 0.1.0
Out-of-tree Zephyr POSIX module
Loading...
Searching...
No Matches
posix_stdio.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 The Zephyr Contributors
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
20#ifndef ZEPHYR_INCLUDE_POSIX_POSIX_STDIO_H_
21#define ZEPHYR_INCLUDE_POSIX_POSIX_STDIO_H_
22
23#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__)
24
25#include <stdarg.h>
26#include <stddef.h>
27#include <stdio.h>
28
29#include <sys/types.h>
30#include <zephyr/toolchain.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/* FILE must be defined in the libc stdio.h */
37/* fpos_t must be defined in the libc stdio.h */
38/* size_t must be defined in the libc stddef.h */
39
40/* BUFSIZ must be defined in the libc stdio.h */
41/* EOF must be defined in the libc stdio.h */
42/* FOPEN_MAX must be defined in the libc stdio.h */
43/* FILENAME_MAX must be defined in the libc stdio.h */
44/* L_tmpnam must be defined in the libc stdio.h */
45/* TMP_MAX must be defined in the libc stdio.h */
46
47/* _IOFBF must be defined in the libc stdio.h */
48/* _IOLBF must be defined in the libc stdio.h */
49/* _IONBF must be defined in the libc stdio.h */
50
51/* SEEK_CUR must be defined in the libc stdio.h */
52/* SEEK_END must be defined in the libc stdio.h */
53/* SEEK_SET must be defined in the libc stdio.h */
54
55/* NULL must be defined in the libc stddef.h */
56
57/* off_t must be defined in the libc sys/types.h */
58/* ssize_t must be defined in the libc sys/types.h */
59
60#if (_XOPEN_SOURCE >= 500) || defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__)
66#ifndef P_tmpdir
67#define P_tmpdir "/tmp"
68#endif
69
75#if !defined(STREAM_MAX) && defined(FOPEN_MAX)
76#define STREAM_MAX FOPEN_MAX
77#endif
78#endif /* (_XOPEN_SOURCE >= 500) || defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) */
79
80/* stderr must be defined in the libc stdio.h */
81/* stdin must be defined in the libc stdio.h */
82/* stdout must be defined in the libc stdio.h */
83
84/* clearerr() must be declared in the libc stdio.h */
85
86#if (_XOPEN_SOURCE >= 500) || (_POSIX_C_SOURCE >= 200112L) || defined(__DOXYGEN__)
94char *ctermid(char *s);
95#endif /* (_XOPEN_SOURCE >= 500) || (_POSIX_C_SOURCE >= 200112L) || defined(__DOXYGEN__) */
96
97#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__)
107int dprintf(int fildes, const char *ZRESTRICT format, ...);
108#endif /* (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__) */
109
110/* fclose() must be declared in the libc stdio.h */
111
112#if (_XOPEN_SOURCE >= 500) || (_POSIX_C_SOURCE >= 200112L) || defined(__DOXYGEN__)
121FILE *fdopen(int fd, const char *mode);
122
130int fileno(FILE *stream);
131#endif /* (_XOPEN_SOURCE >= 500) || (_POSIX_C_SOURCE >= 200112L) || defined(__DOXYGEN__) */
132
133/* feof() must be declared in the libc stdio.h */
134/* ferror() must be declared in the libc stdio.h */
135/* fflush() must be declared in the libc stdio.h */
136/* fgetc() must be declared in the libc stdio.h */
137/* fgetpos() must be declared in the libc stdio.h */
138/* fgets() must be declared in the libc stdio.h */
139
140#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__)
147void flockfile(FILE *file);
148#endif /* (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__) */
149
150#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__)
160FILE *fmemopen(void *ZRESTRICT buf, size_t size, const char *ZRESTRICT mode);
161#endif /* (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__) */
162
163/* fopen() must be declared in the libc stdio.h */
164/* fprintf() must be declared in the libc stdio.h */
165/* fputc() must be declared in the libc stdio.h */
166/* fputs() must be declared in the libc stdio.h */
167/* fread() must be declared in the libc stdio.h */
168/* freopen() must be declared in the libc stdio.h */
169/* fscanf() must be declared in the libc stdio.h */
170/* fseek() must be declared in the libc stdio.h */
171
172#if (_XOPEN_SOURCE >= 500) || (_POSIX_C_SOURCE >= 200112L) || defined(__DOXYGEN__)
182int fseeko(FILE *stream, off_t offset, int whence);
183#endif /* (_XOPEN_SOURCE >= 500) || (_POSIX_C_SOURCE >= 200112L) || defined(__DOXYGEN__) */
184
185/* fsetpos() must be declared in the libc stdio.h */
186/* ftell() must be declared in the libc stdio.h */
187
188#if (_XOPEN_SOURCE >= 500) || (_POSIX_C_SOURCE >= 200112L) || defined(__DOXYGEN__)
196off_t ftello(FILE *stream);
197#endif /* (_XOPEN_SOURCE >= 500) || (_POSIX_C_SOURCE >= 200112L) || defined(__DOXYGEN__) */
198
199#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__)
207int ftrylockfile(FILE *file);
208
215void funlockfile(FILE *file);
216#endif /* (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__) */
217
218/* fwrite() must be declared in the libc stdio.h */
219/* getc() must be declared in the libc stdio.h */
220/* getchar() must be declared in the libc stdio.h */
221
222#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__)
230int getc_unlocked(FILE *stream);
231
239#endif /* (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__) */
240
241#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__)
253ssize_t getdelim(char **ZRESTRICT lineptr, size_t *ZRESTRICT n, int delimiter,
254 FILE *ZRESTRICT stream);
255
266ssize_t getline(char **ZRESTRICT lineptr, size_t *ZRESTRICT n, FILE *ZRESTRICT stream);
267#endif /* (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__) */
268
269/* gets() must be declared in the libc stdio.h */
270
271#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__)
280FILE *open_memstream(char **bufp, size_t *sizep);
281#endif /* (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__) */
282
283#if (_XOPEN_SOURCE >= 500) || (_POSIX_C_SOURCE >= 200112L) || defined(__DOXYGEN__)
291int pclose(FILE *stream);
292#endif /* (_XOPEN_SOURCE >= 500) || (_POSIX_C_SOURCE >= 200112L) || defined(__DOXYGEN__) */
293
294/* perror() must be declared in the libc stdio.h */
295
296#if (_XOPEN_SOURCE >= 500) || (_POSIX_C_SOURCE >= 200112L) || defined(__DOXYGEN__)
305FILE *popen(const char *command, const char *type);
306#endif /* (_XOPEN_SOURCE >= 500) || (_POSIX_C_SOURCE >= 200112L) || defined(__DOXYGEN__) */
307
308/* printf() must be declared in the libc stdio.h */
309/* putc() must be declared in the libc stdio.h */
310/* putchar() must be declared in the libc stdio.h */
311
312#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__)
321int putc_unlocked(int c, FILE *stream);
322
331#endif /* (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__) */
332
333/* puts() must be declared in the libc stdio.h */
334/* remove() must be declared in the libc stdio.h */
335/* rename() must be declared in the libc stdio.h */
336
337#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__)
348int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath);
349#endif /* (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__) */
350
351/* rewind() must be declared in the libc stdio.h */
352/* scanf() must be declared in the libc stdio.h */
353/* setbuf() must be declared in the libc stdio.h */
354/* setvbuf() must be declared in the libc stdio.h */
355/* snprintf() must be declared in the libc stdio.h */
356/* sprintf() must be declared in the libc stdio.h */
357/* sscanf() must be declared in the libc stdio.h */
358
359#if (_XOPEN_SOURCE >= 500) || defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__)
368char *tempnam(const char *dir, const char *pfx);
369#endif /* (_XOPEN_SOURCE >= 500) || defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) */
370
371/* tmpfile() must be declared in the libc stdio.h */
372/* tmpnam() must be declared in the libc stdio.h */
373/* ungetc() must be declared in the libc stdio.h */
374
375#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__)
385int vdprintf(int fildes, const char *ZRESTRICT format, va_list ap);
386#endif /* (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) || defined(__DOXYGEN__) */
387
388/* vfprintf() must be declared in the libc stdio.h */
389/* vfscanf() must be declared in the libc stdio.h */
390/* vprintf() must be declared in the libc stdio.h */
391/* vscanf() must be declared in the libc stdio.h */
392/* vsnprintf() must be declared in the libc stdio.h */
393/* vsprintf() must be declared in the libc stdio.h */
394/* vsscanf() must be declared in the libc stdio.h */
395
396#ifdef __cplusplus
397}
398#endif
399
400#endif /* defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) */
401
402#endif /* ZEPHYR_INCLUDE_POSIX_POSIX_STDIO_H_ */
ssize_t getline(char **ZRESTRICT lineptr, size_t *ZRESTRICT n, FILE *ZRESTRICT stream)
Read a line from a stream.
int vdprintf(int fildes, const char *ZRESTRICT format, va_list ap)
Print formatted output to a file descriptor.
FILE * fmemopen(void *ZRESTRICT buf, size_t size, const char *ZRESTRICT mode)
Open a memory-backed stream.
FILE * open_memstream(char **bufp, size_t *sizep)
Open a dynamic memory output stream.
ssize_t getdelim(char **ZRESTRICT lineptr, size_t *ZRESTRICT n, int delimiter, FILE *ZRESTRICT stream)
Read a delimited record from a stream.
int dprintf(int fildes, const char *ZRESTRICT format,...)
Print formatted output to a file descriptor.
int fileno(FILE *stream)
Return the file descriptor associated with a stream.
FILE * fdopen(int fd, const char *mode)
Associate a stream with an open file descriptor.
int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath)
Rename a file relative to directory file descriptors.
off_t ftello(FILE *stream)
Obtain the current file offset of a stream.
int fseeko(FILE *stream, off_t offset, int whence)
Reposition a stream to a new offset.
int putchar_unlocked(int c)
Write a byte to stdout without acquiring the stream lock.
int getc_unlocked(FILE *stream)
Read a byte from a stream without acquiring the stream lock.
int putc_unlocked(int c, FILE *stream)
Write a byte to a stream without acquiring the stream lock.
int ftrylockfile(FILE *file)
Try to acquire a stdio stream lock without blocking.
void funlockfile(FILE *file)
Release a stdio stream lock.
void flockfile(FILE *file)
Acquire a stdio stream lock.
int getchar_unlocked(void)
Read a byte from stdin without acquiring the stream lock.
char * tempnam(const char *dir, const char *pfx)
Generate a pathname for a temporary file (obsolescent).
FILE * popen(const char *command, const char *type)
Create a pipe to a process.
char * ctermid(char *s)
Maximum number of streams that one process can have open at one time.
int pclose(FILE *stream)
Close a pipe stream.
POSIX fundamental types (<sys/types.h>)