1 /* -----------------------------------------------------------------------------
2 * $Id: HsBase.h,v 1.31 2003/10/13 03:19:48 sof 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 extern HsInt nocldstop;
135 /* -----------------------------------------------------------------------------
136 64-bit operations, defined in longlong.c
137 -------------------------------------------------------------------------- */
139 #ifdef SUPPORT_LONG_LONGS
141 StgInt stg_gtWord64 (StgWord64, StgWord64);
142 StgInt stg_geWord64 (StgWord64, StgWord64);
143 StgInt stg_eqWord64 (StgWord64, StgWord64);
144 StgInt stg_neWord64 (StgWord64, StgWord64);
145 StgInt stg_ltWord64 (StgWord64, StgWord64);
146 StgInt stg_leWord64 (StgWord64, StgWord64);
148 StgInt stg_gtInt64 (StgInt64, StgInt64);
149 StgInt stg_geInt64 (StgInt64, StgInt64);
150 StgInt stg_eqInt64 (StgInt64, StgInt64);
151 StgInt stg_neInt64 (StgInt64, StgInt64);
152 StgInt stg_ltInt64 (StgInt64, StgInt64);
153 StgInt stg_leInt64 (StgInt64, StgInt64);
155 StgWord64 stg_remWord64 (StgWord64, StgWord64);
156 StgWord64 stg_quotWord64 (StgWord64, StgWord64);
158 StgInt64 stg_remInt64 (StgInt64, StgInt64);
159 StgInt64 stg_quotInt64 (StgInt64, StgInt64);
160 StgInt64 stg_negateInt64 (StgInt64);
161 StgInt64 stg_plusInt64 (StgInt64, StgInt64);
162 StgInt64 stg_minusInt64 (StgInt64, StgInt64);
163 StgInt64 stg_timesInt64 (StgInt64, StgInt64);
165 StgWord64 stg_and64 (StgWord64, StgWord64);
166 StgWord64 stg_or64 (StgWord64, StgWord64);
167 StgWord64 stg_xor64 (StgWord64, StgWord64);
168 StgWord64 stg_not64 (StgWord64);
170 StgWord64 stg_uncheckedShiftL64 (StgWord64, StgInt);
171 StgWord64 stg_uncheckedShiftRL64 (StgWord64, StgInt);
172 StgInt64 stg_uncheckedIShiftL64 (StgInt64, StgInt);
173 StgInt64 stg_uncheckedIShiftRL64 (StgInt64, StgInt);
174 StgInt64 stg_uncheckedIShiftRA64 (StgInt64, StgInt);
176 StgInt64 stg_intToInt64 (StgInt);
177 StgInt stg_int64ToInt (StgInt64);
178 StgWord64 stg_int64ToWord64 (StgInt64);
180 StgWord64 stg_wordToWord64 (StgWord);
181 StgWord stg_word64ToWord (StgWord64);
182 StgInt64 stg_word64ToInt64 (StgWord64);
184 StgInt64 stg_integerToInt64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
185 StgWord64 stg_integerToWord64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
187 #endif /* SUPPORT_LONG_LONGS */
189 /* -----------------------------------------------------------------------------
192 These functions are given as inlines here for when compiling via C,
193 but we also generate static versions into the cbits library for
194 when compiling to native code.
195 -------------------------------------------------------------------------- */
198 # if defined(_MSC_VER)
199 # define INLINE extern __inline
201 # define INLINE extern inline
205 #if !defined(_MSC_VER) && !defined(__MINGW__)
206 INLINE int __hscore_s_isreg(m) { return S_ISREG(m); }
207 INLINE int __hscore_s_isdir(m) { return S_ISDIR(m); }
208 INLINE int __hscore_s_isfifo(m) { return S_ISFIFO(m); }
209 INLINE int __hscore_s_isblk(m) { return S_ISBLK(m); }
210 INLINE int __hscore_s_ischr(m) { return S_ISCHR(m); }
212 INLINE int __hscore_s_issock(m) { return S_ISSOCK(m); }
216 #if !defined(mingw32_TARGET_OS) && !defined(_MSC_VER) && !defined(__MINGW__)
218 __hscore_sigemptyset( sigset_t *set )
219 { return sigemptyset(set); }
222 __hscore_sigfillset( sigset_t *set )
223 { return sigfillset(set); }
226 __hscore_sigaddset( sigset_t * set, int s )
227 { return sigaddset(set,s); }
230 __hscore_sigdelset( sigset_t * set, int s )
231 { return sigdelset(set,s); }
234 __hscore_sigismember( sigset_t * set, int s )
235 { return sigismember(set,s); }
239 __hscore_memcpy_dst_off( char *dst, int dst_off, char *src, size_t sz )
240 { return memcpy(dst+dst_off, src, sz); }
243 __hscore_memcpy_src_off( char *dst, char *src, int src_off, size_t sz )
244 { return memcpy(dst, src+src_off, sz); }
247 __hscore_supportsTextMode()
249 #if defined(mingw32_TARGET_OS)
250 return HS_BOOL_FALSE;
271 #if defined(_MSC_VER)
274 return CONST_O_BINARY;
289 __hscore_o_wronly( void )
299 __hscore_o_rdwr( void )
309 __hscore_o_append( void )
319 __hscore_o_creat( void )
329 __hscore_o_excl( void )
339 __hscore_o_trunc( void )
349 __hscore_o_noctty( void )
359 __hscore_o_nonblock( void )
369 __hscore_seek_set( void )
375 __hscore_seek_end( void )
381 __hscore_setmode( HsInt fd, HsBool toBin )
383 #if defined(__MINGW32__)
384 return setmode(fd,(toBin == HS_BOOL_TRUE) ? _O_BINARY : _O_TEXT);
391 __hscore_PrelHandle_write( HsInt fd, HsBool isSock, HsAddr ptr,
394 #if defined(__MINGW32__)
396 return send(fd,(char *)ptr + off, sz, 0);
399 return write(fd,(char *)ptr + off, sz);
403 __hscore_PrelHandle_read( HsInt fd, HsBool isSock, HsAddr ptr,
406 #if defined(__MINGW32__)
408 return recv(fd,(char *)ptr + off, sz, 0);
411 return read(fd,(char *)ptr + off, sz);
415 #if defined(__MINGW32__)
417 __hscore_Time_ghcTimezone( void ) { return &_timezone; }
420 __hscore_Time_ghcTzname( void ) { return _tzname; }
424 __hscore_mkdir( HsAddr pathName, HsInt mode )
426 #if defined(__MINGW32__)
427 return mkdir(pathName);
429 return mkdir(pathName,mode);
434 __hscore_lstat( HsAddr fname, HsAddr st )
437 return lstat((const char*)fname, (struct stat*)st);
439 return stat((const char*)fname, (struct stat*)st);
444 /* A size that will contain many path names, but not necessarily all
445 * (PATH_MAX is not defined on systems with unlimited path length,
448 INLINE HsInt __hscore_long_path_size() { return PATH_MAX; }
450 INLINE HsInt __hscore_long_path_size() { return 4096; }
454 INLINE mode_t __hscore_R_OK() { return R_OK; }
457 INLINE mode_t __hscore_W_OK() { return W_OK; }
460 INLINE mode_t __hscore_X_OK() { return X_OK; }
464 INLINE mode_t __hscore_S_IRUSR() { return S_IRUSR; }
467 INLINE mode_t __hscore_S_IWUSR() { return S_IWUSR; }
470 INLINE mode_t __hscore_S_IXUSR() { return S_IXUSR; }
473 #if !defined(_MSC_VER) && !defined(__MINGW__)
475 __hscore_d_name( struct dirent* d )
477 #ifndef mingw32_TARGET_OS
478 return (HsAddr)(&d->d_name);
480 return (HsAddr)(d->d_name);
486 __hscore_end_of_dir( void )
488 #ifndef mingw32_TARGET_OS
496 __hscore_free_dirent(HsAddr dEnt)
504 __hscore_sizeof_stat( void )
506 return sizeof(struct stat);
509 INLINE time_t __hscore_st_mtime ( struct stat* st ) { return st->st_mtime; }
510 INLINE off_t __hscore_st_size ( struct stat* st ) { return st->st_size; }
511 #if !defined(_MSC_VER) && !defined(__MINGW__)
512 INLINE mode_t __hscore_st_mode ( struct stat* st ) { return st->st_mode; }
516 INLINE tcflag_t __hscore_lflag( struct termios* ts ) { return ts->c_lflag; }
519 __hscore_poke_lflag( struct termios* ts, tcflag_t t ) { ts->c_lflag = t; }
521 INLINE unsigned char*
522 __hscore_ptr_c_cc( struct termios* ts )
523 { return (unsigned char*) &ts->c_cc; }
526 __hscore_sizeof_termios( void )
528 #ifndef mingw32_TARGET_OS
529 return sizeof(struct termios);
536 #if !defined(_MSC_VER) && !defined(__MINGW__)
538 __hscore_sizeof_sigset_t( void )
540 #ifndef mingw32_TARGET_OS
541 return sizeof(sigset_t);
549 __hscore_echo( void )
560 __hscore_tcsanow( void )
571 __hscore_icanon( void )
580 INLINE int __hscore_vmin( void )
589 INLINE int __hscore_vtime( void )
598 INLINE int __hscore_sigttou( void )
607 INLINE int __hscore_sig_block( void )
616 INLINE int __hscore_sig_setmask( void )
626 __hscore_f_getfl( void )
636 __hscore_f_setfl( void )
645 // defined in rts/RtsStartup.c.
646 extern void* __hscore_get_saved_termios(int fd);
647 extern void __hscore_set_saved_termios(int fd, void* ts);
649 INLINE int __hscore_hs_fileno (FILE *f) { return fileno (f); }
651 #if !defined(mingw32_TARGET_OS) && !defined(_MSC_VER) && !defined(__MINGW32__)
652 INLINE int __hsposix_SIGABRT() { return SIGABRT; }
653 INLINE int __hsposix_SIGALRM() { return SIGALRM; }
654 INLINE int __hsposix_SIGBUS() { return SIGBUS; }
655 INLINE int __hsposix_SIGCHLD() { return SIGCHLD; }
656 INLINE int __hsposix_SIGCONT() { return SIGCONT; }
657 INLINE int __hsposix_SIGFPE() { return SIGFPE; }
658 INLINE int __hsposix_SIGHUP() { return SIGHUP; }
659 INLINE int __hsposix_SIGILL() { return SIGILL; }
660 INLINE int __hsposix_SIGINT() { return SIGINT; }
661 INLINE int __hsposix_SIGKILL() { return SIGKILL; }
662 INLINE int __hsposix_SIGPIPE() { return SIGPIPE; }
663 INLINE int __hsposix_SIGQUIT() { return SIGQUIT; }
664 INLINE int __hsposix_SIGSEGV() { return SIGSEGV; }
665 INLINE int __hsposix_SIGSTOP() { return SIGSTOP; }
666 INLINE int __hsposix_SIGTERM() { return SIGTERM; }
667 INLINE int __hsposix_SIGTSTP() { return SIGTSTP; }
668 INLINE int __hsposix_SIGTTIN() { return SIGTTIN; }
669 INLINE int __hsposix_SIGTTOU() { return SIGTTOU; }
670 INLINE int __hsposix_SIGUSR1() { return SIGUSR1; }
671 INLINE int __hsposix_SIGUSR2() { return SIGUSR2; }
673 INLINE int __hsposix_SIGPOLL() { return SIGPOLL; }
675 INLINE int __hsposix_SIGPROF() { return SIGPROF; }
676 INLINE int __hsposix_SIGSYS() { return SIGSYS; }
677 INLINE int __hsposix_SIGTRAP() { return SIGTRAP; }
678 INLINE int __hsposix_SIGURG() { return SIGURG; }
679 INLINE int __hsposix_SIGVTALRM() { return SIGVTALRM; }
680 INLINE int __hsposix_SIGXCPU() { return SIGXCPU; }
681 INLINE int __hsposix_SIGXFSZ() { return SIGXFSZ; }
683 INLINE int __hsposix_SIG_BLOCK() { return SIG_BLOCK; }
684 INLINE int __hsposix_SIG_UNBLOCK() { return SIG_SETMASK; }
685 INLINE int __hsposix_SIG_SETMASK() { return SIG_UNBLOCK; }
686 #endif /* mingw32_TARGET_OS */
688 #endif /* __HSBASE_H__ */