forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBSStdio.h
51 lines (43 loc) · 837 Bytes
/
BSStdio.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
#ifndef BS_STDIO_H
#define BS_STDIO_H
#include <stdio.h>
#include <exception>
namespace bs
{
class StdIOHelper
{
public:
StdIOHelper()
{
}
size_t printf(const char *format, ...)
{
va_list arg;
va_start(arg, format);
size_t result = vprintf(format, arg);
va_end(arg);
return result;
}
size_t read_line(char* dest, size_t dest_size)
{
char* res = fgets(dest, dest_size, stdin);
if (res == NULL)
{
return 0;
}
size_t len = strlen(dest);
if (dest[len - 1] == '\n')
{
dest[len - 1] = 0;
len--;
}
return len;
}
};
typedef StdIOHelper IOHelper;
inline void fatal()
{
throw std::runtime_error("fatal error");
}
} // namespace bs
#endif //BS_STDIO_H