1 /* -----------------------------------------------------------------------------
2 * $Id: HsBase.h,v 1.1 2002/02/07 11:13:30 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>
75 #if !defined(mingw32_TARGET_OS) && !defined(irix_TARGET_OS)
76 # if defined(HAVE_SYS_RESOURCE_H)
77 # include <sys/resource.h>
82 #include <sys/syscall.h>
83 #define getrusage(a, b) syscall(SYS_GETRUSAGE, a, b)
84 #define HAVE_GETRUSAGE
88 #ifdef HAVE_SYS_WAIT_H
107 HsInt systemCmd(HsAddr cmd);
109 /* in inputReady.c */
110 int inputReady(int fd, int msecs, int isSock);
112 /* -----------------------------------------------------------------------------
115 These functions are given as inlines here for when compiling via C,
116 but we also generate static versions into the cbits library for
117 when compiling to native code.
118 -------------------------------------------------------------------------- */
121 #define INLINE extern inline
124 INLINE int __hscore_s_isreg(m) { return S_ISREG(m); }
125 INLINE int __hscore_s_isdir(m) { return S_ISDIR(m); }
126 INLINE int __hscore_s_isfifo(m) { return S_ISFIFO(m); }
127 INLINE int __hscore_s_isblk(m) { return S_ISBLK(m); }
128 INLINE int __hscore_s_ischr(m) { return S_ISCHR(m); }
130 INLINE int __hscore_s_issock(m) { return S_ISSOCK(m); }
133 #ifndef mingw32_TARGET_OS
135 __hscore_sigemptyset( sigset_t *set )
136 { sigemptyset(set); }
140 __hscore_memcpy_dst_off( char *dst, int dst_off, char *src, size_t sz )
141 { return memcpy(dst+dst_off, src, sz); }
144 __hscore_memcpy_src_off( char *dst, char *src, int src_off, size_t sz )
145 { return memcpy(dst, src+src_off, sz); }
148 __hscore_supportsTextMode()
150 #if defined(mingw32_TARGET_OS)
151 return HS_BOOL_FALSE;
190 __hscore_o_wronly( void )
200 __hscore_o_rdwr( void )
210 __hscore_o_append( void )
220 __hscore_o_creat( void )
230 __hscore_o_excl( void )
240 __hscore_o_trunc( void )
250 __hscore_o_noctty( void )
260 __hscore_o_nonblock( void )
270 __hscore_seek_set( void )
276 __hscore_seek_end( void )
282 __hscore_setmode( HsInt fd, HsBool toBin )
285 return setmode(fd,(toBin == HS_BOOL_TRUE) ? _O_BINARY : _O_TEXT);
292 __hscore_PrelHandle_write( HsInt fd, HsBool isSock, HsAddr ptr,
297 return send(fd,ptr + off, sz, 0);
300 return write(fd,ptr + off, sz);
304 __hscore_PrelHandle_read( HsInt fd, HsBool isSock, HsAddr ptr,
309 return recv(fd,ptr + off, sz, 0);
312 return read(fd,ptr + off, sz);
316 #ifdef mingw32_TARGET_OS
318 __hscore_Time_ghcTimezone( void ) { return &_timezone; }
321 __hscore_Time_ghcTzname( void ) { return _tzname; }
325 __hscore_mkdir( HsAddr pathName, HsInt mode )
327 #if defined(mingw32_TARGET_OS)
328 return mkdir(pathName);
330 return mkdir(pathName,mode);
335 __hscore_lstat( HsAddr fname, HsAddr st )
338 return lstat((const char*)fname, (struct stat*)st);
340 return stat((const char*)fname, (struct stat*)st);
344 INLINE HsInt __hscore_path_max() { return PATH_MAX; }
346 INLINE mode_t __hscore_R_OK() { return R_OK; }
347 INLINE mode_t __hscore_W_OK() { return W_OK; }
348 INLINE mode_t __hscore_X_OK() { return X_OK; }
350 INLINE mode_t __hscore_S_IRUSR() { return S_IRUSR; }
351 INLINE mode_t __hscore_S_IWUSR() { return S_IWUSR; }
352 INLINE mode_t __hscore_S_IXUSR() { return S_IXUSR; }
355 __hscore_d_name( struct dirent* d )
357 #ifndef mingw32_TARGET_OS
358 return (HsAddr)(&d->d_name);
360 return (HsAddr)(d->d_name);
365 __hscore_end_of_dir( void )
367 #ifndef mingw32_TARGET_OS
375 __hscore_free_dirent(HsAddr dEnt)
383 __hscore_sizeof_stat( void )
385 return sizeof(struct stat);
388 INLINE time_t __hscore_st_mtime ( struct stat* st ) { return st->st_mtime; }
389 INLINE off_t __hscore_st_size ( struct stat* st ) { return st->st_size; }
390 INLINE mode_t __hscore_st_mode ( struct stat* st ) { return st->st_mode; }
393 INLINE tcflag_t __hscore_lflag( struct termios* ts ) { return ts->c_lflag; }
396 __hscore_poke_lflag( struct termios* ts, tcflag_t t ) { ts->c_lflag = t; }
398 INLINE unsigned char*
399 __hscore_ptr_c_cc( struct termios* ts )
400 { return (unsigned char*) &ts->c_cc; }
404 __hscore_sizeof_termios( void )
406 #ifndef mingw32_TARGET_OS
407 return sizeof(struct termios);
414 __hscore_sizeof_sigset_t( void )
416 #ifndef mingw32_TARGET_OS
417 return sizeof(sigset_t);
424 __hscore_echo( void )
435 __hscore_tcsanow( void )
446 __hscore_icanon( void )
455 INLINE int __hscore_vmin( void )
464 INLINE int __hscore_vtime( void )
473 INLINE int __hscore_sigttou( void )
482 INLINE int __hscore_sig_block( void )
491 INLINE int __hscore_sig_setmask( void )
501 __hscore_f_getfl( void )
511 __hscore_f_setfl( void )