1 /* -----------------------------------------------------------------------------
2 * $Id: HsCore.h,v 1.7 2002/02/05 17:32:27 simonmar Exp $
4 * (c) The University of Glasgow 2001-2002
6 * Definitions for package `core' which are visible in Haskell land.
8 * ---------------------------------------------------------------------------*/
18 #ifdef HAVE_SYS_TYPES_H
19 #include <sys/types.h>
24 #ifdef HAVE_SYS_STAT_H
48 #if defined(HAVE_GETTIMEOFDAY)
49 # ifdef HAVE_SYS_TIME_H
50 # include <sys/time.h>
52 #elif defined(HAVE_GETCLOCK)
53 # ifdef HAVE_SYS_TIMERS_H
55 # include <sys/timers.h>
58 #if defined(HAVE_TIME_H)
61 #ifdef HAVE_SYS_TIMEB_H
62 #include <sys/timeb.h>
67 #ifdef HAVE_SYS_TIMES_H
68 #include <sys/times.h>
74 #if !defined(mingw32_TARGET_OS) && !defined(irix_TARGET_OS)
75 # if defined(HAVE_SYS_RESOURCE_H)
76 # include <sys/resource.h>
81 #include <sys/syscall.h>
82 #define getrusage(a, b) syscall(SYS_GETRUSAGE, a, b)
83 #define HAVE_GETRUSAGE
87 #ifdef HAVE_SYS_WAIT_H
106 HsInt systemCmd(HsAddr cmd);
108 /* in inputReady.c */
109 int inputReady(int fd, int msecs, int isSock);
111 /* -----------------------------------------------------------------------------
114 These functions are given as inlines here for when compiling via C,
115 but we also generate static versions into the cbits library for
116 when compiling to native code.
117 -------------------------------------------------------------------------- */
120 #define INLINE extern inline
123 INLINE int __hscore_s_isreg(m) { return S_ISREG(m); }
124 INLINE int __hscore_s_isdir(m) { return S_ISDIR(m); }
125 INLINE int __hscore_s_isfifo(m) { return S_ISFIFO(m); }
126 INLINE int __hscore_s_isblk(m) { return S_ISBLK(m); }
127 INLINE int __hscore_s_ischr(m) { return S_ISCHR(m); }
129 INLINE int __hscore_s_issock(m) { return S_ISSOCK(m); }
132 #ifndef mingw32_TARGET_OS
134 __hscore_sigemptyset( sigset_t *set )
135 { sigemptyset(set); }
139 __hscore_memcpy_dst_off( char *dst, int dst_off, char *src, size_t sz )
140 { return memcpy(dst+dst_off, src, sz); }
143 __hscore_memcpy_src_off( char *dst, char *src, int src_off, size_t sz )
144 { return memcpy(dst, src+src_off, sz); }
147 __hscore_supportsTextMode()
149 #if defined(mingw32_TARGET_OS)
150 return HS_BOOL_FALSE;
189 __hscore_o_wronly( void )
199 __hscore_o_rdwr( void )
209 __hscore_o_append( void )
219 __hscore_o_creat( void )
229 __hscore_o_excl( void )
239 __hscore_o_trunc( void )
249 __hscore_o_noctty( void )
259 __hscore_o_nonblock( void )
269 __hscore_seek_set( void )
275 __hscore_seek_end( void )
281 __hscore_setmode( HsInt fd, HsBool toBin )
284 return setmode(fd,(toBin == HS_BOOL_TRUE) ? _O_BINARY : _O_TEXT);
291 __hscore_PrelHandle_write( HsInt fd, HsBool isSock, HsAddr ptr,
296 return send(fd,ptr + off, sz, 0);
299 return write(fd,ptr + off, sz);
303 __hscore_PrelHandle_read( HsInt fd, HsBool isSock, HsAddr ptr,
308 return recv(fd,ptr + off, sz, 0);
311 return read(fd,ptr + off, sz);
315 #ifdef mingw32_TARGET_OS
317 __hscore_Time_ghcTimezone( void ) { return &_timezone; }
320 __hscore_Time_ghcTzname( void ) { return _tzname; }
324 __hscore_mkdir( HsAddr pathName, HsInt mode )
326 #if defined(mingw32_TARGET_OS)
327 return mkdir(pathName);
329 return mkdir(pathName,mode);
334 __hscore_lstat( HsAddr fname, HsAddr st )
337 return lstat((const char*)fname, (struct stat*)st);
339 return stat((const char*)fname, (struct stat*)st);
343 INLINE HsInt __hscore_path_max() { return PATH_MAX; }
345 INLINE mode_t __hscore_R_OK() { return R_OK; }
346 INLINE mode_t __hscore_W_OK() { return W_OK; }
347 INLINE mode_t __hscore_X_OK() { return X_OK; }
349 INLINE mode_t __hscore_S_IRUSR() { return S_IRUSR; }
350 INLINE mode_t __hscore_S_IWUSR() { return S_IWUSR; }
351 INLINE mode_t __hscore_S_IXUSR() { return S_IXUSR; }
354 __hscore_d_name( struct dirent* d )
356 #ifndef mingw32_TARGET_OS
357 return (HsAddr)(&d->d_name);
359 return (HsAddr)(d->d_name);
364 __hscore_end_of_dir( void )
366 #ifndef mingw32_TARGET_OS
374 __hscore_free_dirent(HsAddr dEnt)
382 __hscore_sizeof_stat( void )
384 return sizeof(struct stat);
387 INLINE time_t __hscore_st_mtime ( struct stat* st ) { return st->st_mtime; }
388 INLINE off_t __hscore_st_size ( struct stat* st ) { return st->st_size; }
389 INLINE mode_t __hscore_st_mode ( struct stat* st ) { return st->st_mode; }
392 INLINE tcflag_t __hscore_lflag( struct termios* ts ) { return ts->c_lflag; }
395 __hscore_poke_lflag( struct termios* ts, tcflag_t t ) { ts->c_lflag = t; }
397 INLINE unsigned char*
398 __hscore_ptr_c_cc( struct termios* ts )
399 { return (unsigned char*) &ts->c_cc; }
403 __hscore_sizeof_termios( void )
405 #ifndef mingw32_TARGET_OS
406 return sizeof(struct termios);
413 __hscore_sizeof_sigset_t( void )
415 #ifndef mingw32_TARGET_OS
416 return sizeof(sigset_t);
423 __hscore_echo( void )
434 __hscore_tcsanow( void )
445 __hscore_icanon( void )
454 INLINE int __hscore_vmin( void )
463 INLINE int __hscore_vtime( void )
472 INLINE int __hscore_sigttou( void )
481 INLINE int __hscore_sig_block( void )
490 INLINE int __hscore_sig_setmask( void )
500 __hscore_f_getfl( void )
510 __hscore_f_setfl( void )