1 /* -----------------------------------------------------------------------------
2 * $Id: HsBase.h,v 1.13 2002/09/06 14:34:15 simonmar 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 #if defined(HAVE_GETTIMEOFDAY)
51 # ifdef HAVE_SYS_TIME_H
52 # include <sys/time.h>
54 #elif defined(HAVE_GETCLOCK)
55 # ifdef HAVE_SYS_TIMERS_H
57 # include <sys/timers.h>
60 #if defined(HAVE_TIME_H)
63 #ifdef HAVE_SYS_TIMEB_H
64 #include <sys/timeb.h>
69 #ifdef HAVE_SYS_TIMES_H
70 #include <sys/times.h>
72 #if defined(HAVE_WINSOCK_H) && defined(__MINGW32__)
79 #if !defined(mingw32_TARGET_OS) && !defined(irix_TARGET_OS)
80 # if defined(HAVE_SYS_RESOURCE_H)
81 # include <sys/resource.h>
86 #include <sys/syscall.h>
87 #define getrusage(a, b) syscall(SYS_GETRUSAGE, a, b)
88 #define HAVE_GETRUSAGE
92 #ifdef HAVE_SYS_WAIT_H
100 #include "errUtils.h"
102 #if defined(__MINGW32__)
105 #include "timeUtils.h"
112 HsInt systemCmd(HsAddr cmd);
115 HsInt rawSystemCmd(HsAddr cmd);
117 /* in inputReady.c */
118 int inputReady(int fd, int msecs, int isSock);
120 /* -----------------------------------------------------------------------------
121 64-bit operations, defined in longlong.c
122 -------------------------------------------------------------------------- */
124 #ifdef SUPPORT_LONG_LONGS
126 StgInt stg_gtWord64 (StgWord64, StgWord64);
127 StgInt stg_geWord64 (StgWord64, StgWord64);
128 StgInt stg_eqWord64 (StgWord64, StgWord64);
129 StgInt stg_neWord64 (StgWord64, StgWord64);
130 StgInt stg_ltWord64 (StgWord64, StgWord64);
131 StgInt stg_leWord64 (StgWord64, StgWord64);
133 StgInt stg_gtInt64 (StgInt64, StgInt64);
134 StgInt stg_geInt64 (StgInt64, StgInt64);
135 StgInt stg_eqInt64 (StgInt64, StgInt64);
136 StgInt stg_neInt64 (StgInt64, StgInt64);
137 StgInt stg_ltInt64 (StgInt64, StgInt64);
138 StgInt stg_leInt64 (StgInt64, StgInt64);
140 StgWord64 stg_remWord64 (StgWord64, StgWord64);
141 StgWord64 stg_quotWord64 (StgWord64, StgWord64);
143 StgInt64 stg_remInt64 (StgInt64, StgInt64);
144 StgInt64 stg_quotInt64 (StgInt64, StgInt64);
145 StgInt64 stg_negateInt64 (StgInt64);
146 StgInt64 stg_plusInt64 (StgInt64, StgInt64);
147 StgInt64 stg_minusInt64 (StgInt64, StgInt64);
148 StgInt64 stg_timesInt64 (StgInt64, StgInt64);
150 StgWord64 stg_and64 (StgWord64, StgWord64);
151 StgWord64 stg_or64 (StgWord64, StgWord64);
152 StgWord64 stg_xor64 (StgWord64, StgWord64);
153 StgWord64 stg_not64 (StgWord64);
155 StgWord64 stg_uncheckedShiftL64 (StgWord64, StgInt);
156 StgWord64 stg_uncheckedShiftRL64 (StgWord64, StgInt);
157 StgInt64 stg_uncheckedIShiftL64 (StgInt64, StgInt);
158 StgInt64 stg_uncheckedIShiftRL64 (StgInt64, StgInt);
159 StgInt64 stg_uncheckedIShiftRA64 (StgInt64, StgInt);
161 StgInt64 stg_intToInt64 (StgInt);
162 StgInt stg_int64ToInt (StgInt64);
163 StgWord64 stg_int64ToWord64 (StgInt64);
165 StgWord64 stg_wordToWord64 (StgWord);
166 StgWord stg_word64ToWord (StgWord64);
167 StgInt64 stg_word64ToInt64 (StgWord64);
169 StgInt64 stg_integerToInt64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
170 StgWord64 stg_integerToWord64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
172 #endif /* SUPPORT_LONG_LONGS */
174 /* -----------------------------------------------------------------------------
177 These functions are given as inlines here for when compiling via C,
178 but we also generate static versions into the cbits library for
179 when compiling to native code.
180 -------------------------------------------------------------------------- */
183 #define INLINE extern inline
186 INLINE int __hscore_s_isreg(m) { return S_ISREG(m); }
187 INLINE int __hscore_s_isdir(m) { return S_ISDIR(m); }
188 INLINE int __hscore_s_isfifo(m) { return S_ISFIFO(m); }
189 INLINE int __hscore_s_isblk(m) { return S_ISBLK(m); }
190 INLINE int __hscore_s_ischr(m) { return S_ISCHR(m); }
192 INLINE int __hscore_s_issock(m) { return S_ISSOCK(m); }
195 #ifndef mingw32_TARGET_OS
197 __hscore_sigemptyset( sigset_t *set )
198 { return sigemptyset(set); }
201 __hscore_sigfillset( sigset_t *set )
202 { return sigfillset(set); }
205 __hscore_sigaddset( sigset_t * set, int s )
206 { return sigaddset(set,s); }
209 __hscore_sigdelset( sigset_t * set, int s )
210 { return sigdelset(set,s); }
213 __hscore_sigismember( sigset_t * set, int s )
214 { return sigismember(set,s); }
218 __hscore_memcpy_dst_off( char *dst, int dst_off, char *src, size_t sz )
219 { return memcpy(dst+dst_off, src, sz); }
222 __hscore_memcpy_src_off( char *dst, char *src, int src_off, size_t sz )
223 { return memcpy(dst, src+src_off, sz); }
226 __hscore_supportsTextMode()
228 #if defined(mingw32_TARGET_OS)
229 return HS_BOOL_FALSE;
268 __hscore_o_wronly( void )
278 __hscore_o_rdwr( void )
288 __hscore_o_append( void )
298 __hscore_o_creat( void )
308 __hscore_o_excl( void )
318 __hscore_o_trunc( void )
328 __hscore_o_noctty( void )
338 __hscore_o_nonblock( void )
348 __hscore_seek_set( void )
354 __hscore_seek_end( void )
360 __hscore_setmode( HsInt fd, HsBool toBin )
362 #if defined(__MINGW32__)
363 return setmode(fd,(toBin == HS_BOOL_TRUE) ? _O_BINARY : _O_TEXT);
370 __hscore_PrelHandle_write( HsInt fd, HsBool isSock, HsAddr ptr,
373 #if defined(__MINGW32__)
375 return send(fd,ptr + off, sz, 0);
378 return write(fd,ptr + off, sz);
382 __hscore_PrelHandle_read( HsInt fd, HsBool isSock, HsAddr ptr,
385 #if defined(__MINGW32__)
387 return recv(fd,ptr + off, sz, 0);
390 return read(fd,ptr + off, sz);
394 #if defined(__MINGW32__)
396 __hscore_Time_ghcTimezone( void ) { return &_timezone; }
399 __hscore_Time_ghcTzname( void ) { return _tzname; }
403 __hscore_mkdir( HsAddr pathName, HsInt mode )
405 #if defined(__MINGW32__)
406 return mkdir(pathName);
408 return mkdir(pathName,mode);
413 __hscore_lstat( HsAddr fname, HsAddr st )
416 return lstat((const char*)fname, (struct stat*)st);
418 return stat((const char*)fname, (struct stat*)st);
422 INLINE HsInt __hscore_path_max() { return PATH_MAX; }
424 INLINE mode_t __hscore_R_OK() { return R_OK; }
425 INLINE mode_t __hscore_W_OK() { return W_OK; }
426 INLINE mode_t __hscore_X_OK() { return X_OK; }
428 INLINE mode_t __hscore_S_IRUSR() { return S_IRUSR; }
429 INLINE mode_t __hscore_S_IWUSR() { return S_IWUSR; }
430 INLINE mode_t __hscore_S_IXUSR() { return S_IXUSR; }
433 __hscore_d_name( struct dirent* d )
435 #ifndef mingw32_TARGET_OS
436 return (HsAddr)(&d->d_name);
438 return (HsAddr)(d->d_name);
443 __hscore_end_of_dir( void )
445 #ifndef mingw32_TARGET_OS
453 __hscore_free_dirent(HsAddr dEnt)
461 __hscore_sizeof_stat( void )
463 return sizeof(struct stat);
466 INLINE time_t __hscore_st_mtime ( struct stat* st ) { return st->st_mtime; }
467 INLINE off_t __hscore_st_size ( struct stat* st ) { return st->st_size; }
468 INLINE mode_t __hscore_st_mode ( struct stat* st ) { return st->st_mode; }
471 INLINE tcflag_t __hscore_lflag( struct termios* ts ) { return ts->c_lflag; }
474 __hscore_poke_lflag( struct termios* ts, tcflag_t t ) { ts->c_lflag = t; }
476 INLINE unsigned char*
477 __hscore_ptr_c_cc( struct termios* ts )
478 { return (unsigned char*) &ts->c_cc; }
482 __hscore_sizeof_termios( void )
484 #ifndef mingw32_TARGET_OS
485 return sizeof(struct termios);
492 __hscore_sizeof_sigset_t( void )
494 #ifndef mingw32_TARGET_OS
495 return sizeof(sigset_t);
502 __hscore_echo( void )
513 __hscore_tcsanow( void )
524 __hscore_icanon( void )
533 INLINE int __hscore_vmin( void )
542 INLINE int __hscore_vtime( void )
551 INLINE int __hscore_sigttou( void )
560 INLINE int __hscore_sig_block( void )
569 INLINE int __hscore_sig_setmask( void )
579 __hscore_f_getfl( void )
589 __hscore_f_setfl( void )
598 INLINE int __hscore_hs_fileno (FILE *f) { return fileno (f); }
600 #ifndef mingw32_TARGET_OS
601 INLINE int __hsposix_SIGABRT() { return SIGABRT; }
602 INLINE int __hsposix_SIGALRM() { return SIGALRM; }
603 INLINE int __hsposix_SIGBUS() { return SIGBUS; }
604 INLINE int __hsposix_SIGCHLD() { return SIGCHLD; }
605 INLINE int __hsposix_SIGCONT() { return SIGCONT; }
606 INLINE int __hsposix_SIGFPE() { return SIGFPE; }
607 INLINE int __hsposix_SIGHUP() { return SIGHUP; }
608 INLINE int __hsposix_SIGILL() { return SIGILL; }
609 INLINE int __hsposix_SIGINT() { return SIGINT; }
610 INLINE int __hsposix_SIGKILL() { return SIGKILL; }
611 INLINE int __hsposix_SIGPIPE() { return SIGPIPE; }
612 INLINE int __hsposix_SIGQUIT() { return SIGQUIT; }
613 INLINE int __hsposix_SIGSEGV() { return SIGSEGV; }
614 INLINE int __hsposix_SIGSTOP() { return SIGSTOP; }
615 INLINE int __hsposix_SIGTERM() { return SIGTERM; }
616 INLINE int __hsposix_SIGTSTP() { return SIGTSTP; }
617 INLINE int __hsposix_SIGTTIN() { return SIGTTIN; }
618 INLINE int __hsposix_SIGTTOU() { return SIGTTOU; }
619 INLINE int __hsposix_SIGUSR1() { return SIGUSR1; }
620 INLINE int __hsposix_SIGUSR2() { return SIGUSR2; }
621 INLINE int __hsposix_SIGPOLL() { return SIGPOLL; }
622 INLINE int __hsposix_SIGPROF() { return SIGPROF; }
623 INLINE int __hsposix_SIGSYS() { return SIGSYS; }
624 INLINE int __hsposix_SIGTRAP() { return SIGTRAP; }
625 INLINE int __hsposix_SIGURG() { return SIGURG; }
626 INLINE int __hsposix_SIGVTALRM() { return SIGVTALRM; }
627 INLINE int __hsposix_SIGXCPU() { return SIGXCPU; }
628 INLINE int __hsposix_SIGXFSZ() { return SIGXFSZ; }
630 INLINE int __hsposix_SIG_BLOCK() { return SIG_BLOCK; }
631 INLINE int __hsposix_SIG_UNBLOCK() { return SIG_SETMASK; }
632 INLINE int __hsposix_SIG_SETMASK() { return SIG_UNBLOCK; }
633 #endif // mingw32_TARGET_OS