1 /* -----------------------------------------------------------------------------
2 * $Id: HsBase.h,v 1.27 2003/09/21 22:20:57 wolfgang 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__)
85 #if !defined(mingw32_TARGET_OS) && !defined(irix_TARGET_OS)
86 # if defined(HAVE_SYS_RESOURCE_H)
87 # include <sys/resource.h>
92 #include <sys/syscall.h>
93 #define getrusage(a, b) syscall(SYS_GETRUSAGE, a, b)
94 #define HAVE_GETRUSAGE
98 #ifdef HAVE_SYS_WAIT_H
104 #include "lockFile.h"
105 #include "dirUtils.h"
107 #if defined(__MINGW32__)
110 #include "timeUtils.h"
117 HsInt systemCmd(HsAddr cmd);
120 #if defined(mingw32_TARGET_OS)
121 HsInt rawSystem(HsAddr cmd);
123 HsInt rawSystem(HsAddr cmd, HsAddr args);
126 /* in inputReady.c */
127 int inputReady(int fd, int msecs, int isSock);
129 /* in writeError.c */
130 void writeErrString__(HsAddr msg_hdr, HsAddr msg, HsInt len);
133 int forkOS_createThread ( HsStablePtr entry );
136 extern HsInt nocldstop;
138 /* -----------------------------------------------------------------------------
139 64-bit operations, defined in longlong.c
140 -------------------------------------------------------------------------- */
142 #ifdef SUPPORT_LONG_LONGS
144 StgInt stg_gtWord64 (StgWord64, StgWord64);
145 StgInt stg_geWord64 (StgWord64, StgWord64);
146 StgInt stg_eqWord64 (StgWord64, StgWord64);
147 StgInt stg_neWord64 (StgWord64, StgWord64);
148 StgInt stg_ltWord64 (StgWord64, StgWord64);
149 StgInt stg_leWord64 (StgWord64, StgWord64);
151 StgInt stg_gtInt64 (StgInt64, StgInt64);
152 StgInt stg_geInt64 (StgInt64, StgInt64);
153 StgInt stg_eqInt64 (StgInt64, StgInt64);
154 StgInt stg_neInt64 (StgInt64, StgInt64);
155 StgInt stg_ltInt64 (StgInt64, StgInt64);
156 StgInt stg_leInt64 (StgInt64, StgInt64);
158 StgWord64 stg_remWord64 (StgWord64, StgWord64);
159 StgWord64 stg_quotWord64 (StgWord64, StgWord64);
161 StgInt64 stg_remInt64 (StgInt64, StgInt64);
162 StgInt64 stg_quotInt64 (StgInt64, StgInt64);
163 StgInt64 stg_negateInt64 (StgInt64);
164 StgInt64 stg_plusInt64 (StgInt64, StgInt64);
165 StgInt64 stg_minusInt64 (StgInt64, StgInt64);
166 StgInt64 stg_timesInt64 (StgInt64, StgInt64);
168 StgWord64 stg_and64 (StgWord64, StgWord64);
169 StgWord64 stg_or64 (StgWord64, StgWord64);
170 StgWord64 stg_xor64 (StgWord64, StgWord64);
171 StgWord64 stg_not64 (StgWord64);
173 StgWord64 stg_uncheckedShiftL64 (StgWord64, StgInt);
174 StgWord64 stg_uncheckedShiftRL64 (StgWord64, StgInt);
175 StgInt64 stg_uncheckedIShiftL64 (StgInt64, StgInt);
176 StgInt64 stg_uncheckedIShiftRL64 (StgInt64, StgInt);
177 StgInt64 stg_uncheckedIShiftRA64 (StgInt64, StgInt);
179 StgInt64 stg_intToInt64 (StgInt);
180 StgInt stg_int64ToInt (StgInt64);
181 StgWord64 stg_int64ToWord64 (StgInt64);
183 StgWord64 stg_wordToWord64 (StgWord);
184 StgWord stg_word64ToWord (StgWord64);
185 StgInt64 stg_word64ToInt64 (StgWord64);
187 StgInt64 stg_integerToInt64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
188 StgWord64 stg_integerToWord64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
190 #endif /* SUPPORT_LONG_LONGS */
192 /* -----------------------------------------------------------------------------
195 These functions are given as inlines here for when compiling via C,
196 but we also generate static versions into the cbits library for
197 when compiling to native code.
198 -------------------------------------------------------------------------- */
201 #define INLINE extern inline
204 INLINE int __hscore_s_isreg(m) { return S_ISREG(m); }
205 INLINE int __hscore_s_isdir(m) { return S_ISDIR(m); }
206 INLINE int __hscore_s_isfifo(m) { return S_ISFIFO(m); }
207 INLINE int __hscore_s_isblk(m) { return S_ISBLK(m); }
208 INLINE int __hscore_s_ischr(m) { return S_ISCHR(m); }
210 INLINE int __hscore_s_issock(m) { return S_ISSOCK(m); }
213 #ifndef mingw32_TARGET_OS
215 __hscore_sigemptyset( sigset_t *set )
216 { return sigemptyset(set); }
219 __hscore_sigfillset( sigset_t *set )
220 { return sigfillset(set); }
223 __hscore_sigaddset( sigset_t * set, int s )
224 { return sigaddset(set,s); }
227 __hscore_sigdelset( sigset_t * set, int s )
228 { return sigdelset(set,s); }
231 __hscore_sigismember( sigset_t * set, int s )
232 { return sigismember(set,s); }
236 __hscore_memcpy_dst_off( char *dst, int dst_off, char *src, size_t sz )
237 { return memcpy(dst+dst_off, src, sz); }
240 __hscore_memcpy_src_off( char *dst, char *src, int src_off, size_t sz )
241 { return memcpy(dst, src+src_off, sz); }
244 __hscore_supportsTextMode()
246 #if defined(mingw32_TARGET_OS)
247 return HS_BOOL_FALSE;
268 return CONST_O_BINARY;
282 __hscore_o_wronly( void )
292 __hscore_o_rdwr( void )
302 __hscore_o_append( void )
312 __hscore_o_creat( void )
322 __hscore_o_excl( void )
332 __hscore_o_trunc( void )
342 __hscore_o_noctty( void )
352 __hscore_o_nonblock( void )
362 __hscore_seek_set( void )
368 __hscore_seek_end( void )
374 __hscore_setmode( HsInt fd, HsBool toBin )
376 #if defined(__MINGW32__)
377 return setmode(fd,(toBin == HS_BOOL_TRUE) ? _O_BINARY : _O_TEXT);
384 __hscore_PrelHandle_write( HsInt fd, HsBool isSock, HsAddr ptr,
387 #if defined(__MINGW32__)
389 return send(fd,(char *)ptr + off, sz, 0);
392 return write(fd,(char *)ptr + off, sz);
396 __hscore_PrelHandle_read( HsInt fd, HsBool isSock, HsAddr ptr,
399 #if defined(__MINGW32__)
401 return recv(fd,(char *)ptr + off, sz, 0);
404 return read(fd,(char *)ptr + off, sz);
408 #if defined(__MINGW32__)
410 __hscore_Time_ghcTimezone( void ) { return &_timezone; }
413 __hscore_Time_ghcTzname( void ) { return _tzname; }
417 __hscore_mkdir( HsAddr pathName, HsInt mode )
419 #if defined(__MINGW32__)
420 return mkdir(pathName);
422 return mkdir(pathName,mode);
427 __hscore_lstat( HsAddr fname, HsAddr st )
430 return lstat((const char*)fname, (struct stat*)st);
432 return stat((const char*)fname, (struct stat*)st);
437 /* A size that will contain many path names, but not necessarily all
438 * (PATH_MAX is not defined on systems with unlimited path length,
441 INLINE HsInt __hscore_long_path_size() { return PATH_MAX; }
443 INLINE HsInt __hscore_long_path_size() { return 4096; }
446 INLINE mode_t __hscore_R_OK() { return R_OK; }
447 INLINE mode_t __hscore_W_OK() { return W_OK; }
448 INLINE mode_t __hscore_X_OK() { return X_OK; }
450 INLINE mode_t __hscore_S_IRUSR() { return S_IRUSR; }
451 INLINE mode_t __hscore_S_IWUSR() { return S_IWUSR; }
452 INLINE mode_t __hscore_S_IXUSR() { return S_IXUSR; }
455 __hscore_d_name( struct dirent* d )
457 #ifndef mingw32_TARGET_OS
458 return (HsAddr)(&d->d_name);
460 return (HsAddr)(d->d_name);
465 __hscore_end_of_dir( void )
467 #ifndef mingw32_TARGET_OS
475 __hscore_free_dirent(HsAddr dEnt)
483 __hscore_sizeof_stat( void )
485 return sizeof(struct stat);
488 INLINE time_t __hscore_st_mtime ( struct stat* st ) { return st->st_mtime; }
489 INLINE off_t __hscore_st_size ( struct stat* st ) { return st->st_size; }
490 INLINE mode_t __hscore_st_mode ( struct stat* st ) { return st->st_mode; }
493 INLINE tcflag_t __hscore_lflag( struct termios* ts ) { return ts->c_lflag; }
496 __hscore_poke_lflag( struct termios* ts, tcflag_t t ) { ts->c_lflag = t; }
498 INLINE unsigned char*
499 __hscore_ptr_c_cc( struct termios* ts )
500 { return (unsigned char*) &ts->c_cc; }
504 __hscore_sizeof_termios( void )
506 #ifndef mingw32_TARGET_OS
507 return sizeof(struct termios);
514 __hscore_sizeof_sigset_t( void )
516 #ifndef mingw32_TARGET_OS
517 return sizeof(sigset_t);
524 __hscore_echo( void )
535 __hscore_tcsanow( void )
546 __hscore_icanon( void )
555 INLINE int __hscore_vmin( void )
564 INLINE int __hscore_vtime( void )
573 INLINE int __hscore_sigttou( void )
582 INLINE int __hscore_sig_block( void )
591 INLINE int __hscore_sig_setmask( void )
601 __hscore_f_getfl( void )
611 __hscore_f_setfl( void )
620 INLINE int __hscore_hs_fileno (FILE *f) { return fileno (f); }
622 #ifndef mingw32_TARGET_OS
623 INLINE int __hsposix_SIGABRT() { return SIGABRT; }
624 INLINE int __hsposix_SIGALRM() { return SIGALRM; }
625 INLINE int __hsposix_SIGBUS() { return SIGBUS; }
626 INLINE int __hsposix_SIGCHLD() { return SIGCHLD; }
627 INLINE int __hsposix_SIGCONT() { return SIGCONT; }
628 INLINE int __hsposix_SIGFPE() { return SIGFPE; }
629 INLINE int __hsposix_SIGHUP() { return SIGHUP; }
630 INLINE int __hsposix_SIGILL() { return SIGILL; }
631 INLINE int __hsposix_SIGINT() { return SIGINT; }
632 INLINE int __hsposix_SIGKILL() { return SIGKILL; }
633 INLINE int __hsposix_SIGPIPE() { return SIGPIPE; }
634 INLINE int __hsposix_SIGQUIT() { return SIGQUIT; }
635 INLINE int __hsposix_SIGSEGV() { return SIGSEGV; }
636 INLINE int __hsposix_SIGSTOP() { return SIGSTOP; }
637 INLINE int __hsposix_SIGTERM() { return SIGTERM; }
638 INLINE int __hsposix_SIGTSTP() { return SIGTSTP; }
639 INLINE int __hsposix_SIGTTIN() { return SIGTTIN; }
640 INLINE int __hsposix_SIGTTOU() { return SIGTTOU; }
641 INLINE int __hsposix_SIGUSR1() { return SIGUSR1; }
642 INLINE int __hsposix_SIGUSR2() { return SIGUSR2; }
644 INLINE int __hsposix_SIGPOLL() { return SIGPOLL; }
646 INLINE int __hsposix_SIGPROF() { return SIGPROF; }
647 INLINE int __hsposix_SIGSYS() { return SIGSYS; }
648 INLINE int __hsposix_SIGTRAP() { return SIGTRAP; }
649 INLINE int __hsposix_SIGURG() { return SIGURG; }
650 INLINE int __hsposix_SIGVTALRM() { return SIGVTALRM; }
651 INLINE int __hsposix_SIGXCPU() { return SIGXCPU; }
652 INLINE int __hsposix_SIGXFSZ() { return SIGXFSZ; }
654 INLINE int __hsposix_SIG_BLOCK() { return SIG_BLOCK; }
655 INLINE int __hsposix_SIG_UNBLOCK() { return SIG_SETMASK; }
656 INLINE int __hsposix_SIG_SETMASK() { return SIG_UNBLOCK; }
657 #endif /* mingw32_TARGET_OS */
659 #endif /* __HSBASE_H__ */