1 /* -----------------------------------------------------------------------------
2 * $Id: HsBase.h,v 1.21 2003/05/08 16:06:41 ross Exp $
4 * (c) The University of Glasgow 2001-2002
6 * Definitions for package `base' 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 /* in writeError.c */
123 void writeErrString__(HsAddr msg_hdr, HsAddr msg, HsInt len);
125 /* -----------------------------------------------------------------------------
126 64-bit operations, defined in longlong.c
127 -------------------------------------------------------------------------- */
129 #ifdef SUPPORT_LONG_LONGS
131 StgInt stg_gtWord64 (StgWord64, StgWord64);
132 StgInt stg_geWord64 (StgWord64, StgWord64);
133 StgInt stg_eqWord64 (StgWord64, StgWord64);
134 StgInt stg_neWord64 (StgWord64, StgWord64);
135 StgInt stg_ltWord64 (StgWord64, StgWord64);
136 StgInt stg_leWord64 (StgWord64, StgWord64);
138 StgInt stg_gtInt64 (StgInt64, StgInt64);
139 StgInt stg_geInt64 (StgInt64, StgInt64);
140 StgInt stg_eqInt64 (StgInt64, StgInt64);
141 StgInt stg_neInt64 (StgInt64, StgInt64);
142 StgInt stg_ltInt64 (StgInt64, StgInt64);
143 StgInt stg_leInt64 (StgInt64, StgInt64);
145 StgWord64 stg_remWord64 (StgWord64, StgWord64);
146 StgWord64 stg_quotWord64 (StgWord64, StgWord64);
148 StgInt64 stg_remInt64 (StgInt64, StgInt64);
149 StgInt64 stg_quotInt64 (StgInt64, StgInt64);
150 StgInt64 stg_negateInt64 (StgInt64);
151 StgInt64 stg_plusInt64 (StgInt64, StgInt64);
152 StgInt64 stg_minusInt64 (StgInt64, StgInt64);
153 StgInt64 stg_timesInt64 (StgInt64, StgInt64);
155 StgWord64 stg_and64 (StgWord64, StgWord64);
156 StgWord64 stg_or64 (StgWord64, StgWord64);
157 StgWord64 stg_xor64 (StgWord64, StgWord64);
158 StgWord64 stg_not64 (StgWord64);
160 StgWord64 stg_uncheckedShiftL64 (StgWord64, StgInt);
161 StgWord64 stg_uncheckedShiftRL64 (StgWord64, StgInt);
162 StgInt64 stg_uncheckedIShiftL64 (StgInt64, StgInt);
163 StgInt64 stg_uncheckedIShiftRL64 (StgInt64, StgInt);
164 StgInt64 stg_uncheckedIShiftRA64 (StgInt64, StgInt);
166 StgInt64 stg_intToInt64 (StgInt);
167 StgInt stg_int64ToInt (StgInt64);
168 StgWord64 stg_int64ToWord64 (StgInt64);
170 StgWord64 stg_wordToWord64 (StgWord);
171 StgWord stg_word64ToWord (StgWord64);
172 StgInt64 stg_word64ToInt64 (StgWord64);
174 StgInt64 stg_integerToInt64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
175 StgWord64 stg_integerToWord64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
177 #endif /* SUPPORT_LONG_LONGS */
179 /* -----------------------------------------------------------------------------
182 These functions are given as inlines here for when compiling via C,
183 but we also generate static versions into the cbits library for
184 when compiling to native code.
185 -------------------------------------------------------------------------- */
188 #define INLINE extern inline
191 INLINE int __hscore_s_isreg(m) { return S_ISREG(m); }
192 INLINE int __hscore_s_isdir(m) { return S_ISDIR(m); }
193 INLINE int __hscore_s_isfifo(m) { return S_ISFIFO(m); }
194 INLINE int __hscore_s_isblk(m) { return S_ISBLK(m); }
195 INLINE int __hscore_s_ischr(m) { return S_ISCHR(m); }
197 INLINE int __hscore_s_issock(m) { return S_ISSOCK(m); }
200 #ifndef mingw32_TARGET_OS
202 __hscore_sigemptyset( sigset_t *set )
203 { return sigemptyset(set); }
206 __hscore_sigfillset( sigset_t *set )
207 { return sigfillset(set); }
210 __hscore_sigaddset( sigset_t * set, int s )
211 { return sigaddset(set,s); }
214 __hscore_sigdelset( sigset_t * set, int s )
215 { return sigdelset(set,s); }
218 __hscore_sigismember( sigset_t * set, int s )
219 { return sigismember(set,s); }
223 __hscore_memcpy_dst_off( char *dst, int dst_off, char *src, size_t sz )
224 { return memcpy(dst+dst_off, src, sz); }
227 __hscore_memcpy_src_off( char *dst, char *src, int src_off, size_t sz )
228 { return memcpy(dst, src+src_off, sz); }
231 __hscore_supportsTextMode()
233 #if defined(mingw32_TARGET_OS)
234 return HS_BOOL_FALSE;
273 __hscore_o_wronly( void )
283 __hscore_o_rdwr( void )
293 __hscore_o_append( void )
303 __hscore_o_creat( void )
313 __hscore_o_excl( void )
323 __hscore_o_trunc( void )
333 __hscore_o_noctty( void )
343 __hscore_o_nonblock( void )
353 __hscore_seek_set( void )
359 __hscore_seek_end( void )
365 __hscore_setmode( HsInt fd, HsBool toBin )
367 #if defined(__MINGW32__)
368 return setmode(fd,(toBin == HS_BOOL_TRUE) ? _O_BINARY : _O_TEXT);
375 __hscore_PrelHandle_write( HsInt fd, HsBool isSock, HsAddr ptr,
378 #if defined(__MINGW32__)
380 return send(fd,(char *)ptr + off, sz, 0);
383 return write(fd,(char *)ptr + off, sz);
387 __hscore_PrelHandle_read( HsInt fd, HsBool isSock, HsAddr ptr,
390 #if defined(__MINGW32__)
392 return recv(fd,(char *)ptr + off, sz, 0);
395 return read(fd,(char *)ptr + off, sz);
399 #if defined(__MINGW32__)
401 __hscore_Time_ghcTimezone( void ) { return &_timezone; }
404 __hscore_Time_ghcTzname( void ) { return _tzname; }
408 __hscore_mkdir( HsAddr pathName, HsInt mode )
410 #if defined(__MINGW32__)
411 return mkdir(pathName);
413 return mkdir(pathName,mode);
418 __hscore_lstat( HsAddr fname, HsAddr st )
421 return lstat((const char*)fname, (struct stat*)st);
423 return stat((const char*)fname, (struct stat*)st);
427 INLINE HsInt __hscore_path_max() { return PATH_MAX; }
429 INLINE mode_t __hscore_R_OK() { return R_OK; }
430 INLINE mode_t __hscore_W_OK() { return W_OK; }
431 INLINE mode_t __hscore_X_OK() { return X_OK; }
433 INLINE mode_t __hscore_S_IRUSR() { return S_IRUSR; }
434 INLINE mode_t __hscore_S_IWUSR() { return S_IWUSR; }
435 INLINE mode_t __hscore_S_IXUSR() { return S_IXUSR; }
438 __hscore_d_name( struct dirent* d )
440 #ifndef mingw32_TARGET_OS
441 return (HsAddr)(&d->d_name);
443 return (HsAddr)(d->d_name);
448 __hscore_end_of_dir( void )
450 #ifndef mingw32_TARGET_OS
458 __hscore_free_dirent(HsAddr dEnt)
466 __hscore_sizeof_stat( void )
468 return sizeof(struct stat);
471 INLINE time_t __hscore_st_mtime ( struct stat* st ) { return st->st_mtime; }
472 INLINE off_t __hscore_st_size ( struct stat* st ) { return st->st_size; }
473 INLINE mode_t __hscore_st_mode ( struct stat* st ) { return st->st_mode; }
476 INLINE tcflag_t __hscore_lflag( struct termios* ts ) { return ts->c_lflag; }
479 __hscore_poke_lflag( struct termios* ts, tcflag_t t ) { ts->c_lflag = t; }
481 INLINE unsigned char*
482 __hscore_ptr_c_cc( struct termios* ts )
483 { return (unsigned char*) &ts->c_cc; }
487 __hscore_sizeof_termios( void )
489 #ifndef mingw32_TARGET_OS
490 return sizeof(struct termios);
497 __hscore_sizeof_sigset_t( void )
499 #ifndef mingw32_TARGET_OS
500 return sizeof(sigset_t);
507 __hscore_echo( void )
518 __hscore_tcsanow( void )
529 __hscore_icanon( void )
538 INLINE int __hscore_vmin( void )
547 INLINE int __hscore_vtime( void )
556 INLINE int __hscore_sigttou( void )
565 INLINE int __hscore_sig_block( void )
574 INLINE int __hscore_sig_setmask( void )
584 __hscore_f_getfl( void )
594 __hscore_f_setfl( void )
603 INLINE int __hscore_hs_fileno (FILE *f) { return fileno (f); }
605 #ifndef mingw32_TARGET_OS
606 INLINE int __hsposix_SIGABRT() { return SIGABRT; }
607 INLINE int __hsposix_SIGALRM() { return SIGALRM; }
608 INLINE int __hsposix_SIGBUS() { return SIGBUS; }
609 INLINE int __hsposix_SIGCHLD() { return SIGCHLD; }
610 INLINE int __hsposix_SIGCONT() { return SIGCONT; }
611 INLINE int __hsposix_SIGFPE() { return SIGFPE; }
612 INLINE int __hsposix_SIGHUP() { return SIGHUP; }
613 INLINE int __hsposix_SIGILL() { return SIGILL; }
614 INLINE int __hsposix_SIGINT() { return SIGINT; }
615 INLINE int __hsposix_SIGKILL() { return SIGKILL; }
616 INLINE int __hsposix_SIGPIPE() { return SIGPIPE; }
617 INLINE int __hsposix_SIGQUIT() { return SIGQUIT; }
618 INLINE int __hsposix_SIGSEGV() { return SIGSEGV; }
619 INLINE int __hsposix_SIGSTOP() { return SIGSTOP; }
620 INLINE int __hsposix_SIGTERM() { return SIGTERM; }
621 INLINE int __hsposix_SIGTSTP() { return SIGTSTP; }
622 INLINE int __hsposix_SIGTTIN() { return SIGTTIN; }
623 INLINE int __hsposix_SIGTTOU() { return SIGTTOU; }
624 INLINE int __hsposix_SIGUSR1() { return SIGUSR1; }
625 INLINE int __hsposix_SIGUSR2() { return SIGUSR2; }
627 INLINE int __hsposix_SIGPOLL() { return SIGPOLL; }
629 INLINE int __hsposix_SIGPROF() { return SIGPROF; }
630 INLINE int __hsposix_SIGSYS() { return SIGSYS; }
631 INLINE int __hsposix_SIGTRAP() { return SIGTRAP; }
632 INLINE int __hsposix_SIGURG() { return SIGURG; }
633 INLINE int __hsposix_SIGVTALRM() { return SIGVTALRM; }
634 INLINE int __hsposix_SIGXCPU() { return SIGXCPU; }
635 INLINE int __hsposix_SIGXFSZ() { return SIGXFSZ; }
637 INLINE int __hsposix_SIG_BLOCK() { return SIG_BLOCK; }
638 INLINE int __hsposix_SIG_UNBLOCK() { return SIG_SETMASK; }
639 INLINE int __hsposix_SIG_SETMASK() { return SIG_UNBLOCK; }
640 #endif /* mingw32_TARGET_OS */
642 #endif /* __HSBASE_H__ */