-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstdio.h
65 lines (54 loc) · 1.36 KB
/
stdio.h
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
#pragma once
#include <cstdarg>
/**
* @file
* @brief Functions similar to standard library.
*
* Documantations omitted, I know you have the POSIX manual.
*
* `stdin` and `stdout` are set to the console, `stderr` is not supported.
*/
/// @name Color control escape strings
//@{
#define CRED "\x1b[31m" ///< red
#define CGRN "\x1b[32m" ///< green
#define CYLW "\x1b[33m" ///< yellow
#define CBLU "\x1b[34m" ///< blue
#define CMAG "\x1b[35m" ///< magenta
#define CCYN "\x1b[36m" ///< cyan
#define CEND "\x1b[0m" ///< back to default color
//@}
struct FILE {
void (*putc)(int ch);
int (*getc)();
};
extern FILE * const stdin;
extern FILE * const stdout;
extern FILE * const stderr;
static inline int getchar()
{
return stdin->getc();
}
// The standard one returns int, but we can't do anything if it fails.
static inline void putchar(int c)
{
stdout->putc(c);
}
// Same to above.
static inline void puts(const char *s)
{
for (; *s; ++s)
putchar(*s);
putchar('\n');
}
// We need this because puts always write trainling new line
static inline void fputs(const char *s, FILE *stream)
{
for (; *s; ++s)
stream->putc(*s);
}
int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
int vfprintf(FILE *stream, const char *format, va_list ap);
// Not a stdio function in fact
char * readline(const char *prompt);