Line | Count | Source |
1 | | #ifndef UTIL_H |
2 | | #define UTIL_H |
3 | | |
4 | | #ifdef WIN32 |
5 | | /* For WriteFile() below */ |
6 | | #include <windows.h> |
7 | | #include <io.h> |
8 | | #include <processenv.h> |
9 | | #include <shellapi.h> |
10 | | #include <wchar.h> |
11 | | #include <wtypes.h> |
12 | | #endif |
13 | | |
14 | | #include "jv.h" |
15 | | |
16 | | jv expand_path(jv); |
17 | | jv get_home(void); |
18 | | jv jq_realpath(jv); |
19 | | |
20 | | /* |
21 | | * The Windows CRT and console are something else. In order for the |
22 | | * console to get UTF-8 written to it correctly we have to bypass stdio |
23 | | * completely. No amount of fflush()ing helps. If the first byte of a |
24 | | * buffer being written with fwrite() is non-ASCII UTF-8 then the |
25 | | * console misinterprets the byte sequence. But one must not |
26 | | * WriteFile() if stdout is a file!1!! |
27 | | * |
28 | | * We carry knowledge of whether the FILE * is a tty everywhere we |
29 | | * output to it just so we can write with WriteFile() if stdout is a |
30 | | * console on WIN32. |
31 | | */ |
32 | | |
33 | 0 | static void priv_fwrite(const char *s, size_t len, FILE *fout, int is_tty) { |
34 | 0 | #ifdef WIN32 |
35 | 0 | if (is_tty) |
36 | 0 | WriteFile((HANDLE)_get_osfhandle(fileno(fout)), s, len, NULL, NULL); |
37 | 0 | else |
38 | 0 | fwrite(s, 1, len, fout); |
39 | 0 | #else |
40 | 0 | fwrite(s, 1, len, fout); |
41 | 0 | #endif |
42 | 0 | } Unexecuted instantiation: jv.c:priv_fwrite Unexecuted instantiation: util.c:priv_fwrite Unexecuted instantiation: execute.c:priv_fwrite Unexecuted instantiation: linker.c:priv_fwrite Unexecuted instantiation: locfile.c:priv_fwrite Unexecuted instantiation: builtin.c:priv_fwrite Unexecuted instantiation: compile.c:priv_fwrite |
43 | | |
44 | | const void *_jq_memmem(const void *haystack, size_t haystacklen, |
45 | | const void *needle, size_t needlelen); |
46 | | |
47 | | #ifndef MIN |
48 | | #define MIN(a,b) \ |
49 | 1 | ({ __typeof__ (a) _a = (a); \ |
50 | 1 | __typeof__ (b) _b = (b); \ |
51 | 1 | _a < _b ? _a : _b; }) |
52 | | #endif |
53 | | #ifndef MAX |
54 | | #define MAX(a,b) \ |
55 | 0 | ({ __typeof__ (a) _a = (a); \ |
56 | 0 | __typeof__ (b) _b = (b); \ |
57 | 0 | _a > _b ? _a : _b; }) |
58 | | #endif |
59 | | |
60 | | #include <time.h> |
61 | | |
62 | | #ifndef HAVE_STRPTIME |
63 | | char* strptime(const char *buf, const char *fmt, struct tm *tm); |
64 | | #endif |
65 | | |
66 | | #endif /* UTIL_H */ |