CS350 COS
COS
Loading...
Searching...
No Matches
stdio.h File Reference
#include <sys/types.h>
#include <sys/cdefs.h>
Include dependency graph for stdio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  FILE
 

Macros

#define SEEK_SET   0
 
#define SEEK_CUR   1
 
#define SEEK_END   2
 
#define EOF   (-1)
 
#define FOPEN_MAX   16
 
#define getc(_fh)   fgetc(_fh)
 

Typedefs

typedef struct FILE FILE
 

Functions

FILEfopen (const char *path, const char *mode)
 
int fclose (FILE *fh)
 
int feof (FILE *fh)
 
int fflush (FILE *fh)
 
size_t fread (void *buf, size_t size, size_t nmemb, FILE *fh)
 
size_t fwrite (const void *buf, size_t size, size_t nmemb, FILE *fh)
 
int fputc (int ch, FILE *fh)
 
int fputs (const char *str, FILE *fh)
 
int fgetc (FILE *fh)
 
char * fgets (char *str, int size, FILE *fh)
 
int puts (const char *str)
 
int printf (const char *fmt,...)
 
int fprintf (FILE *stream, const char *fmt,...)
 
int sprintf (char *str, const char *fmt,...)
 
int snprintf (char *str, size_t size, const char *fmt,...) __printflike(3
 

Variables

FILEstdin
 
FILEstdout
 
FILEstderr
 

Data Structure Documentation

◆ FILE

struct FILE

Definition at line 8 of file stdio.h.

Collaboration diagram for FILE:
[legend]
Data Fields
uint64_t fd
int in_use
fpos_t offset

Macro Definition Documentation

◆ EOF

#define EOF   (-1)

Definition at line 18 of file stdio.h.

◆ FOPEN_MAX

#define FOPEN_MAX   16

Definition at line 24 of file stdio.h.

◆ getc

#define getc (   _fh)    fgetc(_fh)

Definition at line 39 of file stdio.h.

◆ SEEK_CUR

#define SEEK_CUR   1

Definition at line 15 of file stdio.h.

◆ SEEK_END

#define SEEK_END   2

Definition at line 16 of file stdio.h.

◆ SEEK_SET

#define SEEK_SET   0

Definition at line 14 of file stdio.h.

Typedef Documentation

◆ FILE

typedef struct FILE FILE

Function Documentation

◆ fclose()

int fclose ( FILE fh)

Definition at line 86 of file file.c.

87{
88 int status = OSClose(fh->fd);
89
90 _free_file(fh);
91
92 return status;
93}
void _free_file(FILE *fh)
Definition: file.c:56
int OSClose(uint64_t fd)
Definition: syscall.c:83
uint64_t fd
Definition: stdio.h:10
Here is the call graph for this function:

◆ feof()

int feof ( FILE fh)

Definition at line 96 of file file.c.

97{
98 errno = ENOSYS;
99 return -1;
100}
#define ENOSYS
Definition: errno.h:18
#define errno
Definition: errno.h:7

◆ fflush()

int fflush ( FILE fh)

Definition at line 103 of file file.c.

104{
105 errno = ENOSYS;
106 return -1;
107}

◆ fgetc()

int fgetc ( FILE fh)

Definition at line 157 of file file.c.

158{
159 char ch;
160 if (fread(&ch, 1, 1, fh) == 1)
161 return ch;
162 return EOF;
163}
size_t fread(void *buf, size_t size, size_t nmemb, FILE *fh)
Definition: file.c:110
#define EOF
Definition: stdio.h:18
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fgets()

char * fgets ( char *  str,
int  size,
FILE fh 
)

Definition at line 166 of file file.c.

167{
168 int i;
169
170 for (i = 0; i < (size - 1); i++) {
171 int ch = fgetc(fh);
172 if (ch == EOF)
173 return NULL;
174 if (ch == '\b') {
175 if (i > 0)
176 i -= 1;
177 i -= 1;
178 continue;
179 }
180 str[i] = (char)ch;
181 if (ch == '\n') {
182 str[i + 1] = '\0';
183 return str;
184 }
185 }
186
187 str[size - 1] = '\0';
188 return str;
189}
int fgetc(FILE *fh)
Definition: file.c:157
uint32_t size
Definition: multiboot.h:0
#define NULL
Definition: stddef.h:6
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fopen()

FILE * fopen ( const char *  path,
const char *  mode 
)

Definition at line 66 of file file.c.

67{
68 uint64_t fd;
69 FILE *fh;
70 // XXX: handle mode
71
72 fd = OSOpen(path, 0);
73 if (fd == 0)
74 return NULL;
75
76 fh = _alloc_file();
77 fh->fd = fd;
78 fh->offset = 0;
79
80 // XXX: handle append
81
82 return fh;
83}
FILE * _alloc_file()
Definition: file.c:39
uint64_t OSOpen(const char *path, uint64_t flags)
Definition: syscall.c:77
fpos_t offset
Definition: stdio.h:11
Definition: stdio.h:8
unsigned long uint64_t
Definition: types.h:13
Here is the call graph for this function:

◆ fprintf()

int fprintf ( FILE stream,
const char *  fmt,
  ... 
)

Definition at line 224 of file printf.c.

225{
226 int ret;
227 va_list ap;
228
229 va_start(ap, fmt);
230 ret = kvprintf(fmt, fileputc, stream, ap);
231 va_end(ap);
232
233 return ret;
234}
static int kvprintf(char const *fmt, void(*func)(int, void *), void *handle, va_list ap)
Definition: printf.c:75
static void fileputc(int c, void *handle)
Definition: printf.c:207
#define va_end(ap)
Definition: stdarg.h:21
#define va_start(ap, last)
Definition: stdarg.h:9
__builtin_va_list va_list
Definition: stdarg.h:6
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fputc()

int fputc ( int  ch,
FILE fh 
)

Definition at line 124 of file file.c.

125{
126 if (fwrite(&ch, 1, 1, fh) == 1)
127 return ch;
128 return EOF;
129}
size_t fwrite(const void *buf, size_t size, size_t nmemb, FILE *fh)
Definition: file.c:117
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fputs()

int fputs ( const char *  str,
FILE fh 
)

Definition at line 132 of file file.c.

133{
134 int status = fwrite(str, strlen(str), 1, fh);
135 if (status > 0)
136 return status;
137 // XXX: error handling
138 return EOF;
139}
size_t strlen(const char *str)
Definition: string.c:112
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fread()

size_t fread ( void *  buf,
size_t  size,
size_t  nmemb,
FILE fh 
)

Definition at line 110 of file file.c.

111{
112 return OSRead(fh->fd, buf, 0, size * nmemb);
113 // set errno
114}
static char buf[4096]
Definition: ethdump.c:10
int OSRead(uint64_t fd, void *addr, uint64_t off, uint64_t length)
Definition: syscall.c:59
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fwrite()

size_t fwrite ( const void *  buf,
size_t  size,
size_t  nmemb,
FILE fh 
)

Definition at line 117 of file file.c.

118{
119 return OSWrite(fh->fd, buf, 0, size * nmemb);
120 // set errno
121}
int OSWrite(uint64_t fd, const void *addr, uint64_t off, uint64_t length)
Definition: syscall.c:65
Here is the call graph for this function:
Here is the caller graph for this function:

◆ printf()

int printf ( const char *  fmt,
  ... 
)

Definition at line 212 of file printf.c.

213{
214 int ret;
215 va_list ap;
216
217 va_start(ap, fmt);
218 ret = kvprintf(fmt, fileputc, (void *)stdout, ap);
219 va_end(ap);
220
221 return ret;
222}
FILE * stdout
Definition: file.c:16
Here is the call graph for this function:
Here is the caller graph for this function:

◆ puts()

int puts ( const char *  str)

Definition at line 142 of file file.c.

143{
144 int status, status2;
145 status = fputs(str, stdout);
146 if (status < 0)
147 return EOF;
148
149 status2 = fputc('\n', stdout);
150 if (status2 < 0)
151 return EOF;
152
153 return status;
154}
int fputs(const char *str, FILE *fh)
Definition: file.c:132
FILE * stdout
Definition: file.c:16
int fputc(int ch, FILE *fh)
Definition: file.c:124
Here is the call graph for this function:

◆ snprintf()

int snprintf ( char *  str,
size_t  size,
const char *  fmt,
  ... 
)
Here is the caller graph for this function:

◆ sprintf()

int sprintf ( char *  str,
const char *  fmt,
  ... 
)

Definition at line 256 of file printf.c.

257{
258 int ret;
259 va_list ap;
260 StrState state;
261
262 state.buf = str;
263 state.cur = str;
264 state.maxlen = -1;
265
266 va_start(ap, fmt);
267 ret = kvprintf(fmt, strputc, &state, ap);
268 va_end(ap);
269
270 state.cur[0] = '\0';
271
272 return ret;
273}
size_t maxlen
Definition: printf.c:239
char * buf
Definition: printf.c:237
char * cur
Definition: printf.c:238
static void strputc(int c, void *handle)
Definition: printf.c:242
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ stderr

FILE* stderr
extern

Definition at line 17 of file file.c.

◆ stdin

FILE* stdin
extern

Definition at line 15 of file file.c.

◆ stdout

FILE* stdout
extern

Definition at line 16 of file file.c.