OILS / cpp / libc.h View on Github | oils.pub

70 lines, 44 significant
1// libc.h: Replacement for native/libc.c
2
3#ifndef LIBC_H
4#define LIBC_H
5
6#include <langinfo.h> // using CODESET
7#include <locale.h> // using LC_CTYPE
8#include <stdlib.h>
9
10#include "mycpp/runtime.h"
11
12namespace libc {
13
14// TODO: SHARE with pyext
15inline void print_time(double real, double user, double sys) {
16 fprintf(stderr, "real\t%.3f\n", real);
17 fprintf(stderr, "user\t%.3f\n", user);
18 fprintf(stderr, "sys\t%.3f\n", sys);
19}
20
21BigStr* realpath(BigStr* path);
22
23BigStr* gethostname();
24
25int fnmatch(BigStr* pat, BigStr* str, int flags = 0);
26
27List<BigStr*>* glob(BigStr* pat, int flags = 0);
28
29Tuple2<int, int>* regex_first_group_match(BigStr* pattern, BigStr* str,
30 int pos);
31
32List<int>* regex_search(BigStr* pattern, int cflags, BigStr* str, int eflags,
33 int pos = 0);
34
35int wcswidth(BigStr* str);
36int get_terminal_width();
37int sleep_until_error(double seconds);
38
39BigStr* strsignal(int sig_num);
40
41} // namespace libc
42
43// pylib/locale_.py
44namespace pylocale {
45
46constexpr int codeset = CODESET;
47constexpr int lc_all = LC_ALL;
48constexpr int lc_collate = LC_COLLATE;
49constexpr int lc_ctype = LC_CTYPE;
50#undef CODESET
51#undef LC_ALL
52#undef LC_COLLATE
53#undef LC_CTYPE
54constexpr int CODESET = codeset;
55constexpr int LC_ALL = lc_all;
56constexpr int LC_COLLATE = lc_collate;
57constexpr int LC_CTYPE = lc_ctype;
58
59class Error {
60 public:
61 static constexpr ObjHeader obj_header() {
62 return ObjHeader::ClassFixed(kZeroMask, sizeof(Error));
63 }
64};
65BigStr* setlocale(int category, BigStr* locale);
66BigStr* nl_langinfo(int item);
67
68} // namespace pylocale
69
70#endif // LIBC_H