VSF Documented
stdio.h
Go to the documentation of this file.
1#ifndef __SIMPLE_LIBC_STDIO_H__
2#define __SIMPLE_LIBC_STDIO_H__
3
5
6#if VSF_LINUX_CFG_RELATIVE_PATH == ENABLED && VSF_LINUX_USE_SIMPLE_LIBC == ENABLED
7# include "./stddef.h"
8// for off64_t
9# include "../sys/types.h"
10#else
11# include <stddef.h>
12// for off64_t
13# include <sys/types.h>
14#endif
15
16#include <stdarg.h>
17#include <stdint.h>
18
24#define __USE_LOCAL_STDBOOL__
26
27#if __IS_COMPILER_LLVM__
28# pragma clang diagnostic push
29# pragma clang diagnostic ignored "-Wbuiltin-requires-header"
30# pragma clang diagnostic ignored "-Wincompatible-library-redeclaration"
31# pragma clang diagnostic ignored "-Winconsistent-dllimport"
32#endif
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38// in cstdio, common macro overrides will be undefined
39#if VSF_LINUX_LIBC_CFG_WRAPPER == ENABLED
40#define ferror VSF_LINUX_LIBC_WRAPPER(ferror)
41#define clearerr VSF_LINUX_LIBC_WRAPPER(clearerr)
42#define getc VSF_LINUX_LIBC_WRAPPER(getc)
43#define getchar VSF_LINUX_LIBC_WRAPPER(getchar)
44#define putc VSF_LINUX_LIBC_WRAPPER(putc)
45#define putchar VSF_LINUX_LIBC_WRAPPER(putchar)
46#define ungetc VSF_LINUX_LIBC_WRAPPER(ungetc)
47#define feof VSF_LINUX_LIBC_WRAPPER(feof)
48
49
50#define fopen VSF_LINUX_LIBC_WRAPPER(fopen)
51#define fdopen VSF_LINUX_LIBC_WRAPPER(fdopen)
52#define freopen VSF_LINUX_LIBC_WRAPPER(freopen)
53#define fclose VSF_LINUX_LIBC_WRAPPER(fclose)
54#define fileno VSF_LINUX_LIBC_WRAPPER(fileno)
55#define fseek VSF_LINUX_LIBC_WRAPPER(fseek)
56#define fseeko VSF_LINUX_LIBC_WRAPPER(fseeko)
57#define fseeko64 VSF_LINUX_LIBC_WRAPPER(fseeko64)
58#define ftell VSF_LINUX_LIBC_WRAPPER(ftell)
59#define ftello VSF_LINUX_LIBC_WRAPPER(ftello)
60#define ftello64 VSF_LINUX_LIBC_WRAPPER(ftello64)
61#define rewind VSF_LINUX_LIBC_WRAPPER(rewind)
62#define fgetpos VSF_LINUX_LIBC_WRAPPER(fgetpos)
63#define fsetpos VSF_LINUX_LIBC_WRAPPER(fsetpos)
64#define fgetpos64 VSF_LINUX_LIBC_WRAPPER(fgetpos64)
65#define fsetpos64 VSF_LINUX_LIBC_WRAPPER(fsetpos64)
66#define fwrite VSF_LINUX_LIBC_WRAPPER(fwrite)
67#define fread VSF_LINUX_LIBC_WRAPPER(fread)
68#define fflush VSF_LINUX_LIBC_WRAPPER(fflush)
69#define fgetc VSF_LINUX_LIBC_WRAPPER(fgetc)
70#define fgets VSF_LINUX_LIBC_WRAPPER(fgets)
71#define gets VSF_LINUX_LIBC_WRAPPER(gets)
72#define fputc VSF_LINUX_LIBC_WRAPPER(fputc)
73#define fputs VSF_LINUX_LIBC_WRAPPER(fputs)
74#define puts VSF_LINUX_LIBC_WRAPPER(puts)
75#define printf VSF_LINUX_LIBC_WRAPPER(printf)
76#define vprintf VSF_LINUX_LIBC_WRAPPER(vprintf)
77#define vfprintf VSF_LINUX_LIBC_WRAPPER(vfprintf)
78#define vdprintf VSF_LINUX_LIBC_WRAPPER(vdprintf)
79#define fprintf VSF_LINUX_LIBC_WRAPPER(fprintf)
80#define dprintf VSF_LINUX_LIBC_WRAPPER(dprintf)
81#define fiprintf VSF_LINUX_LIBC_WRAPPER(fiprintf)
82#define fscanf VSF_LINUX_LIBC_WRAPPER(fscanf)
83#define vfscanf VSF_LINUX_LIBC_WRAPPER(vfscanf)
84#define perror VSF_LINUX_LIBC_WRAPPER(perror)
85#define setvbuf VSF_LINUX_LIBC_WRAPPER(setvbuf)
86#define rename VSF_LINUX_LIBC_WRAPPER(rename)
87#define renameat VSF_LINUX_LIBC_WRAPPER(renameat)
88
89#define tmpfile VSF_LINUX_LIBC_WRAPPER(tmpfile)
90#define tmpnam VSF_LINUX_LIBC_WRAPPER(tmpnam)
91
92// usually there is no need to wrap snprintf/vsnprintf.
93// __VSF_LINUX_LIBC_STDIO_WRAPPER_SNPRINTF will be enabled on some platform like windows.
94#if __VSF_LINUX_LIBC_STDIO_WRAPPER_SNPRINTF == ENABLED
95# define vsnprintf VSF_LINUX_LIBC_WRAPPER(vsnprintf)
96# define snprintf VSF_LINUX_LIBC_WRAPPER(snprintf)
97#endif
98
99#if defined(_GNU_SOURCE)
100#define getline VSF_LINUX_LIBC_WRAPPER(getline)
101#endif
102#elif defined(__WIN__) && !defined(__VSF_APPLET__)
103// avoid conflicts with APIs in ucrt
104#define fopen VSF_LINUX_LIBC_WRAPPER(fopen)
105#define freopen VSF_LINUX_LIBC_WRAPPER(freopen)
106#define fclose VSF_LINUX_LIBC_WRAPPER(fclose)
107#define fseek VSF_LINUX_LIBC_WRAPPER(fseek)
108#define ftell VSF_LINUX_LIBC_WRAPPER(ftell)
109#define fflush VSF_LINUX_LIBC_WRAPPER(fflush)
110#define putc VSF_LINUX_LIBC_WRAPPER(putc)
111#define putchar VSF_LINUX_LIBC_WRAPPER(putchar)
112#define fputc VSF_LINUX_LIBC_WRAPPER(fputc)
113#define fprintf VSF_LINUX_LIBC_WRAPPER(fprintf)
114#define vsnprintf VSF_LINUX_LIBC_WRAPPER(vsnprintf)
115#define snprintf VSF_LINUX_LIBC_WRAPPER(snprintf)
116#endif
117
120
121// fpos_t here is not compatible with fpos_t in DLib, so _FPOSOFF MUST be redefined
122#if __IS_COMPILER_IAR__
123# undef _FPOSOFF
124# define _FPOSOFF(__FPOS) (__FPOS)
125#endif
126
127#ifdef __WIN__
128# define sprintf_s snprintf
129# define _scprintf printf
130
131static inline unsigned char swprintf_s(const wchar_t *c, ...)
132{
133 return 0;
134}
135static inline unsigned char _scwprintf(const wchar_t *c, ...)
136{
137 return 0;
138}
139#endif
140
141#ifndef __VSF_STDIO_INTERNAL_FILE_NAME
142# define __VSF_STDIO_INTERNAL_FILE_NAME __VSF_STDIO_FILE
143#endif
144
146 int fd;
148
149// use extern functions with no dependent on shell.linux
150#define stdin __vsf_linux_stdin()
151#define stdout __vsf_linux_stdout()
152#define stderr __vsf_linux_stderr()
153
154#define BUFSIZ 512
155#define L_tmpnam 260
156
157#define SEEK_SET 0 // same value as VSF_FILE_SEEK_SET
158#define SEEK_CUR 1 // same value as VSF_FILE_SEEK_CUR
159#define SEEK_END 2 // same value as VSF_FILE_SEEK_END
160
161#define EOF -1
162
163#define _IOFBF 0x0000
164#define _IOLBF 0x0040
165#define _IONBF 0x0004
166
167#ifndef FILENAME_MAX
168# define FILENAME_MAX 128
169#endif
170
171#if VSF_LINUX_APPLET_USE_LIBC_STDIO == ENABLED
174
178
180
191
196
203
223
226
229
233
240
243
245
250
253
256# ifndef __VSF_APPLET__
258# endif
259#endif
260
261#if defined(__VSF_APPLET__) && (defined(__VSF_APPLET_LIB__) || defined(__VSF_APPLET_LINUX_LIBC_STDIO_LIB__))\
262 && VSF_APPLET_CFG_ABI_PATCH != ENABLED && VSF_LINUX_APPLET_USE_LIBC_STDIO == ENABLED
263
264#ifndef VSF_LINUX_APPLET_LIBC_STDIO_VPLT
265# if VSF_LINUX_USE_APPLET == ENABLED
266# define VSF_LINUX_APPLET_LIBC_STDIO_VPLT \
267 ((vsf_linux_libc_stdio_vplt_t *)(VSF_LINUX_APPLET_VPLT->libc_stdio_vplt))
268# else
269# define VSF_LINUX_APPLET_LIBC_STDIO_VPLT \
270 ((vsf_linux_libc_stdio_vplt_t *)vsf_vplt((void *)0))
271# endif
272#endif
273
274#define VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(__NAME) \
275 VSF_APPLET_VPLT_ENTRY_FUNC_ENTRY(VSF_LINUX_APPLET_LIBC_STDIO_VPLT, __NAME)
276#define VSF_LINUX_APPLET_LIBC_STDIO_IMP(...) \
277 VSF_APPLET_VPLT_ENTRY_FUNC_IMP(VSF_LINUX_APPLET_LIBC_STDIO_VPLT, __VA_ARGS__)
278
279VSF_LINUX_APPLET_LIBC_STDIO_IMP(__vsf_linux_stdin, FILE *, void) {
281 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(__vsf_linux_stdin)();
282}
283VSF_LINUX_APPLET_LIBC_STDIO_IMP(__vsf_linux_stdout, FILE *, void) {
285 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(__vsf_linux_stdout)();
286}
287VSF_LINUX_APPLET_LIBC_STDIO_IMP(__vsf_linux_stderr, FILE *, void) {
289 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(__vsf_linux_stderr)();
290}
291VSF_LINUX_APPLET_LIBC_STDIO_IMP(perror, void, const char *str) {
293 VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(perror)(str);
294}
295VSF_LINUX_APPLET_LIBC_STDIO_IMP(setbuf, void, FILE *f, char *buf) {
297 VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(setbuf)(f, buf);
298}
299VSF_LINUX_APPLET_LIBC_STDIO_IMP(setbuffer, void, FILE *f, char *buf, size_t size) {
301 VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(setbuffer)(f, buf, size);
302}
303VSF_LINUX_APPLET_LIBC_STDIO_IMP(setlinebuf, void, FILE *f) {
305 VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(setlinebuf)(f);
306}
307VSF_LINUX_APPLET_LIBC_STDIO_IMP(setvbuf, int, FILE *f, char *buf, int mode, size_t size) {
309 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(setvbuf)(f, buf, mode, size);
310}
311VSF_LINUX_APPLET_LIBC_STDIO_IMP(putchar, int, int ch) {
313 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(putchar)(ch);
314}
315VSF_LINUX_APPLET_LIBC_STDIO_IMP(getchar, int, void) {
317 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(getchar)();
318}
319VSF_LINUX_APPLET_LIBC_STDIO_IMP(fgetc, int, FILE *f) {
321 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fgetc)(f);
322}
323VSF_LINUX_APPLET_LIBC_STDIO_IMP(fputc, int, int ch, FILE *f) {
325 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fputc)(ch, f);
326}
327VSF_LINUX_APPLET_LIBC_STDIO_IMP(getc, int, FILE *f) {
329 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(getc)(f);
330}
331VSF_LINUX_APPLET_LIBC_STDIO_IMP(putc, int, int ch, FILE *f) {
333 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(putc)(ch, f);
334}
335VSF_LINUX_APPLET_LIBC_STDIO_IMP(ungetc, int, int c, FILE *f) {
337 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(ungetc)(c, f);
338}
339VSF_LINUX_APPLET_LIBC_STDIO_IMP(puts, int, const char *str) {
341 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(puts)(str);
342}
343VSF_LINUX_APPLET_LIBC_STDIO_IMP(fputs, int, const char *str, FILE *f) {
345 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fputs)(str, f);
346}
347VSF_LINUX_APPLET_LIBC_STDIO_IMP(fgets, char *, char *str, int n, FILE *f) {
349 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fgets)(str, n, f);
350}
351VSF_LINUX_APPLET_LIBC_STDIO_IMP(vscanf, int, const char *format, va_list ap) {
353 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(vscanf)(format, ap);
354}
355VSF_LINUX_APPLET_LIBC_STDIO_IMP(vfscanf, int, FILE *f, const char *format, va_list ap) {
357 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(vfscanf)(f, format, ap);
358}
359VSF_LINUX_APPLET_LIBC_STDIO_IMP(vfprintf, int, FILE *f, const char *format, va_list ap) {
361 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(vfprintf)(f, format, ap);
362}
363VSF_LINUX_APPLET_LIBC_STDIO_IMP(vdprintf, int, int fd, const char *format, va_list ap) {
365 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(vdprintf)(fd, format, ap);
366}
367VSF_LINUX_APPLET_LIBC_STDIO_IMP(vprintf, int, const char *format, va_list ap) {
369 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(vprintf)(format, ap);
370}
371VSF_LINUX_APPLET_LIBC_STDIO_IMP(fopen, FILE *, const char *filename, const char *mode) {
373 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fopen)(filename, mode);
374}
375VSF_LINUX_APPLET_LIBC_STDIO_IMP(fdopen, FILE *, int fildes, const char *mode) {
377 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fdopen)(fildes, mode);
378}
379VSF_LINUX_APPLET_LIBC_STDIO_IMP(freopen, FILE *, const char *filename, const char *mode, FILE *f) {
381 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(freopen)(filename, mode, f);
382}
383VSF_LINUX_APPLET_LIBC_STDIO_IMP(fclose, int, FILE *f) {
385 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fclose)(f);
386}
387VSF_LINUX_APPLET_LIBC_STDIO_IMP(fileno, int, FILE *f) {
389 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fileno)(f);
390}
391VSF_LINUX_APPLET_LIBC_STDIO_IMP(fseek, int, FILE *f, long offset, int fromwhere) {
393 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fseek)(f, offset, fromwhere);
394}
395VSF_LINUX_APPLET_LIBC_STDIO_IMP(fseeko, int, FILE *f, off_t offset, int fromwhere) {
397 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fseeko)(f, offset, fromwhere);
398}
399VSF_LINUX_APPLET_LIBC_STDIO_IMP(fseeko64, int, FILE *f, off64_t offset, int fromwhere) {
401 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fseeko64)(f, offset, fromwhere);
402}
403VSF_LINUX_APPLET_LIBC_STDIO_IMP(ftell, long, FILE *f) {
405 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(ftell)(f);
406}
407VSF_LINUX_APPLET_LIBC_STDIO_IMP(ftello, off_t, FILE *f) {
409 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(ftello)(f);
410}
411VSF_LINUX_APPLET_LIBC_STDIO_IMP(ftello64, off64_t, FILE *f) {
413 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(ftello64)(f);
414}
415VSF_LINUX_APPLET_LIBC_STDIO_IMP(rewind, void, FILE *f) {
417 VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(rewind)(f);
418}
419VSF_LINUX_APPLET_LIBC_STDIO_IMP(fgetpos, int, FILE *f, fpos_t *pos) {
421 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fgetpos)(f, pos);
422}
423VSF_LINUX_APPLET_LIBC_STDIO_IMP(fsetpos, int, FILE *f, const fpos_t *pos) {
425 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fsetpos)(f, pos);
426}
427VSF_LINUX_APPLET_LIBC_STDIO_IMP(fgetpos64, int, FILE *f, fpos64_t *pos) {
429 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fgetpos64)(f, pos);
430}
431VSF_LINUX_APPLET_LIBC_STDIO_IMP(fsetpos64, int, FILE *f, const fpos64_t *pos) {
433 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fsetpos64)(f, pos);
434}
435VSF_LINUX_APPLET_LIBC_STDIO_IMP(fread, size_t, void *ptr, size_t size, size_t nmemb, FILE *f) {
437 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fread)(ptr, size, nmemb, f);
438}
439VSF_LINUX_APPLET_LIBC_STDIO_IMP(fwrite, size_t, const void *ptr, size_t size, size_t nmemb, FILE *f) {
441 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fwrite)(ptr, size, nmemb, f);
442}
443VSF_LINUX_APPLET_LIBC_STDIO_IMP(fflush, int, FILE *f) {
445 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(fflush)(f);
446}
447VSF_LINUX_APPLET_LIBC_STDIO_IMP(popen, FILE *, const char *command, const char *type) {
449 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(popen)(command, type);
450}
451VSF_LINUX_APPLET_LIBC_STDIO_IMP(pclose, int, FILE *stream) {
453 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(pclose)(stream);
454}
455VSF_LINUX_APPLET_LIBC_STDIO_IMP(rename, int, const char *old_filename, const char *new_filename) {
457 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(rename)(old_filename, new_filename);
458}
459VSF_LINUX_APPLET_LIBC_STDIO_IMP(renameat, int, int olddirfd, const char *oldpath, int newdirfd, const char *newpath) {
461 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(renameat)(olddirfd, oldpath, newdirfd, newpath);
462}
463VSF_LINUX_APPLET_LIBC_STDIO_IMP(ferror, int, FILE *f) {
465 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(ferror)(f);
466}
467VSF_LINUX_APPLET_LIBC_STDIO_IMP(clearerr, void, FILE *f) {
469 VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(clearerr)(f);
470}
471VSF_LINUX_APPLET_LIBC_STDIO_IMP(feof, int, FILE *f) {
473 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(feof)(f);
474}
475VSF_LINUX_APPLET_LIBC_STDIO_IMP(vsprintf, int, char *str, const char *format, va_list ap) {
477 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(vsprintf)(str, format, ap);
478}
479VSF_LINUX_APPLET_LIBC_STDIO_IMP(vsnprintf, int, char *str, size_t size, const char* format, va_list ap) {
481 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(vsnprintf)(str, size, format, ap);
482}
483VSF_LINUX_APPLET_LIBC_STDIO_IMP(vasprintf, int, char **strp, const char *format, va_list ap) {
485 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(vasprintf)(strp, format, ap);
486}
487VSF_LINUX_APPLET_LIBC_STDIO_IMP(vsscanf, int, const char *str, const char *format, va_list ap) {
489 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(vsscanf)(str, format, ap);
490}
491VSF_LINUX_APPLET_LIBC_STDIO_IMP(remove, int, const char *filename) {
493 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(remove)(filename);
494}
495VSF_LINUX_APPLET_LIBC_STDIO_IMP(tmpfile, FILE *, void) {
497 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(tmpfile)();
498}
499VSF_LINUX_APPLET_LIBC_STDIO_IMP(tmpnam, char *, char *str) {
501 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(tmpnam)(str);
502}
503VSF_LINUX_APPLET_LIBC_STDIO_IMP(getline, ssize_t, char **lineptr, size_t *n, FILE *f) {
505 return VSF_LINUX_APPLET_LIBC_STDIO_ENTRY(getline)(lineptr, n, f);
506}
507
508VSF_APPLET_VPLT_FUNC_DECORATOR(scanf) int scanf(const char *format, ...) {
509 int result;
510 va_list ap;
511 va_start(ap, format);
512 result = vscanf(format, ap);
513 va_end(ap);
514 return result;
515}
516VSF_APPLET_VPLT_FUNC_DECORATOR(fscanf) int fscanf(FILE *f, const char *format, ...) {
517 int result;
518 va_list ap;
519 va_start(ap, format);
520 result = vfscanf(f, format, ap);
521 va_end(ap);
522 return result;
523}
524VSF_APPLET_VPLT_FUNC_DECORATOR(printf) int printf(const char *format, ...) {
525 int result;
526 va_list ap;
527 va_start(ap, format);
528 result = vprintf(format, ap);
529 va_end(ap);
530 return result;
531}
532VSF_APPLET_VPLT_FUNC_DECORATOR(fprintf) int fprintf(FILE *f, const char *format, ...) {
533 int result;
534 va_list ap;
535 va_start(ap, format);
536 result = vfprintf(f, format, ap);
537 va_end(ap);
538 return result;
539}
540VSF_APPLET_VPLT_FUNC_DECORATOR(dprintf) int dprintf(int fd, const char *format, ...) {
541 int result;
542 va_list ap;
543 va_start(ap, format);
544 result = vdprintf(fd, format, ap);
545 va_end(ap);
546 return result;
547}
548VSF_APPLET_VPLT_FUNC_DECORATOR(sprintf) int sprintf(char *str, const char *format, ...) {
549 int result;
550 va_list ap;
551 va_start(ap, format);
552 result = vsprintf(str, format, ap);
553 va_end(ap);
554 return result;
555}
556VSF_APPLET_VPLT_FUNC_DECORATOR(snprintf) int snprintf(char *str, size_t size, const char *format, ...) {
557 int result;
558 va_list ap;
559 va_start(ap, format);
560 result = vsnprintf(str, size, format, ap);
561 va_end(ap);
562 return result;
563}
564VSF_APPLET_VPLT_FUNC_DECORATOR(asprintf) int asprintf(char **strp, const char *format, ...) {
565 int result;
566 va_list ap;
567 va_start(ap, format);
568 result = vasprintf(strp, format, ap);
569 va_end(ap);
570 return result;
571}
572VSF_APPLET_VPLT_FUNC_DECORATOR(sscanf) int sscanf(const char *str, const char *format, ...) {
573 int result;
574 va_list ap;
575 va_start(ap, format);
576 result = vsscanf(str, format, ap);
577 va_end(ap);
578 return result;
579}
580
581#else // __VSF_APPLET__ && VSF_LINUX_APPLET_USE_LIBC_STDIO
582
583FILE * __vsf_linux_stdin(void);
586
587void perror(const char *str);
588
589void setbuf(FILE *f, char *buf);
590void setbuffer(FILE *f, char *buf, size_t size);
591void setlinebuf(FILE *f);
592int setvbuf(FILE *f, char *buf, int mode, size_t size);
593
594int putchar(int ch);
595int getchar(void);
596int fgetc(FILE *f);
597int fputc(int ch, FILE *f);
598int getc(FILE *f);
599int putc(int ch, FILE *f);
600int ungetc(int c, FILE *f);
601int puts(const char *str);
602int fputs(const char *str, FILE *f);
603char * fgets(char *str, int n, FILE *f);
604
605int scanf(const char *format, ...);
606int vscanf(const char *format, va_list ap);
607int fscanf(FILE *f, const char *format, ...);
608int vfscanf(FILE *f, const char *format, va_list ap);
609
610int printf(const char *format, ...);
611int fprintf(FILE *f, const char *format, ...);
612int vfprintf(FILE *f, const char *format, va_list ap);
613int dprintf(int fd, const char *format, ...);
614int vdprintf(int fd, const char *format, va_list ap);
615int fiprintf(FILE *f, const char *format, ...);
616int vprintf(const char *format, va_list ap);
617
618FILE * fopen(const char *filename, const char *mode);
619FILE * fdopen(int fildes, const char *mode);
620FILE * freopen(const char *filename, const char *mode, FILE *f);
621int fclose(FILE *f);
622int fileno(FILE *f);
623int fseek(FILE *f, long offset, int fromwhere);
624int fseeko(FILE *f, off_t offset, int fromwhere);
625int fseeko64(FILE *f, off64_t offset, int fromwhere);
626long ftell(FILE *f);
627off_t ftello(FILE *f);
629void rewind(FILE *f);
630size_t fread(void *ptr, size_t size, size_t nmemb, FILE *f);
631size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *f);
632int fflush(FILE *f);
633int fgetpos(FILE *f, fpos_t *pos);
634int fsetpos(FILE *f, const fpos_t *pos);
635int fgetpos64(FILE *f, fpos_t *pos);
636int fsetpos64(FILE *f, const fpos_t *pos);
637
638FILE * popen(const char *command, const char *type);
639int pclose(FILE *stream);
640
641int rename(const char *old_filename, const char *new_filename);
642int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath);
643
644int ferror(FILE *f);
645void clearerr(FILE *f);
646int feof(FILE *f);
647
648int sprintf(char *str, const char *format, ...);
649int vsprintf(char *str, const char *format, va_list ap);
650int snprintf(char *str, size_t size, const char *format, ...);
651int vsnprintf(char *str, size_t size, const char* format, va_list ap);
652int asprintf(char **strp, const char *format, ...);
653int vasprintf(char **strp, const char *format, va_list ap);
654
655int vsscanf(const char *str, const char *format, va_list ap);
656int sscanf(const char *str, const char *format, ...);
657
658int remove(const char *filename);
659
660FILE * tmpfile(void);
661char * tmpnam(char *str);
662#endif // __VSF_APPLET__ && VSF_LINUX_APPLET_USE_LIBC_STDIO
663
664// use static inline for unlocked APIs for better compatibility
665// MACROs will have side effects
666static inline int getc_unlocked(FILE *f) {
667 return getc(f);
668}
669static inline int getchar_unlocked(void) {
670 return getchar();
671}
672static inline int putc_unlocked(int c, FILE *f){
673 return putc(c, f);
674}
675static inline int putchar_unlocked(int c) {
676 return putchar(c);
677}
678static inline void clearerr_unlocked(FILE *f) {
679 clearerr(f);
680}
681static inline int feof_unlocked(FILE *f) {
682 return feof(f);
683}
684static inline int ferror_unlocked(FILE *f) {
685 return ferror(f);
686}
687static inline int fileno_unlocked(FILE *f) {
688 return fileno(f);
689}
690static inline int fflush_unlocked(FILE *f) {
691 return fflush(f);
692}
693static inline int fgetc_unlocked(FILE *f) {
694 return fgetc(f);
695}
696static inline int fputc_unlocked(int ch, FILE *f) {
697 return fputc(ch, f);
698}
699static inline size_t fread_unlocked(void *ptr, size_t size, size_t nmemb, FILE *f) {
700 return fread(ptr, size, nmemb, f);
701}
702static inline size_t fwrite_unlocked(const void *ptr, size_t size, size_t nmemb, FILE *f) {
703 return fwrite(ptr, size, nmemb, f);
704}
705static inline int fputs_unlocked(const char *str, FILE *f) {
706 return fputs(str, f);
707}
708static inline char * fgets_unlocked(char *str, int n, FILE *f) {
709 return fgets(str, n, f);
710}
711static inline FILE *fopen64(const char *filename, const char *mode) {
712 return fopen(filename, mode);
713}
714
715ssize_t getline(char **lineptr, size_t *n, FILE *f);
716
717#if defined(__WIN__) && !defined(__VSF_APPLET__)
718// wrapper for original _lock_file/_unlock_file called in win c++ libs
719#define _lock_file VSF_LINUX_LIBC_WRAPPER(_lock_file)
720#define _unlock_file VSF_LINUX_LIBC_WRAPPER(_unlock_file)
721#define _get_stream_buffer_pointers VSF_LINUX_LIBC_WRAPPER(_get_stream_buffer_pointers)
722void _lock_file(FILE *f);
723void _unlock_file(FILE *f);
724errno_t _get_stream_buffer_pointers(FILE *f, char ***base, char ***ptr, int **cnt);
725int _fseeki64(FILE *f, uint64_t offset, int origin);
726#endif
727
728#ifdef __cplusplus
729}
730#endif
731
732#if __IS_COMPILER_LLVM__
733# pragma clang diagnostic pop
734#endif
735
736#endif
long long off64_t
Definition types.h:97
int ssize_t
Definition types.h:68
long off_t
Definition types.h:95
unsigned long long uint64_t
Definition stdint.h:11
#define vsnprintf
Definition stdio.h:95
#define fopen
Definition stdio.h:50
int vasprintf(char **strp, const char *format, va_list ap)
Definition vsf_linux_glibc_stdio.c:458
#define ftello64
Definition stdio.h:60
#define dprintf
Definition stdio.h:80
#define fread
Definition stdio.h:67
#define tmpnam
Definition stdio.h:90
#define fclose
Definition stdio.h:53
#define fseeko
Definition stdio.h:56
#define vprintf
Definition stdio.h:76
#define ungetc
Definition stdio.h:46
#define fileno
Definition stdio.h:54
void setlinebuf(FILE *f)
Definition vsf_linux_glibc_stdio.c:102
int remove(const char *filename)
Definition vsf_linux_glibc_stdio.c:927
int sprintf(char *str, const char *format,...)
Definition simple_sprintf.c:682
FILE * popen(const char *command, const char *type)
Definition vsf_linux_glibc_stdio.c:811
#define printf
Definition stdio.h:75
#define fscanf
Definition stdio.h:82
#define fiprintf
Definition stdio.h:81
void setbuf(FILE *f, char *buf)
Definition vsf_linux_glibc_stdio.c:87
int vscanf(const char *format, va_list ap)
Definition vsf_linux_glibc_stdio.c:749
#define fputs
Definition stdio.h:73
void setbuffer(FILE *f, char *buf, size_t size)
Definition vsf_linux_glibc_stdio.c:98
#define fflush
Definition stdio.h:68
int scanf(const char *format,...)
Definition vsf_linux_glibc_stdio.c:764
#define vdprintf
Definition stdio.h:78
FILE * __vsf_linux_stderr(void)
Definition vsf_linux_glibc_stdio.c:82
#define freopen
Definition stdio.h:52
#define putchar
Definition stdio.h:45
#define fsetpos64
Definition stdio.h:65
__VSF_VPLT_DECORATOR__ vsf_linux_libc_stdio_vplt_t vsf_linux_libc_stdio_vplt
Definition vsf_linux_glibc_stdio.c:1018
int asprintf(char **strp, const char *format,...)
Definition vsf_linux_glibc_stdio.c:472
#define puts
Definition stdio.h:74
#define fsetpos
Definition stdio.h:63
#define rewind
Definition stdio.h:61
#define tmpfile
Definition stdio.h:89
FILE * __vsf_linux_stdin(void)
Definition vsf_linux_glibc_stdio.c:72
ssize_t getline(char **lineptr, size_t *n, FILE *f)
Definition vsf_linux_glibc_stdio.c:981
#define fseek
Definition stdio.h:55
#define vfscanf
Definition stdio.h:83
#define vfprintf
Definition stdio.h:77
#define perror
Definition stdio.h:84
#define rename
Definition stdio.h:86
#define renameat
Definition stdio.h:87
#define fgetpos
Definition stdio.h:62
#define snprintf
Definition stdio.h:96
#define fgets
Definition stdio.h:70
#define fdopen
Definition stdio.h:51
off64_t fpos64_t
Definition stdio.h:119
int vsprintf(char *str, const char *format, va_list ap)
Definition simple_sprintf.c:673
#define fprintf
Definition stdio.h:79
off64_t fpos_t
Definition stdio.h:118
#define fseeko64
Definition stdio.h:57
int vsscanf(const char *str, const char *format, va_list ap)
Definition simple_sscanf.c:211
FILE * __vsf_linux_stdout(void)
Definition vsf_linux_glibc_stdio.c:77
#define fgetpos64
Definition stdio.h:64
#define feof
Definition stdio.h:47
#define putc
Definition stdio.h:44
#define fgetc
Definition stdio.h:69
#define ferror
Definition stdio.h:40
#define fwrite
Definition stdio.h:66
#define clearerr
Definition stdio.h:41
struct __VSF_STDIO_INTERNAL_FILE_NAME FILE
#define getchar
Definition stdio.h:43
#define getc
Definition stdio.h:42
int sscanf(const char *str, const char *format,...)
Definition simple_sscanf.c:226
#define ftello
Definition stdio.h:59
int pclose(FILE *stream)
Definition vsf_linux_glibc_stdio.c:872
#define fputc
Definition stdio.h:72
#define setvbuf
Definition stdio.h:85
#define ftell
Definition stdio.h:58
Definition stdio.h:145
int fd
Definition stdio.h:146
Definition stdio.h:172
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(vsnprintf)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(setlinebuf)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(asprintf)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(vasprintf)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__vsf_linux_stderr)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(ftello64)
vsf_vplt_info_t info
Definition stdio.h:173
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(fgetpos64)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(setbuffer)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(vdprintf)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(fseeko64)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(snprintf)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(vfprintf)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(renameat)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(vsprintf)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(clearerr)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__vsf_linux_stdout)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(fsetpos64)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__vsf_linux_stdin)
Definition vsf_cfg.h:95
vk_av_control_type_t type
Definition vsf_audio.h:170
#define __VSF_VPLT_DECORATOR__
Definition vsf_cfg.h:93
#define VSF_APPLET_VPLT_ENTRY_FUNC_TRACE()
Definition vsf_cfg.h:165
#define VSF_APPLET_VPLT_FUNC_DECORATOR(__NAME)
Definition vsf_linux_applet_lib.c:1
uint64_t offset
Definition vsf_memfs.h:49
uint32_t size
Definition vsf_memfs.h:50
SDL_PixelFormat format
Definition vsf_sdl2_pixelformat.c:32