1 /* -----------------------------------------------------------------------------
2 * $Id: HsBase.h,v 1.15 2002/10/03 12:43:50 panne Exp $
4 * (c) The University of Glasgow 2001-2002
6 * Definitions for package `core' which are visible in Haskell land.
8 * ---------------------------------------------------------------------------*/
20 #ifdef HAVE_SYS_TYPES_H
21 #include <sys/types.h>
26 #ifdef HAVE_SYS_STAT_H
50 #ifdef HAVE_SYS_UTSNAME_H
51 #include <sys/utsname.h>
53 #if defined(HAVE_GETTIMEOFDAY)
54 # ifdef HAVE_SYS_TIME_H
55 # include <sys/time.h>
57 #elif defined(HAVE_GETCLOCK)
58 # ifdef HAVE_SYS_TIMERS_H
60 # include <sys/timers.h>
63 #if defined(HAVE_TIME_H)
66 #ifdef HAVE_SYS_TIMEB_H
67 #include <sys/timeb.h>
72 #ifdef HAVE_SYS_TIMES_H
73 #include <sys/times.h>
75 #if defined(HAVE_WINSOCK_H) && defined(__MINGW32__)
82 #if !defined(mingw32_TARGET_OS) && !defined(irix_TARGET_OS)
83 # if defined(HAVE_SYS_RESOURCE_H)
84 # include <sys/resource.h>
89 #include <sys/syscall.h>
90 #define getrusage(a, b) syscall(SYS_GETRUSAGE, a, b)
91 #define HAVE_GETRUSAGE
95 #ifdef HAVE_SYS_WAIT_H
101 #include "lockFile.h"
102 #include "dirUtils.h"
104 #if defined(__MINGW32__)
107 #include "timeUtils.h"
114 HsInt systemCmd(HsAddr cmd);
117 HsInt rawSystemCmd(HsAddr cmd);
119 /* in inputReady.c */
120 int inputReady(int fd, int msecs, int isSock);
122 /* -----------------------------------------------------------------------------
123 64-bit operations, defined in longlong.c
124 -------------------------------------------------------------------------- */
126 #ifdef SUPPORT_LONG_LONGS
128 StgInt stg_gtWord64 (StgWord64, StgWord64);
129 StgInt stg_geWord64 (StgWord64, StgWord64);
130 StgInt stg_eqWord64 (StgWord64, StgWord64);
131 StgInt stg_neWord64 (StgWord64, StgWord64);
132 StgInt stg_ltWord64 (StgWord64, StgWord64);
133 StgInt stg_leWord64 (StgWord64, StgWord64);
135 StgInt stg_gtInt64 (StgInt64, StgInt64);
136 StgInt stg_geInt64 (StgInt64, StgInt64);
137 StgInt stg_eqInt64 (StgInt64, StgInt64);
138 StgInt stg_neInt64 (StgInt64, StgInt64);
139 StgInt stg_ltInt64 (StgInt64, StgInt64);
140 StgInt stg_leInt64 (StgInt64, StgInt64);
142 StgWord64 stg_remWord64 (StgWord64, StgWord64);
143 StgWord64 stg_quotWord64 (StgWord64, StgWord64);
145 StgInt64 stg_remInt64 (StgInt64, StgInt64);
146 StgInt64 stg_quotInt64 (StgInt64, StgInt64);
147 StgInt64 stg_negateInt64 (StgInt64);
148 StgInt64 stg_plusInt64 (StgInt64, StgInt64);
149 StgInt64 stg_minusInt64 (StgInt64, StgInt64);
150 StgInt64 stg_timesInt64 (StgInt64, StgInt64);
152 StgWord64 stg_and64 (StgWord64, StgWord64);
153 StgWord64 stg_or64 (StgWord64, StgWord64);
154 StgWord64 stg_xor64 (StgWord64, StgWord64);
155 StgWord64 stg_not64 (StgWord64);
157 StgWord64 stg_uncheckedShiftL64 (StgWord64, StgInt);
158 StgWord64 stg_uncheckedShiftRL64 (StgWord64, StgInt);
159 StgInt64 stg_uncheckedIShiftL64 (StgInt64, StgInt);
160 StgInt64 stg_uncheckedIShiftRL64 (StgInt64, StgInt);
161 StgInt64 stg_uncheckedIShiftRA64 (StgInt64, StgInt);
163 StgInt64 stg_intToInt64 (StgInt);
164 StgInt stg_int64ToInt (StgInt64);
165 StgWord64 stg_int64ToWord64 (StgInt64);
167 StgWord64 stg_wordToWord64 (StgWord);
168 StgWord stg_word64ToWord (StgWord64);
169 StgInt64 stg_word64ToInt64 (StgWord64);
171 StgInt64 stg_integerToInt64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
172 StgWord64 stg_integerToWord64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
174 #endif /* SUPPORT_LONG_LONGS */
176 /* -----------------------------------------------------------------------------
179 These functions are given as inlines here for when compiling via C,
180 but we also generate static versions into the cbits library for
181 when compiling to native code.
182 -------------------------------------------------------------------------- */
185 #define INLINE extern inline
188 INLINE int __hscore_s_isreg(m) { return S_ISREG(m); }
189 INLINE int __hscore_s_isdir(m) { return S_ISDIR(m); }
190 INLINE int __hscore_s_isfifo(m) { return S_ISFIFO(m); }
191 INLINE int __hscore_s_isblk(m) { return S_ISBLK(m); }
192 INLINE int __hscore_s_ischr(m) { return S_ISCHR(m); }
194 INLINE int __hscore_s_issock(m) { return S_ISSOCK(m); }
197 #ifndef mingw32_TARGET_OS
199 __hscore_sigemptyset( sigset_t *set )
200 { return sigemptyset(set); }
203 __hscore_sigfillset( sigset_t *set )
204 { return sigfillset(set); }
207 __hscore_sigaddset( sigset_t * set, int s )
208 { return sigaddset(set,s); }
211 __hscore_sigdelset( sigset_t * set, int s )
212 { return sigdelset(set,s); }
215 __hscore_sigismember( sigset_t * set, int s )
216 { return sigismember(set,s); }
220 __hscore_memcpy_dst_off( char *dst, int dst_off, char *src, size_t sz )
221 { return memcpy(dst+dst_off, src, sz); }
224 __hscore_memcpy_src_off( char *dst, char *src, int src_off, size_t sz )
225 { return memcpy(dst, src+src_off, sz); }
228 __hscore_supportsTextMode()
230 #if defined(mingw32_TARGET_OS)
231 return HS_BOOL_FALSE;
270 __hscore_o_wronly( void )
280 __hscore_o_rdwr( void )
290 __hscore_o_append( void )
300 __hscore_o_creat( void )
310 __hscore_o_excl( void )
320 __hscore_o_trunc( void )
330 __hscore_o_noctty( void )
340 __hscore_o_nonblock( void )
350 __hscore_seek_set( void )
356 __hscore_seek_end( void )
362 __hscore_setmode( HsInt fd, HsBool toBin )
364 #if defined(__MINGW32__)
365 return setmode(fd,(toBin == HS_BOOL_TRUE) ? _O_BINARY : _O_TEXT);
372 __hscore_PrelHandle_write( HsInt fd, HsBool isSock, HsAddr ptr,
375 #if defined(__MINGW32__)
377 return send(fd,ptr + off, sz, 0);
380 return write(fd,ptr + off, sz);
384 __hscore_PrelHandle_read( HsInt fd, HsBool isSock, HsAddr ptr,
387 #if defined(__MINGW32__)
389 return recv(fd,ptr + off, sz, 0);
392 return read(fd,ptr + off, sz);
396 #if defined(__MINGW32__)
398 __hscore_Time_ghcTimezone( void ) { return &_timezone; }
401 __hscore_Time_ghcTzname( void ) { return _tzname; }
405 __hscore_mkdir( HsAddr pathName, HsInt mode )
407 #if defined(__MINGW32__)
408 return mkdir(pathName);
410 return mkdir(pathName,mode);
415 __hscore_lstat( HsAddr fname, HsAddr st )
418 return lstat((const char*)fname, (struct stat*)st);
420 return stat((const char*)fname, (struct stat*)st);
424 INLINE HsInt __hscore_path_max() { return PATH_MAX; }
426 INLINE mode_t __hscore_R_OK() { return R_OK; }
427 INLINE mode_t __hscore_W_OK() { return W_OK; }
428 INLINE mode_t __hscore_X_OK() { return X_OK; }
430 INLINE mode_t __hscore_S_IRUSR() { return S_IRUSR; }
431 INLINE mode_t __hscore_S_IWUSR() { return S_IWUSR; }
432 INLINE mode_t __hscore_S_IXUSR() { return S_IXUSR; }
435 __hscore_d_name( struct dirent* d )
437 #ifndef mingw32_TARGET_OS
438 return (HsAddr)(&d->d_name);
440 return (HsAddr)(d->d_name);
445 __hscore_end_of_dir( void )
447 #ifndef mingw32_TARGET_OS
455 __hscore_free_dirent(HsAddr dEnt)
463 __hscore_sizeof_stat( void )
465 return sizeof(struct stat);
468 INLINE time_t __hscore_st_mtime ( struct stat* st ) { return st->st_mtime; }
469 INLINE off_t __hscore_st_size ( struct stat* st ) { return st->st_size; }
470 INLINE mode_t __hscore_st_mode ( struct stat* st ) { return st->st_mode; }
473 INLINE tcflag_t __hscore_lflag( struct termios* ts ) { return ts->c_lflag; }
476 __hscore_poke_lflag( struct termios* ts, tcflag_t t ) { ts->c_lflag = t; }
478 INLINE unsigned char*
479 __hscore_ptr_c_cc( struct termios* ts )
480 { return (unsigned char*) &ts->c_cc; }
484 __hscore_sizeof_termios( void )
486 #ifndef mingw32_TARGET_OS
487 return sizeof(struct termios);
494 __hscore_sizeof_sigset_t( void )
496 #ifndef mingw32_TARGET_OS
497 return sizeof(sigset_t);
504 __hscore_echo( void )
515 __hscore_tcsanow( void )
526 __hscore_icanon( void )
535 INLINE int __hscore_vmin( void )
544 INLINE int __hscore_vtime( void )
553 INLINE int __hscore_sigttou( void )
562 INLINE int __hscore_sig_block( void )
571 INLINE int __hscore_sig_setmask( void )
581 __hscore_f_getfl( void )
591 __hscore_f_setfl( void )
600 INLINE int __hscore_hs_fileno (FILE *f) { return fileno (f); }
602 #ifndef mingw32_TARGET_OS
603 INLINE int __hsposix_SIGABRT() { return SIGABRT; }
604 INLINE int __hsposix_SIGALRM() { return SIGALRM; }
605 INLINE int __hsposix_SIGBUS() { return SIGBUS; }
606 INLINE int __hsposix_SIGCHLD() { return SIGCHLD; }
607 INLINE int __hsposix_SIGCONT() { return SIGCONT; }
608 INLINE int __hsposix_SIGFPE() { return SIGFPE; }
609 INLINE int __hsposix_SIGHUP() { return SIGHUP; }
610 INLINE int __hsposix_SIGILL() { return SIGILL; }
611 INLINE int __hsposix_SIGINT() { return SIGINT; }
612 INLINE int __hsposix_SIGKILL() { return SIGKILL; }
613 INLINE int __hsposix_SIGPIPE() { return SIGPIPE; }
614 INLINE int __hsposix_SIGQUIT() { return SIGQUIT; }
615 INLINE int __hsposix_SIGSEGV() { return SIGSEGV; }
616 INLINE int __hsposix_SIGSTOP() { return SIGSTOP; }
617 INLINE int __hsposix_SIGTERM() { return SIGTERM; }
618 INLINE int __hsposix_SIGTSTP() { return SIGTSTP; }
619 INLINE int __hsposix_SIGTTIN() { return SIGTTIN; }
620 INLINE int __hsposix_SIGTTOU() { return SIGTTOU; }
621 INLINE int __hsposix_SIGUSR1() { return SIGUSR1; }
622 INLINE int __hsposix_SIGUSR2() { return SIGUSR2; }
623 INLINE int __hsposix_SIGPOLL() { return SIGPOLL; }
624 INLINE int __hsposix_SIGPROF() { return SIGPROF; }
625 INLINE int __hsposix_SIGSYS() { return SIGSYS; }
626 INLINE int __hsposix_SIGTRAP() { return SIGTRAP; }
627 INLINE int __hsposix_SIGURG() { return SIGURG; }
628 INLINE int __hsposix_SIGVTALRM() { return SIGVTALRM; }
629 INLINE int __hsposix_SIGXCPU() { return SIGXCPU; }
630 INLINE int __hsposix_SIGXFSZ() { return SIGXFSZ; }
632 INLINE int __hsposix_SIG_BLOCK() { return SIG_BLOCK; }
633 INLINE int __hsposix_SIG_UNBLOCK() { return SIG_SETMASK; }
634 INLINE int __hsposix_SIG_SETMASK() { return SIG_UNBLOCK; }
635 #endif // mingw32_TARGET_OS