HsUnix.h 4.42 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
/* -----------------------------------------------------------------------------
 *
 * (c) The University of Glasgow 2002
 *
 * Definitions for package `unix' which are visible in Haskell land.
 *
 * ---------------------------------------------------------------------------*/

#ifndef HSUNIX_H
#define HSUNIX_H

ross's avatar
ross committed
12
#include "HsUnixConfig.h"
13
#include "HsFFI.h"
ross's avatar
ross committed
14

15
16
17
18
19
20
21
/* ultra-evil... */
#undef PACKAGE_BUGREPORT
#undef PACKAGE_NAME
#undef PACKAGE_STRING
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION

ross's avatar
ross committed
22
23
24
#include <stdlib.h>
#include <stdio.h>

ross's avatar
ross committed
25
26
27
#ifdef HAVE_STRING_H
#include <string.h>
#endif
28
29
30
31
32
33
34
35
36
#ifdef HAVE_SYS_TIMES_H
#include <sys/times.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
37
38
39
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
40
41
42
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
ross's avatar
ross committed
43
44
45
#ifdef HAVE_TIME_H
#include <time.h>
#endif
46
47
48
49
50
51
52
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_UTIME_H
#include <utime.h>
#endif
#ifdef HAVE_FCNTL_H
53
#include <fcntl.h>
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#endif
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
#ifdef HAVE_SYS_UTSNAME_H
#include <sys/utsname.h>
#endif
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#ifdef HAVE_GRP_H
#include <grp.h>
#endif
ross's avatar
ross committed
70
71
72
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#endif
73

74
75
76
#if defined(HAVE_BSD_LIBUTIL_H)
#include <bsd/libutil.h>
#elif defined(HAVE_LIBUTIL_H)
bos's avatar
bos committed
77
78
79
80
81
82
83
84
85
#include <libutil.h>
#endif
#ifdef HAVE_PTY_H
#include <pty.h>
#endif
#ifdef HAVE_UTMP_H
#include <utmp.h>
#endif

86
87
#include <dlfcn.h>

88
89
90
91
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif

92
93
94
/* in Signals.c */
extern HsInt nocldstop;

95
extern char **environ;
96

97
98
99
100
101
102
int __hsunix_wifexited   (int stat);
int __hsunix_wexitstatus (int stat);
int __hsunix_wifsignaled (int stat);
int __hsunix_wtermsig    (int stat);
int __hsunix_wifstopped  (int stat);
int __hsunix_wstopsig    (int stat);
103

104
#ifdef HAVE_RTLDNEXT
105
void *__hsunix_rtldNext (void);
106
107
#endif

108
#ifdef HAVE_RTLDDEFAULT
109
void *__hsunix_rtldDefault (void);
110
111
#endif

112
113
114
115
116
117
/* O_SYNC doesn't exist on Mac OS X and (at least some versions of) FreeBSD,
fall back to O_FSYNC, which should be the same */
#ifndef O_SYNC
#define O_SYNC O_FSYNC
#endif

118
// lstat is a macro on some platforms, so we need a wrapper:
119
int __hsunix_lstat(const char *path, struct stat *buf);
120
121

// lstat is a macro on some platforms, so we need a wrapper:
122
int __hsunix_mknod(const char *pathname, mode_t mode, dev_t dev);
123

124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifdef HAVE_GETPWENT
// getpwent is a macro on some platforms, so we need a wrapper:
struct passwd *__hsunix_getpwent(void);
#endif

#if HAVE_GETPWNAM_R
// getpwnam_r is a macro on some platforms, so we need a wrapper:
int __hsunix_getpwnam_r(const char *, struct passwd *, char *, size_t,
                        struct passwd **);
#endif

#ifdef HAVE_GETPWUID_R
// getpwuid_r is a macro on some platforms, so we need a wrapper:
int __hsunix_getpwuid_r(uid_t, struct passwd *, char *, size_t,
                        struct passwd **);
#endif

#ifdef HAVE_NANOSLEEP
// nanosleep is a macro on some platforms, so we need a wrapper:
int __hsunix_nanosleep(const struct timespec *, struct timespec *);
#endif

// opendir is a macro on some platforms, so we need a wrapper:
DIR *__hsunix_opendir(const char *);

// time is a macro on some platforms, so we need a wrapper:
time_t __hsunix_time(time_t *);

// times is a macro on some platforms, so we need a wrapper:
clock_t __hsunix_times(struct tms *);

bos's avatar
bos committed
155
156
157
158
159
#ifdef HAVE_PTSNAME
// I cannot figure out how to make the definitions of the following
// functions visible in <stdlib.h> on Linux.  But these definitions
// follow the POSIX specs, and everything links and runs.

160
161
162
char *__hsunix_ptsname(int fd);
int __hsunix_grantpt(int fd);
int __hsunix_unlockpt(int fd);
bos's avatar
bos committed
163
164
165
#endif

// push a SVR4 STREAMS module; do nothing if STREAMS not available
166
int __hsunix_push_module(int fd, const char *module);
bos's avatar
bos committed
167

168
#if !defined(__MINGW32__)
169
int __hscore_mkstemp(char *filetemplate);
deian's avatar
deian committed
170
171
172
#endif

#if HAVE_MKSTEMPS
deian's avatar
deian committed
173
int __hscore_mkstemps(char *filetemplate, int suffixlen);
deian's avatar
deian committed
174
175
176
#endif

#if HAVE_MKDTEMP
deian's avatar
deian committed
177
char *__hscore_mkdtemp(char *filetemplate);
178
179
180
#endif

#if !defined(__MINGW32__) && !defined(irix_HOST_OS)
181
182
int __hscore_getrlimit(int resource, struct rlimit *rlim);
int __hscore_setrlimit(int resource, struct rlimit *rlim);
183
184
#endif

185
int __hsunix_unsetenv(const char *name);
186

187
188
189
190
/* 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).
 */
191
HsInt __hsunix_long_path_size();
192

193
#endif