/home/andy/git/oilshell/oil/cpp/leaky_libc.h
Line | Count | Source (jump to first uncovered line) |
1 | | // leaky_libc.h: Replacement for native/libc.c |
2 | | |
3 | | #ifndef LIBC_H |
4 | | #define LIBC_H |
5 | | |
6 | | #include <fnmatch.h> |
7 | | #include <limits.h> |
8 | | #include <stdlib.h> |
9 | | #include <unistd.h> // gethostname() |
10 | | |
11 | | #include "mycpp/runtime.h" |
12 | | |
13 | | namespace libc { |
14 | | |
15 | 0 | inline Str* realpath(Str* path) { |
16 | 0 | char* rp = ::realpath(path->data_, 0); |
17 | 0 | return StrFromC(rp); |
18 | 0 | } |
19 | | |
20 | 1 | inline Str* gethostname() { |
21 | 1 | char* buf = static_cast<char*>(malloc(HOST_NAME_MAX + 1)); |
22 | 1 | int result = ::gethostname(buf, HOST_NAME_MAX); |
23 | 1 | if (result != 0) { |
24 | | // TODO: print errno, e.g. ENAMETOOLONG (glibc) |
25 | 0 | throw Alloc<RuntimeError>(StrFromC("Couldn't get working directory")); |
26 | 0 | } |
27 | 1 | return StrFromC(buf); |
28 | 1 | } |
29 | | |
30 | 4 | inline bool fnmatch(Str* pat, Str* str) { |
31 | 4 | int flags = FNM_EXTMATCH; |
32 | 4 | bool result = ::fnmatch(pat->data(), str->data(), flags) == 0; |
33 | 4 | return result; |
34 | 4 | } |
35 | | |
36 | | List<Str*>* glob(Str* pat); |
37 | | |
38 | | List<Str*>* regex_match(Str* pattern, Str* str); |
39 | | |
40 | | Tuple2<int, int>* regex_first_group_match(Str* pattern, Str* str, int pos); |
41 | | |
42 | 0 | inline void print_time(double real_time, double user_time, double system_time) { |
43 | 0 | // TODO(Jesse): How to we report CPU load? .. Do we need to? |
44 | 0 | printf("%1.2fs user %1.2fs system BUG cpu %1.3f total", user_time, |
45 | 0 | system_time, real_time); // 0.05s user 0.03s system 2% cpu 3.186 total |
46 | 0 | } |
47 | | |
48 | | } // namespace libc |
49 | | |
50 | | #endif // LIBC_H |