1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/* -----------------------------------------------------------------------------
*
* (c) The University of Glasgow 2002
*
* Definitions for package `unix' which are visible in Haskell land.
*
* ---------------------------------------------------------------------------*/
#include "HsUnix.h"
#ifdef HAVE_RTLDNEXT
void *__hsunix_rtldNext (void) {return RTLD_NEXT;}
#endif
#ifdef HAVE_RTLDDEFAULT
void *__hsunix_rtldDefault (void) {return RTLD_DEFAULT;}
#endif
#if HAVE_GETPWNAM_R
// getpwnam_r is a macro on some platforms, so we need a wrapper:
int __hsunix_getpwnam_r(const char *name, struct passwd *pw, char *buffer,
size_t buflen, struct passwd **result)
{
return getpwnam_r(name, pw, buffer, buflen, result);
}
#endif
#ifdef HAVE_GETPWUID_R
// getpwuid_r is a macro on some platforms, so we need a wrapper:
int __hsunix_getpwuid_r(uid_t uid, struct passwd *pw, char *buffer,
size_t buflen, struct passwd **result)
{
return getpwuid_r(uid, pw, buffer, buflen, result);
}
#endif
#ifdef HAVE_PTSNAME
// On Linux (and others), <stdlib.h> needs to be included while
// `_XOPEN_SOURCE` is already defined. However, GHCs before GHC 8.0
// didn't do that yet for CApiFFI, so we need this workaround here.
char *__hsunix_ptsname(int fd)
{
return ptsname(fd);
}
int __hsunix_grantpt(int fd)
{
return grantpt(fd);
}
int __hsunix_unlockpt(int fd)
{
return unlockpt(fd);
}
#endif
// push a SVR4 STREAMS module; do nothing if STREAMS not available
int __hsunix_push_module(int fd, const char *module)
{
#if defined(I_PUSH) && !defined(HAVE_DEV_PTC)
return ioctl(fd, I_PUSH, module);
#else
return 0;
#endif
}
int __hscore_mkstemp(char *filetemplate) {
return (mkstemp(filetemplate));
}
#if HAVE_MKSTEMPS
int __hscore_mkstemps(char *filetemplate, int suffixlen) {
return (mkstemps(filetemplate, suffixlen));
}
#endif
#if HAVE_MKDTEMP
char *__hscore_mkdtemp(char *filetemplate) {
return (mkdtemp(filetemplate));
}
#endif
#if !defined(irix_HOST_OS)
int __hscore_getrlimit(int resource, struct rlimit *rlim) {
return (getrlimit(resource, rlim));
}
int __hscore_setrlimit(int resource, struct rlimit *rlim) {
return (setrlimit(resource, rlim));
}
#endif
#ifdef HAVE_UNSETENV
int __hsunix_unsetenv(const char *name)
{
#ifdef UNSETENV_RETURNS_VOID
unsetenv(name);
return 0;
#else
return unsetenv(name);
#endif
}
#endif
/* A size that will contain many path names, but not necessarily all
* (PATH_MAX is not defined on systems with unlimited path length,
* e.g. the Hurd).
*/
HsInt __hsunix_long_path_size(void) {
#ifdef PATH_MAX
return PATH_MAX;
#else
return 4096;
#endif
}
|