Import Upstream version 20180207
[hcoop/debian/mlton.git] / runtime / platform / linux.h
1 #include <inttypes.h>
2 #include <stdint.h>
3 #ifdef __UCLIBC__
4 #include <fpu_control.h>
5 #else
6 #include <fenv.h>
7 #endif
8
9 #include <unistd.h>
10
11 #include <dirent.h>
12 #include <fcntl.h>
13 #include <grp.h>
14 #include <netdb.h>
15 #include <netinet/in.h>
16 #include <netinet/tcp.h>
17 #include <poll.h>
18 #include <pwd.h>
19 #include <sys/ioctl.h>
20 #include <sys/mman.h>
21 #include <sys/resource.h>
22 #include <sys/socket.h>
23 #include <sys/stat.h>
24 #include <sys/time.h>
25 #include <sys/times.h>
26 #include <sys/un.h>
27 #include <sys/utsname.h>
28 #include <sys/wait.h>
29 #include <sys/sysinfo.h>
30 #include <syslog.h>
31 #include <termios.h>
32 #include <utime.h>
33
34 #ifdef __UCLIBC__
35 #define HAS_FEROUND FALSE
36 #else
37 #define HAS_FEROUND TRUE
38 #endif
39 #define HAS_MSG_DONTWAIT TRUE
40 #define HAS_REMAP TRUE
41 #define HAS_SIGALTSTACK TRUE
42 #if (defined (__hppa__))
43 #define NEEDS_SIGALTSTACK_EXEC TRUE
44 #else
45 #define NEEDS_SIGALTSTACK_EXEC FALSE
46 #endif
47 #define HAS_SPAWN FALSE
48 #define HAS_TIME_PROFILING TRUE
49
50 #define MLton_Platform_OS_host "linux"
51
52 // environ is already defined if _GNU_SOURCE is.
53 #if !defined(_GNU_SOURCE) && !defined(__ANDROID__)
54 extern char **environ; /* for Posix_ProcEnv_environ */
55 #endif
56
57 /* The following is compatibility code with older glibc and kernel
58 versions. */
59
60 #ifndef __suseconds_t_defined
61 #include <linux/types.h>
62 typedef __kernel_suseconds_t suseconds_t;
63 #define __suseconds_t_defined
64 #endif
65
66 #ifdef __GLIBC__
67 #if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 1
68 typedef unsigned long int nfds_t;
69 #endif
70 #endif
71
72 #ifdef __ANDROID__
73 /* Work around buggy android system libraries */
74 #undef PRIxPTR
75 #define PRIxPTR "x"
76
77 /* Needed for fetching program counter */
78 #include <platform/android_ucontext.h>
79
80 /* Android is missing these methods: */
81 #undef tcdrain
82 #undef ctermid
83 #define tcdrain MLton_tcdrain
84 #define ctermid MLton_ctermid
85
86 static inline int tcdrain(int fd) {
87 return ioctl(fd, TCSBRK, 1);
88 }
89
90 static inline char* ctermid(char* x) {
91 static char buf[] = "/dev/tty";
92 if (x) {
93 strcpy(x, buf);
94 return x;
95 } else {
96 return &buf[0];
97 }
98 }
99
100 #endif
101
102 #ifndef SO_ACCEPTCONN
103 #define SO_ACCEPTCONN 30
104 #endif
105
106 #ifdef __UCLIBC__
107 #define FE_DOWNWARD _FPU_RC_DOWN
108 #define FE_TONEAREST _FPU_RC_NEAREST
109 #define FE_TOWARDZERO _FPU_RC_ZERO
110 #define FE_UPWARD _FPU_RC_UP
111 #endif