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

68 lines, 43 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
39} // namespace libc
40
41// pylib/locale_.py
42namespace pylocale {
43
44constexpr int codeset = CODESET;
45constexpr int lc_all = LC_ALL;
46constexpr int lc_collate = LC_COLLATE;
47constexpr int lc_ctype = LC_CTYPE;
48#undef CODESET
49#undef LC_ALL
50#undef LC_COLLATE
51#undef LC_CTYPE
52constexpr int CODESET = codeset;
53constexpr int LC_ALL = lc_all;
54constexpr int LC_COLLATE = lc_collate;
55constexpr int LC_CTYPE = lc_ctype;
56
57class Error {
58 public:
59 static constexpr ObjHeader obj_header() {
60 return ObjHeader::ClassFixed(kZeroMask, sizeof(Error));
61 }
62};
63BigStr* setlocale(int category, BigStr* locale);
64BigStr* nl_langinfo(int item);
65
66} // namespace pylocale
67
68#endif // LIBC_H