| 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 |
|
| 12 | namespace libc {
|
| 13 |
|
| 14 | // TODO: SHARE with pyext
|
| 15 | inline 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 |
|
| 21 | BigStr* realpath(BigStr* path);
|
| 22 |
|
| 23 | BigStr* gethostname();
|
| 24 |
|
| 25 | int fnmatch(BigStr* pat, BigStr* str, int flags = 0);
|
| 26 |
|
| 27 | List<BigStr*>* glob(BigStr* pat, int flags = 0);
|
| 28 |
|
| 29 | Tuple2<int, int>* regex_first_group_match(BigStr* pattern, BigStr* str,
|
| 30 | int pos);
|
| 31 |
|
| 32 | List<int>* regex_search(BigStr* pattern, int cflags, BigStr* str, int eflags,
|
| 33 | int pos = 0);
|
| 34 |
|
| 35 | int wcswidth(BigStr* str);
|
| 36 | int get_terminal_width();
|
| 37 | int sleep_until_error(double seconds);
|
| 38 |
|
| 39 | } // namespace libc
|
| 40 |
|
| 41 | // pylib/locale_.py
|
| 42 | namespace pylocale {
|
| 43 |
|
| 44 | constexpr int codeset = CODESET;
|
| 45 | constexpr int lc_all = LC_ALL;
|
| 46 | constexpr int lc_collate = LC_COLLATE;
|
| 47 | constexpr int lc_ctype = LC_CTYPE;
|
| 48 | #undef CODESET
|
| 49 | #undef LC_ALL
|
| 50 | #undef LC_COLLATE
|
| 51 | #undef LC_CTYPE
|
| 52 | constexpr int CODESET = codeset;
|
| 53 | constexpr int LC_ALL = lc_all;
|
| 54 | constexpr int LC_COLLATE = lc_collate;
|
| 55 | constexpr int LC_CTYPE = lc_ctype;
|
| 56 |
|
| 57 | class Error {
|
| 58 | public:
|
| 59 | static constexpr ObjHeader obj_header() {
|
| 60 | return ObjHeader::ClassFixed(kZeroMask, sizeof(Error));
|
| 61 | }
|
| 62 | };
|
| 63 | BigStr* setlocale(int category, BigStr* locale);
|
| 64 | BigStr* nl_langinfo(int item);
|
| 65 |
|
| 66 | } // namespace pylocale
|
| 67 |
|
| 68 | #endif // LIBC_H
|