1 /* -----------------------------------------------------------------------------
2 * $Id: HsBase.h,v 1.3 2002/02/14 07:31:34 sof Exp $
4 * (c) The University of Glasgow 2001-2002
6 * Definitions for package `core' which are visible in Haskell land.
8 * ---------------------------------------------------------------------------*/
19 #ifdef HAVE_SYS_TYPES_H
20 #include <sys/types.h>
25 #ifdef HAVE_SYS_STAT_H
49 #if defined(HAVE_GETTIMEOFDAY)
50 # ifdef HAVE_SYS_TIME_H
51 # include <sys/time.h>
53 #elif defined(HAVE_GETCLOCK)
54 # ifdef HAVE_SYS_TIMERS_H
56 # include <sys/timers.h>
59 #if defined(HAVE_TIME_H)
62 #ifdef HAVE_SYS_TIMEB_H
63 #include <sys/timeb.h>
68 #ifdef HAVE_SYS_TIMES_H
69 #include <sys/times.h>
78 #if !defined(mingw32_TARGET_OS) && !defined(irix_TARGET_OS)
79 # if defined(HAVE_SYS_RESOURCE_H)
80 # include <sys/resource.h>
85 #include <sys/syscall.h>
86 #define getrusage(a, b) syscall(SYS_GETRUSAGE, a, b)
87 #define HAVE_GETRUSAGE
91 #ifdef HAVE_SYS_WAIT_H
104 #include "timeUtils.h"
111 HsInt systemCmd(HsAddr cmd);
113 /* in inputReady.c */
114 int inputReady(int fd, int msecs, int isSock);
116 /* -----------------------------------------------------------------------------
119 These functions are given as inlines here for when compiling via C,
120 but we also generate static versions into the cbits library for
121 when compiling to native code.
122 -------------------------------------------------------------------------- */
125 #define INLINE extern inline
128 INLINE int __hscore_s_isreg(m) { return S_ISREG(m); }
129 INLINE int __hscore_s_isdir(m) { return S_ISDIR(m); }
130 INLINE int __hscore_s_isfifo(m) { return S_ISFIFO(m); }
131 INLINE int __hscore_s_isblk(m) { return S_ISBLK(m); }
132 INLINE int __hscore_s_ischr(m) { return S_ISCHR(m); }
134 INLINE int __hscore_s_issock(m) { return S_ISSOCK(m); }
137 #ifndef mingw32_TARGET_OS
139 __hscore_sigemptyset( sigset_t *set )
140 { sigemptyset(set); }
144 __hscore_memcpy_dst_off( char *dst, int dst_off, char *src, size_t sz )
145 { return memcpy(dst+dst_off, src, sz); }
148 __hscore_memcpy_src_off( char *dst, char *src, int src_off, size_t sz )
149 { return memcpy(dst, src+src_off, sz); }
152 __hscore_supportsTextMode()
154 #if defined(mingw32_TARGET_OS)
155 return HS_BOOL_FALSE;
194 __hscore_o_wronly( void )
204 __hscore_o_rdwr( void )
214 __hscore_o_append( void )
224 __hscore_o_creat( void )
234 __hscore_o_excl( void )
244 __hscore_o_trunc( void )
254 __hscore_o_noctty( void )
264 __hscore_o_nonblock( void )
274 __hscore_seek_set( void )
280 __hscore_seek_end( void )
286 __hscore_setmode( HsInt fd, HsBool toBin )
289 return setmode(fd,(toBin == HS_BOOL_TRUE) ? _O_BINARY : _O_TEXT);
296 __hscore_PrelHandle_write( HsInt fd, HsBool isSock, HsAddr ptr,
301 return send(fd,ptr + off, sz, 0);
304 return write(fd,ptr + off, sz);
308 __hscore_PrelHandle_read( HsInt fd, HsBool isSock, HsAddr ptr,
313 return recv(fd,ptr + off, sz, 0);
316 return read(fd,ptr + off, sz);
320 #ifdef mingw32_TARGET_OS
322 __hscore_Time_ghcTimezone( void ) { return &_timezone; }
325 __hscore_Time_ghcTzname( void ) { return _tzname; }
329 __hscore_mkdir( HsAddr pathName, HsInt mode )
331 #if defined(mingw32_TARGET_OS)
332 return mkdir(pathName);
334 return mkdir(pathName,mode);
339 __hscore_lstat( HsAddr fname, HsAddr st )
342 return lstat((const char*)fname, (struct stat*)st);
344 return stat((const char*)fname, (struct stat*)st);
348 INLINE HsInt __hscore_path_max() { return PATH_MAX; }
350 INLINE mode_t __hscore_R_OK() { return R_OK; }
351 INLINE mode_t __hscore_W_OK() { return W_OK; }
352 INLINE mode_t __hscore_X_OK() { return X_OK; }
354 INLINE mode_t __hscore_S_IRUSR() { return S_IRUSR; }
355 INLINE mode_t __hscore_S_IWUSR() { return S_IWUSR; }
356 INLINE mode_t __hscore_S_IXUSR() { return S_IXUSR; }
359 __hscore_d_name( struct dirent* d )
361 #ifndef mingw32_TARGET_OS
362 return (HsAddr)(&d->d_name);
364 return (HsAddr)(d->d_name);
369 __hscore_end_of_dir( void )
371 #ifndef mingw32_TARGET_OS
379 __hscore_free_dirent(HsAddr dEnt)
387 __hscore_sizeof_stat( void )
389 return sizeof(struct stat);
392 INLINE time_t __hscore_st_mtime ( struct stat* st ) { return st->st_mtime; }
393 INLINE off_t __hscore_st_size ( struct stat* st ) { return st->st_size; }
394 INLINE mode_t __hscore_st_mode ( struct stat* st ) { return st->st_mode; }
397 INLINE tcflag_t __hscore_lflag( struct termios* ts ) { return ts->c_lflag; }
400 __hscore_poke_lflag( struct termios* ts, tcflag_t t ) { ts->c_lflag = t; }
402 INLINE unsigned char*
403 __hscore_ptr_c_cc( struct termios* ts )
404 { return (unsigned char*) &ts->c_cc; }
408 __hscore_sizeof_termios( void )
410 #ifndef mingw32_TARGET_OS
411 return sizeof(struct termios);
418 __hscore_sizeof_sigset_t( void )
420 #ifndef mingw32_TARGET_OS
421 return sizeof(sigset_t);
428 __hscore_echo( void )
439 __hscore_tcsanow( void )
450 __hscore_icanon( void )
459 INLINE int __hscore_vmin( void )
468 INLINE int __hscore_vtime( void )
477 INLINE int __hscore_sigttou( void )
486 INLINE int __hscore_sig_block( void )
495 INLINE int __hscore_sig_setmask( void )
505 __hscore_f_getfl( void )
515 __hscore_f_setfl( void )