1 /* -----------------------------------------------------------------------------
2 * $Id: HsBase.h,v 1.2 2002/02/13 10:17:29 simonmar 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
110 HsInt systemCmd(HsAddr cmd);
112 /* in inputReady.c */
113 int inputReady(int fd, int msecs, int isSock);
115 /* -----------------------------------------------------------------------------
118 These functions are given as inlines here for when compiling via C,
119 but we also generate static versions into the cbits library for
120 when compiling to native code.
121 -------------------------------------------------------------------------- */
124 #define INLINE extern inline
127 INLINE int __hscore_s_isreg(m) { return S_ISREG(m); }
128 INLINE int __hscore_s_isdir(m) { return S_ISDIR(m); }
129 INLINE int __hscore_s_isfifo(m) { return S_ISFIFO(m); }
130 INLINE int __hscore_s_isblk(m) { return S_ISBLK(m); }
131 INLINE int __hscore_s_ischr(m) { return S_ISCHR(m); }
133 INLINE int __hscore_s_issock(m) { return S_ISSOCK(m); }
136 #ifndef mingw32_TARGET_OS
138 __hscore_sigemptyset( sigset_t *set )
139 { sigemptyset(set); }
143 __hscore_memcpy_dst_off( char *dst, int dst_off, char *src, size_t sz )
144 { return memcpy(dst+dst_off, src, sz); }
147 __hscore_memcpy_src_off( char *dst, char *src, int src_off, size_t sz )
148 { return memcpy(dst, src+src_off, sz); }
151 __hscore_supportsTextMode()
153 #if defined(mingw32_TARGET_OS)
154 return HS_BOOL_FALSE;
193 __hscore_o_wronly( void )
203 __hscore_o_rdwr( void )
213 __hscore_o_append( void )
223 __hscore_o_creat( void )
233 __hscore_o_excl( void )
243 __hscore_o_trunc( void )
253 __hscore_o_noctty( void )
263 __hscore_o_nonblock( void )
273 __hscore_seek_set( void )
279 __hscore_seek_end( void )
285 __hscore_setmode( HsInt fd, HsBool toBin )
288 return setmode(fd,(toBin == HS_BOOL_TRUE) ? _O_BINARY : _O_TEXT);
295 __hscore_PrelHandle_write( HsInt fd, HsBool isSock, HsAddr ptr,
300 return send(fd,ptr + off, sz, 0);
303 return write(fd,ptr + off, sz);
307 __hscore_PrelHandle_read( HsInt fd, HsBool isSock, HsAddr ptr,
312 return recv(fd,ptr + off, sz, 0);
315 return read(fd,ptr + off, sz);
319 #ifdef mingw32_TARGET_OS
321 __hscore_Time_ghcTimezone( void ) { return &_timezone; }
324 __hscore_Time_ghcTzname( void ) { return _tzname; }
328 __hscore_mkdir( HsAddr pathName, HsInt mode )
330 #if defined(mingw32_TARGET_OS)
331 return mkdir(pathName);
333 return mkdir(pathName,mode);
338 __hscore_lstat( HsAddr fname, HsAddr st )
341 return lstat((const char*)fname, (struct stat*)st);
343 return stat((const char*)fname, (struct stat*)st);
347 INLINE HsInt __hscore_path_max() { return PATH_MAX; }
349 INLINE mode_t __hscore_R_OK() { return R_OK; }
350 INLINE mode_t __hscore_W_OK() { return W_OK; }
351 INLINE mode_t __hscore_X_OK() { return X_OK; }
353 INLINE mode_t __hscore_S_IRUSR() { return S_IRUSR; }
354 INLINE mode_t __hscore_S_IWUSR() { return S_IWUSR; }
355 INLINE mode_t __hscore_S_IXUSR() { return S_IXUSR; }
358 __hscore_d_name( struct dirent* d )
360 #ifndef mingw32_TARGET_OS
361 return (HsAddr)(&d->d_name);
363 return (HsAddr)(d->d_name);
368 __hscore_end_of_dir( void )
370 #ifndef mingw32_TARGET_OS
378 __hscore_free_dirent(HsAddr dEnt)
386 __hscore_sizeof_stat( void )
388 return sizeof(struct stat);
391 INLINE time_t __hscore_st_mtime ( struct stat* st ) { return st->st_mtime; }
392 INLINE off_t __hscore_st_size ( struct stat* st ) { return st->st_size; }
393 INLINE mode_t __hscore_st_mode ( struct stat* st ) { return st->st_mode; }
396 INLINE tcflag_t __hscore_lflag( struct termios* ts ) { return ts->c_lflag; }
399 __hscore_poke_lflag( struct termios* ts, tcflag_t t ) { ts->c_lflag = t; }
401 INLINE unsigned char*
402 __hscore_ptr_c_cc( struct termios* ts )
403 { return (unsigned char*) &ts->c_cc; }
407 __hscore_sizeof_termios( void )
409 #ifndef mingw32_TARGET_OS
410 return sizeof(struct termios);
417 __hscore_sizeof_sigset_t( void )
419 #ifndef mingw32_TARGET_OS
420 return sizeof(sigset_t);
427 __hscore_echo( void )
438 __hscore_tcsanow( void )
449 __hscore_icanon( void )
458 INLINE int __hscore_vmin( void )
467 INLINE int __hscore_vtime( void )
476 INLINE int __hscore_sigttou( void )
485 INLINE int __hscore_sig_block( void )
494 INLINE int __hscore_sig_setmask( void )
504 __hscore_f_getfl( void )
514 __hscore_f_setfl( void )