1 /* -----------------------------------------------------------------------------
2 * $Id: HsBase.h,v 1.14 2002/09/25 15:24:07 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
101 #if defined(__MINGW32__)
104 #include "timeUtils.h"
111 HsInt systemCmd(HsAddr cmd);
114 HsInt rawSystemCmd(HsAddr cmd);
116 /* in inputReady.c */
117 int inputReady(int fd, int msecs, int isSock);
119 /* -----------------------------------------------------------------------------
120 64-bit operations, defined in longlong.c
121 -------------------------------------------------------------------------- */
123 #ifdef SUPPORT_LONG_LONGS
125 StgInt stg_gtWord64 (StgWord64, StgWord64);
126 StgInt stg_geWord64 (StgWord64, StgWord64);
127 StgInt stg_eqWord64 (StgWord64, StgWord64);
128 StgInt stg_neWord64 (StgWord64, StgWord64);
129 StgInt stg_ltWord64 (StgWord64, StgWord64);
130 StgInt stg_leWord64 (StgWord64, StgWord64);
132 StgInt stg_gtInt64 (StgInt64, StgInt64);
133 StgInt stg_geInt64 (StgInt64, StgInt64);
134 StgInt stg_eqInt64 (StgInt64, StgInt64);
135 StgInt stg_neInt64 (StgInt64, StgInt64);
136 StgInt stg_ltInt64 (StgInt64, StgInt64);
137 StgInt stg_leInt64 (StgInt64, StgInt64);
139 StgWord64 stg_remWord64 (StgWord64, StgWord64);
140 StgWord64 stg_quotWord64 (StgWord64, StgWord64);
142 StgInt64 stg_remInt64 (StgInt64, StgInt64);
143 StgInt64 stg_quotInt64 (StgInt64, StgInt64);
144 StgInt64 stg_negateInt64 (StgInt64);
145 StgInt64 stg_plusInt64 (StgInt64, StgInt64);
146 StgInt64 stg_minusInt64 (StgInt64, StgInt64);
147 StgInt64 stg_timesInt64 (StgInt64, StgInt64);
149 StgWord64 stg_and64 (StgWord64, StgWord64);
150 StgWord64 stg_or64 (StgWord64, StgWord64);
151 StgWord64 stg_xor64 (StgWord64, StgWord64);
152 StgWord64 stg_not64 (StgWord64);
154 StgWord64 stg_uncheckedShiftL64 (StgWord64, StgInt);
155 StgWord64 stg_uncheckedShiftRL64 (StgWord64, StgInt);
156 StgInt64 stg_uncheckedIShiftL64 (StgInt64, StgInt);
157 StgInt64 stg_uncheckedIShiftRL64 (StgInt64, StgInt);
158 StgInt64 stg_uncheckedIShiftRA64 (StgInt64, StgInt);
160 StgInt64 stg_intToInt64 (StgInt);
161 StgInt stg_int64ToInt (StgInt64);
162 StgWord64 stg_int64ToWord64 (StgInt64);
164 StgWord64 stg_wordToWord64 (StgWord);
165 StgWord stg_word64ToWord (StgWord64);
166 StgInt64 stg_word64ToInt64 (StgWord64);
168 StgInt64 stg_integerToInt64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
169 StgWord64 stg_integerToWord64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
171 #endif /* SUPPORT_LONG_LONGS */
173 /* -----------------------------------------------------------------------------
176 These functions are given as inlines here for when compiling via C,
177 but we also generate static versions into the cbits library for
178 when compiling to native code.
179 -------------------------------------------------------------------------- */
182 #define INLINE extern inline
185 INLINE int __hscore_s_isreg(m) { return S_ISREG(m); }
186 INLINE int __hscore_s_isdir(m) { return S_ISDIR(m); }
187 INLINE int __hscore_s_isfifo(m) { return S_ISFIFO(m); }
188 INLINE int __hscore_s_isblk(m) { return S_ISBLK(m); }
189 INLINE int __hscore_s_ischr(m) { return S_ISCHR(m); }
191 INLINE int __hscore_s_issock(m) { return S_ISSOCK(m); }
194 #ifndef mingw32_TARGET_OS
196 __hscore_sigemptyset( sigset_t *set )
197 { return sigemptyset(set); }
200 __hscore_sigfillset( sigset_t *set )
201 { return sigfillset(set); }
204 __hscore_sigaddset( sigset_t * set, int s )
205 { return sigaddset(set,s); }
208 __hscore_sigdelset( sigset_t * set, int s )
209 { return sigdelset(set,s); }
212 __hscore_sigismember( sigset_t * set, int s )
213 { return sigismember(set,s); }
217 __hscore_memcpy_dst_off( char *dst, int dst_off, char *src, size_t sz )
218 { return memcpy(dst+dst_off, src, sz); }
221 __hscore_memcpy_src_off( char *dst, char *src, int src_off, size_t sz )
222 { return memcpy(dst, src+src_off, sz); }
225 __hscore_supportsTextMode()
227 #if defined(mingw32_TARGET_OS)
228 return HS_BOOL_FALSE;
267 __hscore_o_wronly( void )
277 __hscore_o_rdwr( void )
287 __hscore_o_append( void )
297 __hscore_o_creat( void )
307 __hscore_o_excl( void )
317 __hscore_o_trunc( void )
327 __hscore_o_noctty( void )
337 __hscore_o_nonblock( void )
347 __hscore_seek_set( void )
353 __hscore_seek_end( void )
359 __hscore_setmode( HsInt fd, HsBool toBin )
361 #if defined(__MINGW32__)
362 return setmode(fd,(toBin == HS_BOOL_TRUE) ? _O_BINARY : _O_TEXT);
369 __hscore_PrelHandle_write( HsInt fd, HsBool isSock, HsAddr ptr,
372 #if defined(__MINGW32__)
374 return send(fd,ptr + off, sz, 0);
377 return write(fd,ptr + off, sz);
381 __hscore_PrelHandle_read( HsInt fd, HsBool isSock, HsAddr ptr,
384 #if defined(__MINGW32__)
386 return recv(fd,ptr + off, sz, 0);
389 return read(fd,ptr + off, sz);
393 #if defined(__MINGW32__)
395 __hscore_Time_ghcTimezone( void ) { return &_timezone; }
398 __hscore_Time_ghcTzname( void ) { return _tzname; }
402 __hscore_mkdir( HsAddr pathName, HsInt mode )
404 #if defined(__MINGW32__)
405 return mkdir(pathName);
407 return mkdir(pathName,mode);
412 __hscore_lstat( HsAddr fname, HsAddr st )
415 return lstat((const char*)fname, (struct stat*)st);
417 return stat((const char*)fname, (struct stat*)st);
421 INLINE HsInt __hscore_path_max() { return PATH_MAX; }
423 INLINE mode_t __hscore_R_OK() { return R_OK; }
424 INLINE mode_t __hscore_W_OK() { return W_OK; }
425 INLINE mode_t __hscore_X_OK() { return X_OK; }
427 INLINE mode_t __hscore_S_IRUSR() { return S_IRUSR; }
428 INLINE mode_t __hscore_S_IWUSR() { return S_IWUSR; }
429 INLINE mode_t __hscore_S_IXUSR() { return S_IXUSR; }
432 __hscore_d_name( struct dirent* d )
434 #ifndef mingw32_TARGET_OS
435 return (HsAddr)(&d->d_name);
437 return (HsAddr)(d->d_name);
442 __hscore_end_of_dir( void )
444 #ifndef mingw32_TARGET_OS
452 __hscore_free_dirent(HsAddr dEnt)
460 __hscore_sizeof_stat( void )
462 return sizeof(struct stat);
465 INLINE time_t __hscore_st_mtime ( struct stat* st ) { return st->st_mtime; }
466 INLINE off_t __hscore_st_size ( struct stat* st ) { return st->st_size; }
467 INLINE mode_t __hscore_st_mode ( struct stat* st ) { return st->st_mode; }
470 INLINE tcflag_t __hscore_lflag( struct termios* ts ) { return ts->c_lflag; }
473 __hscore_poke_lflag( struct termios* ts, tcflag_t t ) { ts->c_lflag = t; }
475 INLINE unsigned char*
476 __hscore_ptr_c_cc( struct termios* ts )
477 { return (unsigned char*) &ts->c_cc; }
481 __hscore_sizeof_termios( void )
483 #ifndef mingw32_TARGET_OS
484 return sizeof(struct termios);
491 __hscore_sizeof_sigset_t( void )
493 #ifndef mingw32_TARGET_OS
494 return sizeof(sigset_t);
501 __hscore_echo( void )
512 __hscore_tcsanow( void )
523 __hscore_icanon( void )
532 INLINE int __hscore_vmin( void )
541 INLINE int __hscore_vtime( void )
550 INLINE int __hscore_sigttou( void )
559 INLINE int __hscore_sig_block( void )
568 INLINE int __hscore_sig_setmask( void )
578 __hscore_f_getfl( void )
588 __hscore_f_setfl( void )
597 INLINE int __hscore_hs_fileno (FILE *f) { return fileno (f); }
599 #ifndef mingw32_TARGET_OS
600 INLINE int __hsposix_SIGABRT() { return SIGABRT; }
601 INLINE int __hsposix_SIGALRM() { return SIGALRM; }
602 INLINE int __hsposix_SIGBUS() { return SIGBUS; }
603 INLINE int __hsposix_SIGCHLD() { return SIGCHLD; }
604 INLINE int __hsposix_SIGCONT() { return SIGCONT; }
605 INLINE int __hsposix_SIGFPE() { return SIGFPE; }
606 INLINE int __hsposix_SIGHUP() { return SIGHUP; }
607 INLINE int __hsposix_SIGILL() { return SIGILL; }
608 INLINE int __hsposix_SIGINT() { return SIGINT; }
609 INLINE int __hsposix_SIGKILL() { return SIGKILL; }
610 INLINE int __hsposix_SIGPIPE() { return SIGPIPE; }
611 INLINE int __hsposix_SIGQUIT() { return SIGQUIT; }
612 INLINE int __hsposix_SIGSEGV() { return SIGSEGV; }
613 INLINE int __hsposix_SIGSTOP() { return SIGSTOP; }
614 INLINE int __hsposix_SIGTERM() { return SIGTERM; }
615 INLINE int __hsposix_SIGTSTP() { return SIGTSTP; }
616 INLINE int __hsposix_SIGTTIN() { return SIGTTIN; }
617 INLINE int __hsposix_SIGTTOU() { return SIGTTOU; }
618 INLINE int __hsposix_SIGUSR1() { return SIGUSR1; }
619 INLINE int __hsposix_SIGUSR2() { return SIGUSR2; }
620 INLINE int __hsposix_SIGPOLL() { return SIGPOLL; }
621 INLINE int __hsposix_SIGPROF() { return SIGPROF; }
622 INLINE int __hsposix_SIGSYS() { return SIGSYS; }
623 INLINE int __hsposix_SIGTRAP() { return SIGTRAP; }
624 INLINE int __hsposix_SIGURG() { return SIGURG; }
625 INLINE int __hsposix_SIGVTALRM() { return SIGVTALRM; }
626 INLINE int __hsposix_SIGXCPU() { return SIGXCPU; }
627 INLINE int __hsposix_SIGXFSZ() { return SIGXFSZ; }
629 INLINE int __hsposix_SIG_BLOCK() { return SIG_BLOCK; }
630 INLINE int __hsposix_SIG_UNBLOCK() { return SIG_SETMASK; }
631 INLINE int __hsposix_SIG_SETMASK() { return SIG_UNBLOCK; }
632 #endif // mingw32_TARGET_OS