llvm-mos-sdk
stdio.h
Go to the documentation of this file.
1 // Copyright 2022 LLVM-MOS Project
2 // Licensed under the Apache License, Version 2.0 with LLVM Exceptions.
3 // See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
4 // information.
5 
6 #ifndef _STDIO_H_
7 #define _STDIO_H_
8 
9 #include <stdarg.h>
10 #include <stddef.h>
11 #include <stdint.h>
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 // Originally from the Public Domain C Library (PDCLib).
18 
19 struct _FILE;
20 typedef struct _FILE FILE;
21 
22 #define BUFSIZ 256
23 #define EOF (-1)
24 #define FOPEN_MAX 8
25 
26 /* See setvbuf(), third argument */
27 #define _IOFBF (1u << 0)
28 #define _IOLBF (1u << 1)
29 #define _IONBF (1u << 2)
30 
31 typedef uint32_t fpos_t;
32 
33 extern FILE *stdin;
34 extern FILE *stdout;
35 extern FILE *stderr;
36 
37 #define L_tmpnam 6
38 
39 #define SEEK_SET 0
40 #define SEEK_CUR 1
41 #define SEEK_END 2
42 
43 #define TMP_MAX 25
44 
45 // Operations on files
46 int remove(const char *filename);
47 int rename(const char *old, const char *_new);
48 FILE *tmpfile(void);
49 char *tmpnam(char *s);
50 
51 // File access functions
52 
53 int fclose(FILE *stream);
54 int fflush(FILE *stream);
55 FILE *fopen(const char *__restrict__ filename, const char *__restrict__ mode);
56 FILE *freopen(const char *__restrict__ filename, const char *__restrict__ mode,
57  FILE *__restrict__ stream);
58 void setbuf(FILE *__restrict__ stream, char *__restrict__ buf);
59 int setvbuf(FILE *__restrict__ stream, char *__restrict__ buf, int mode,
60  size_t size);
61 
62 // Formated input/output functions
63 
64 int fprintf(FILE *__restrict__ stream, const char *__restrict__ format, ...);
65 int fscanf(FILE *__restrict__ stream, const char *__restrict__ format, ...);
66 int printf(const char *__restrict__ format, ...);
67 int scanf(const char *__restrict__ format, ...);
68 int snprintf(char *__restrict__ s, size_t n, const char *__restrict__ format,
69  ...);
70 int sprintf(char *__restrict__ s, const char *__restrict__ format, ...);
71 int sscanf(const char *__restrict__ s, const char *__restrict__ format, ...);
72 int vfprintf(FILE *__restrict__ stream, const char *__restrict__ format,
73  va_list arg);
74 int vfscanf(FILE *__restrict__ stream, const char *__restrict__ format,
75  va_list arg);
76 int vprintf(const char *__restrict__ format, va_list arg);
77 int vscanf(const char *__restrict__ format, va_list arg);
78 int vsnprintf(char *__restrict__ s, size_t n, const char *__restrict__ format,
79  va_list arg);
80 int vsprintf(char *__restrict__ s, const char *__restrict__ format,
81  va_list arg);
82 int vsscanf(const char *__restrict__ s, const char *__restrict__ format,
83  va_list arg);
84 
85 // Character input/output functions
86 
87 int fgetc(FILE *stream);
88 char *fgets(char *__restrict__ s, int n, FILE *__restrict__ stream);
89 int fputc(int c, FILE *stream);
90 int fputs(const char *__restrict__ s, FILE *__restrict__ stream);
91 int getc(FILE *stream);
92 int getchar(void);
93 int putc(int c, FILE *stream);
94 int putchar(int c);
95 int puts(const char *s);
96 int ungetc(int c, FILE *stream);
97 
98 // Direct input/output functions
99 
100 size_t fread(void *__restrict ptr, size_t size, size_t nmemb,
101  FILE *__restrict__ stream);
102 
103 size_t fwrite(const void *__restrict ptr, size_t size, size_t nmemb,
104  FILE *__restrict__ stream);
105 
106 // File positioning functions
107 
108 int fgetpos(FILE *__restrict__ stream, fpos_t *__restrict__ pos);
109 int fseek(FILE *stream, long int offset, int whence);
110 int fsetpos(FILE *stream, const fpos_t *pos);
111 long int ftell(FILE *stream);
112 void rewind(FILE *stream);
113 
114 // Error-handling functions
115 
116 void clearerr(FILE *stream);
117 int feof(FILE *stream);
118 int ferror(FILE *stream);
119 void perror(const char *s);
120 
121 // Platform-specific backend
122 
123 // Write a sequence of characters in the target's character set that
124 // correspond to the given ASCII character. Returns EOF on write failure.
125 __attribute__((always_inline)) int
126 __from_ascii(char c, void *ctx, int (*write)(char c, void *ctx));
127 
128 // Read a sequence of characters in the target's character set and return the
129 // corrsponding ASCII character. Returns EOF on read failure.
130 __attribute__((always_inline)) int __to_ascii(void *ctx,
131  int (*read)(void *ctx));
132 
133 // Put a character in the target's character set out to the target's
134 // equivalent of file descriptor 1 (stdout).
135 void __putchar(char c);
136 
137 // Get a character in the target's character set from to the target's
138 // equivalent of file descriptor 0 (stdin).
139 int __getchar(void);
140 
141 #ifdef __cplusplus
142 }
143 #endif
144 
145 #endif // not _STDIO_H_
freopen
FILE * freopen(const char *__restrict__ filename, const char *__restrict__ mode, FILE *__restrict__ stream)
putchar
int putchar(int c)
fputs
int fputs(const char *__restrict__ s, FILE *__restrict__ stream)
fwrite
size_t fwrite(const void *__restrict ptr, size_t size, size_t nmemb, FILE *__restrict__ stream)
fflush
int fflush(FILE *stream)
perror
void perror(const char *s)
fread
size_t fread(void *__restrict ptr, size_t size, size_t nmemb, FILE *__restrict__ stream)
vsscanf
int vsscanf(const char *__restrict__ s, const char *__restrict__ format, va_list arg)
clearerr
void clearerr(FILE *stream)
stderr
FILE * stderr
stdin
FILE * stdin
vfscanf
int vfscanf(FILE *__restrict__ stream, const char *__restrict__ format, va_list arg)
printf
int printf(const char *__restrict__ format,...)
fopen
FILE * fopen(const char *__restrict__ filename, const char *__restrict__ mode)
setbuf
void setbuf(FILE *__restrict__ stream, char *__restrict__ buf)
vsnprintf
int vsnprintf(char *__restrict__ s, size_t n, const char *__restrict__ format, va_list arg)
tmpnam
char * tmpnam(char *s)
ctx
void * ctx
Definition: stdio.h:126
puts
int puts(const char *s)
vprintf
int vprintf(const char *__restrict__ format, va_list arg)
fprintf
int fprintf(FILE *__restrict__ stream, const char *__restrict__ format,...)
vfprintf
int vfprintf(FILE *__restrict__ stream, const char *__restrict__ format, va_list arg)
fgetc
int fgetc(FILE *stream)
fpos_t
uint32_t fpos_t
Definition: stdio.h:31
scanf
int scanf(const char *__restrict__ format,...)
fgets
char * fgets(char *__restrict__ s, int n, FILE *__restrict__ stream)
vscanf
int vscanf(const char *__restrict__ format, va_list arg)
snprintf
int snprintf(char *__restrict__ s, size_t n, const char *__restrict__ format,...)
FILE
struct _FILE FILE
Definition: stdio.h:20
fsetpos
int fsetpos(FILE *stream, const fpos_t *pos)
stdout
FILE * stdout
getc
int getc(FILE *stream)
size
unsigned size
Definition: neslib.h:185
tmpfile
FILE * tmpfile(void)
ferror
int ferror(FILE *stream)
rewind
void rewind(FILE *stream)
remove
int remove(const char *filename)
getchar
int getchar(void)
fgetpos
int fgetpos(FILE *__restrict__ stream, fpos_t *__restrict__ pos)
fscanf
int fscanf(FILE *__restrict__ stream, const char *__restrict__ format,...)
fputc
int fputc(int c, FILE *stream)
write
void int(* write)(char c, void *ctx))
Definition: stdio.h:126
read
int(* read)(void *ctx))
Definition: stdio.h:131
fclose
int fclose(FILE *stream)
ftell
long int ftell(FILE *stream)
ungetc
int ungetc(int c, FILE *stream)
putc
int putc(int c, FILE *stream)
vsprintf
int vsprintf(char *__restrict__ s, const char *__restrict__ format, va_list arg)
fseek
int fseek(FILE *stream, long int offset, int whence)
std::uint32_t
::uint32_t uint32_t
Definition: cstdint:23
sprintf
int sprintf(char *__restrict__ s, const char *__restrict__ format,...)
mode
const void uint16_t uint8_t mode
Definition: memory.h:58
setvbuf
int setvbuf(FILE *__restrict__ stream, char *__restrict__ buf, int mode, size_t size)
sscanf
int sscanf(const char *__restrict__ s, const char *__restrict__ format,...)
c
byte byte c
Definition: api.h:59
rename
int rename(const char *old, const char *_new)
feof
int feof(FILE *stream)