blob: 2e234badc946eb6f33a0d309d2f7a48e6423c76c [file] [log] [blame]
Antonio Nino Diaz27989a82018-08-17 10:45:47 +01001/*
2 * Copyright (c) 2012-2017 Roberto E. Vargas Caballero
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
Antonio Nino Diaz7c0ff9c2018-08-15 19:51:09 +01006/*
7 * Portions copyright (c) 2018, ARM Limited and Contributors.
8 * All rights reserved.
9 */
Antonio Nino Diaz27989a82018-08-17 10:45:47 +010010
11#ifndef _STDIO_H
12#define _STDIO_H
13
Antonio Nino Diaz7c0ff9c2018-08-15 19:51:09 +010014#include <stdio_.h>
Antonio Nino Diaz27989a82018-08-17 10:45:47 +010015
16#ifndef FOPEN_MAX
17#define FOPEN_MAX 12
18#endif
19
20#ifndef NULL
21#define NULL ((void *) 0)
22#endif
23
24#define EOF -1
25#define SEEK_CUR 0
26#define SEEK_END 1
27#define SEEK_SET 2
28
29
30#define _IOWRITE (1 << 0)
31#define _IOREAD (1 << 1)
32#define _IORW (1 << 2)
33#define _IOEOF (1 << 3)
34#define _IOERR (1 << 4)
35#define _IOSTRG (1 << 5)
36#define _IOTXT (1 << 6)
37#define _IOFBF (1 << 7)
38#define _IOLBF (1 << 8)
39#define _IONBF (1 << 9)
40#define _IOALLOC (1 <<10)
41
42typedef struct {
43 int fd; /* file descriptor */
44 unsigned char *buf; /* pointer to i/o buffer */
45 unsigned char *rp; /* read pointer */
46 unsigned char *wp; /* write pointer */
47 unsigned char *lp; /* write pointer used when line-buffering */
48 size_t len; /* actual length of buffer */
49 unsigned short flags;
50 unsigned char unbuf[1]; /* tiny buffer for unbuffered io */
51} FILE;
52
53extern FILE __iob[FOPEN_MAX];
54
55#define stdin (&__iob[0])
56#define stdout (&__iob[1])
57#define stderr (&__iob[2])
58
59extern int remove(const char *filename);
60extern int rename(const char *old, const char *new);
61extern FILE *tmpfile(void);
62extern char *tmpnam(char *s);
63extern int fclose(FILE *fp);
64extern int fflush(FILE *fp);
65extern FILE *fopen(const char * restrict fname, const char * restrict mode);
66extern FILE *freopen(const char * restrict fname, const char * restrict mode,
67 FILE * restrict fp);
68extern void setbuf(FILE * restrict fp, char * restrict buf);
69extern int setvbuf(FILE * restrict fp,
70 char * restrict buf, int mode, size_t size);
71extern int fprintf(FILE * restrict fp, const char * restrict fmt, ...);
72extern int fscanf(FILE * restrict fp, const char * restrict fmt, ...);
73extern int printf(const char * restrict fmt, ...);
74extern int scanf(const char * restrict fmt, ...);
75extern int snprintf(char * restrict s,
76 size_t n, const char * restrict fmt, ...);
77extern int sprintf(char * restrict s, const char * restrict fmt, ...);
78extern int sscanf(const char * restrict s, const char * restrict fmt, ...);
79
80#ifdef _STDARG_H
81extern int vfprintf(FILE * restrict fp,
82 const char * restrict fmt, va_list arg);
83extern int vfscanf(FILE * restrict fp,
84 const char * restrict fmt, va_list arg);
85extern int vprintf(const char * restrict fmt, va_list arg);
86extern int vscanf(const char * restrict fmt, va_list arg);
87extern int vsnprintf(char * restrict s, size_t n, const char * restrict fmt,
88 va_list arg);
89extern int vsprintf(char * restrict s,
90 const char * restrict fmt, va_list arg);
91extern int vsscanf(const char * restrict s,
92 const char * restrict fmt, va_list arg);
93#endif
94
95extern int fgetc(FILE *fp);
96extern char *fgets(char * restrict s, int n, FILE * restrict fp);
97extern int fputc(int c, FILE *fp);
98extern int fputs(const char * restrict s, FILE * restrict fp);
99extern int getc(FILE *fp);
100extern int getchar(void);
101extern char *gets(char *s);
102extern int putc(int c, FILE *fp);
103extern int putchar(int c);
104extern int puts(const char *s);
105extern int ungetc(int c, FILE *fp);
106extern size_t fread(void * restrict ptr, size_t size, size_t nmemb,
107 FILE * restrict fp);
108extern size_t fwrite(const void * restrict ptr, size_t size, size_t nmemb,
109 FILE * restrict fp);
110extern int fgetpos(FILE * restrict fp, fpos_t * restrict pos);
111extern int fseek(FILE *fp, long int offset, int whence);
112extern int fsetpos(FILE *fp, const fpos_t *pos);
113extern long int ftell(FILE *fp);
114extern void rewind(FILE *fp);
115extern void clearerr(FILE *fp);
116extern int feof(FILE *fp);
117extern int ferror(FILE *fp);
118extern void perror(const char *s);
119
120extern int __getc(FILE *fp);
121extern int __putc(int, FILE *fp);
122
123#ifdef __USE_MACROS
124#ifdef __UNIX_FILES
125#define getc(fp) ((fp)->rp >= (fp)->wp ? __getc(fp) : *(fp)->rp++)
126#define putc(c, fp) ((fp)->wp >= (fp)->rp ? __putc(c,fp) : (*(fp)->wp++ = c))
127#endif
128
129#define ferror(fp) ((fp)->flags & _IOERR)
130#define feof(fp) ((fp)->flags & _IOEOF)
131#define clearerr(fp) (void) ((fp)->flags &= ~(_IOERR|_IOEOF))
132#define getchar() getc(stdin)
133#define putchar(c) putc((c), stdout)
134#define setbuf(fp, b) (void) setvbuf(fp, b, b ? _IOFBF:_IONBF, BUFSIZ)
135#endif
136
137#endif