-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathstdio.h
More file actions
113 lines (96 loc) · 2.9 KB
/
stdio.h
File metadata and controls
113 lines (96 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* Copyright (C) 2016 Jeremiah Orians
* This file is part of M2-Planet.
*
* M2-Planet is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* M2-Planet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _STDIO_H
#define _STDIO_H
#ifdef __M2__
/* Actual format of FILE */
struct __IO_FILE
{
int fd;
int bufmode; /* O_RDONLY = 0, O_WRONLY = 1 */
int bufpos;
int file_pos;
int buflen;
char* buffer;
struct __IO_FILE* next;
struct __IO_FILE* prev;
};
/* Now give us the FILE we all love */
typedef struct __IO_FILE FILE;
#include <stdio.c>
#else
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
/* Required constants */
/* For file I/O*/
#define EOF -1
#define BUFSIZ 4096
/* For lseek */
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
/* Actual format of FILE */
struct __IO_FILE
{
int fd;
int bufmode; /* 0 = no buffer, 1 = read, 2 = write */
int bufpos;
int buflen;
char* buffer;
};
/* Now give us the FILE we all love */
typedef struct __IO_FILE FILE;
/* Required variables */
extern FILE* stdin;
extern FILE* stdout;
extern FILE* stderr;
/* Standard C functions */
/* Getting */
extern int fgetc(FILE* f);
extern int getchar();
extern char* fgets(char* str, int count, FILE* stream);
extern size_t fread( void* buffer, size_t size, size_t count, FILE* stream );
/* Putting */
extern void fputc(char s, FILE* f);
extern void putchar(char s);
extern int fputs(char const* str, FILE* stream);
extern int puts(char const* str);
extern size_t fwrite(void const* buffer, size_t size, size_t count, FILE* stream );
/* File management */
extern FILE* fopen(char const* filename, char const* mode);
extern int fclose(FILE* stream);
extern int fflush(FILE* stream);
/* File Positioning */
extern int ungetc(int ch, FILE* stream);
extern long ftell(FILE* stream);
extern int fseek(FILE* f, long offset, int whence);
extern void rewind(FILE* f);
/* Variadic functions */
extern int fprintf(FILE* stream, char* format, ...);
extern int printf(char* format, ...);
extern int snprintf(char* s, size_t n, const char* format, ...);
extern int sprintf(char* s, char* format, ...);
extern int vfprintf(FILE* stream, char* format, va_list arg);
extern int vprintf(const char * format, va_list arg);
extern int vsnprintf(char* s, size_t n, const char* format, va_list arg);
extern int vsprintf(char* s, const char* format, va_list arg);
#endif
#endif