1 /* -----------------------------------------------------------------------------
2 * $Id: HsBase.h,v 1.35 2003/11/02 00:06:23 panne 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
37 /* Ultra-ugly: OpenBSD uses a broken macro for sigfillset (missing cast) */
54 #ifdef HAVE_SYS_UTSNAME_H
55 #include <sys/utsname.h>
57 #if defined(HAVE_GETTIMEOFDAY)
58 # ifdef HAVE_SYS_TIME_H
59 # include <sys/time.h>
61 #elif defined(HAVE_GETCLOCK)
62 # ifdef HAVE_SYS_TIMERS_H
64 # include <sys/timers.h>
67 #if defined(HAVE_TIME_H)
70 #ifdef HAVE_SYS_TIMEB_H
71 #include <sys/timeb.h>
76 #ifdef HAVE_SYS_TIMES_H
77 #include <sys/times.h>
79 #if defined(HAVE_WINSOCK_H) && defined(mingw32_TARGET_OS)
89 #if !defined(mingw32_TARGET_OS) && !defined(irix_TARGET_OS)
90 # if defined(HAVE_SYS_RESOURCE_H)
91 # include <sys/resource.h>
96 #include <sys/syscall.h>
97 #define getrusage(a, b) syscall(SYS_GETRUSAGE, a, b)
98 #define HAVE_GETRUSAGE
102 #ifdef HAVE_SYS_WAIT_H
103 #include <sys/wait.h>
108 #include "lockFile.h"
109 #include "dirUtils.h"
111 #if defined(mingw32_TARGET_OS)
114 #include "timeUtils.h"
121 HsInt systemCmd(HsAddr cmd);
124 #if defined(mingw32_TARGET_OS)
125 HsInt rawSystem(HsAddr cmd);
127 HsInt rawSystem(HsAddr cmd, HsAddr args);
130 /* in inputReady.c */
131 int inputReady(int fd, int msecs, int isSock);
133 /* in writeError.c */
134 void writeErrString__(HsAddr msg_hdr, HsAddr msg, HsInt len);
137 extern HsInt nocldstop;
139 /* -----------------------------------------------------------------------------
140 64-bit operations, defined in longlong.c
141 -------------------------------------------------------------------------- */
143 #ifdef SUPPORT_LONG_LONGS
145 StgInt stg_gtWord64 (StgWord64, StgWord64);
146 StgInt stg_geWord64 (StgWord64, StgWord64);
147 StgInt stg_eqWord64 (StgWord64, StgWord64);
148 StgInt stg_neWord64 (StgWord64, StgWord64);
149 StgInt stg_ltWord64 (StgWord64, StgWord64);
150 StgInt stg_leWord64 (StgWord64, StgWord64);
152 StgInt stg_gtInt64 (StgInt64, StgInt64);
153 StgInt stg_geInt64 (StgInt64, StgInt64);
154 StgInt stg_eqInt64 (StgInt64, StgInt64);
155 StgInt stg_neInt64 (StgInt64, StgInt64);
156 StgInt stg_ltInt64 (StgInt64, StgInt64);
157 StgInt stg_leInt64 (StgInt64, StgInt64);
159 StgWord64 stg_remWord64 (StgWord64, StgWord64);
160 StgWord64 stg_quotWord64 (StgWord64, StgWord64);
162 StgInt64 stg_remInt64 (StgInt64, StgInt64);
163 StgInt64 stg_quotInt64 (StgInt64, StgInt64);
164 StgInt64 stg_negateInt64 (StgInt64);
165 StgInt64 stg_plusInt64 (StgInt64, StgInt64);
166 StgInt64 stg_minusInt64 (StgInt64, StgInt64);
167 StgInt64 stg_timesInt64 (StgInt64, StgInt64);
169 StgWord64 stg_and64 (StgWord64, StgWord64);
170 StgWord64 stg_or64 (StgWord64, StgWord64);
171 StgWord64 stg_xor64 (StgWord64, StgWord64);
172 StgWord64 stg_not64 (StgWord64);
174 StgWord64 stg_uncheckedShiftL64 (StgWord64, StgInt);
175 StgWord64 stg_uncheckedShiftRL64 (StgWord64, StgInt);
176 StgInt64 stg_uncheckedIShiftL64 (StgInt64, StgInt);
177 StgInt64 stg_uncheckedIShiftRL64 (StgInt64, StgInt);
178 StgInt64 stg_uncheckedIShiftRA64 (StgInt64, StgInt);
180 StgInt64 stg_intToInt64 (StgInt);
181 StgInt stg_int64ToInt (StgInt64);
182 StgWord64 stg_int64ToWord64 (StgInt64);
184 StgWord64 stg_wordToWord64 (StgWord);
185 StgWord stg_word64ToWord (StgWord64);
186 StgInt64 stg_word64ToInt64 (StgWord64);
188 StgInt64 stg_integerToInt64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
189 StgWord64 stg_integerToWord64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
191 #endif /* SUPPORT_LONG_LONGS */
193 /* -----------------------------------------------------------------------------
196 These functions are given as inlines here for when compiling via C,
197 but we also generate static versions into the cbits library for
198 when compiling to native code.
199 -------------------------------------------------------------------------- */
202 # if defined(_MSC_VER)
203 # define INLINE extern __inline
205 # define INLINE extern inline
209 #if !defined(_MSC_VER)
210 INLINE int __hscore_s_isreg(m) { return S_ISREG(m); }
211 INLINE int __hscore_s_isdir(m) { return S_ISDIR(m); }
212 INLINE int __hscore_s_isfifo(m) { return S_ISFIFO(m); }
213 INLINE int __hscore_s_isblk(m) { return S_ISBLK(m); }
214 INLINE int __hscore_s_ischr(m) { return S_ISCHR(m); }
216 INLINE int __hscore_s_issock(m) { return S_ISSOCK(m); }
220 #if !defined(mingw32_TARGET_OS) && !defined(_MSC_VER)
222 __hscore_sigemptyset( sigset_t *set )
223 { return sigemptyset(set); }
226 __hscore_sigfillset( sigset_t *set )
227 { return sigfillset(set); }
230 __hscore_sigaddset( sigset_t * set, int s )
231 { return sigaddset(set,s); }
234 __hscore_sigdelset( sigset_t * set, int s )
235 { return sigdelset(set,s); }
238 __hscore_sigismember( sigset_t * set, int s )
239 { return sigismember(set,s); }
243 __hscore_memcpy_dst_off( char *dst, int dst_off, char *src, size_t sz )
244 { return memcpy(dst+dst_off, src, sz); }
247 __hscore_memcpy_src_off( char *dst, char *src, int src_off, size_t sz )
248 { return memcpy(dst, src+src_off, sz); }
251 __hscore_supportsTextMode()
253 #if defined(mingw32_TARGET_OS)
254 return HS_BOOL_FALSE;
275 #if defined(_MSC_VER)
278 return CONST_O_BINARY;
293 __hscore_o_wronly( void )
303 __hscore_o_rdwr( void )
313 __hscore_o_append( void )
323 __hscore_o_creat( void )
333 __hscore_o_excl( void )
343 __hscore_o_trunc( void )
353 __hscore_o_noctty( void )
363 __hscore_o_nonblock( void )
373 __hscore_seek_set( void )
379 __hscore_seek_end( void )
385 __hscore_setmode( HsInt fd, HsBool toBin )
387 #if defined(mingw32_TARGET_OS) || defined(_MSC_VER)
388 return setmode(fd,(toBin == HS_BOOL_TRUE) ? _O_BINARY : _O_TEXT);
395 __hscore_PrelHandle_write( HsInt fd, HsBool isSock, HsAddr ptr,
398 #if defined(mingw32_TARGET_OS) || defined(_MSC_VER)
400 return send(fd,(char *)ptr + off, sz, 0);
403 return write(fd,(char *)ptr + off, sz);
407 __hscore_PrelHandle_read( HsInt fd, HsBool isSock, HsAddr ptr,
410 #if defined(mingw32_TARGET_OS) || defined(_MSC_VER)
412 return recv(fd,(char *)ptr + off, sz, 0);
415 return read(fd,(char *)ptr + off, sz);
419 #if defined(mingw32_TARGET_OS) || defined(_MSC_VER)
421 __hscore_Time_ghcTimezone( void ) { return &_timezone; }
424 __hscore_Time_ghcTzname( void ) { return _tzname; }
428 __hscore_mkdir( HsAddr pathName, HsInt mode )
430 #if defined(mingw32_TARGET_OS) || defined(_MSC_VER)
431 return mkdir(pathName);
433 return mkdir(pathName,mode);
438 __hscore_lstat( HsAddr fname, HsAddr st )
441 return lstat((const char*)fname, (struct stat*)st);
443 return stat((const char*)fname, (struct stat*)st);
448 /* A size that will contain many path names, but not necessarily all
449 * (PATH_MAX is not defined on systems with unlimited path length,
452 INLINE HsInt __hscore_long_path_size() { return PATH_MAX; }
454 INLINE HsInt __hscore_long_path_size() { return 4096; }
458 INLINE mode_t __hscore_R_OK() { return R_OK; }
461 INLINE mode_t __hscore_W_OK() { return W_OK; }
464 INLINE mode_t __hscore_X_OK() { return X_OK; }
468 INLINE mode_t __hscore_S_IRUSR() { return S_IRUSR; }
471 INLINE mode_t __hscore_S_IWUSR() { return S_IWUSR; }
474 INLINE mode_t __hscore_S_IXUSR() { return S_IXUSR; }
477 #if !defined(_MSC_VER)
479 __hscore_d_name( struct dirent* d )
481 #if !defined(mingw32_TARGET_OS) && !defined(_MSC_VER)
482 return (HsAddr)(&d->d_name);
484 return (HsAddr)(d->d_name);
490 __hscore_end_of_dir( void )
492 #ifndef mingw32_TARGET_OS
500 __hscore_free_dirent(HsAddr dEnt)
508 __hscore_sizeof_stat( void )
510 return sizeof(struct stat);
513 INLINE time_t __hscore_st_mtime ( struct stat* st ) { return st->st_mtime; }
514 INLINE off_t __hscore_st_size ( struct stat* st ) { return st->st_size; }
515 #if !defined(_MSC_VER)
516 INLINE mode_t __hscore_st_mode ( struct stat* st ) { return st->st_mode; }
520 INLINE tcflag_t __hscore_lflag( struct termios* ts ) { return ts->c_lflag; }
523 __hscore_poke_lflag( struct termios* ts, tcflag_t t ) { ts->c_lflag = t; }
525 INLINE unsigned char*
526 __hscore_ptr_c_cc( struct termios* ts )
527 { return (unsigned char*) &ts->c_cc; }
530 __hscore_sizeof_termios( void )
532 #ifndef mingw32_TARGET_OS
533 return sizeof(struct termios);
540 #if !defined(mingw32_TARGET_OS) && !defined(_MSC_VER)
542 __hscore_sizeof_sigset_t( void )
544 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)
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_UNBLOCK; }
685 INLINE int __hsposix_SIG_SETMASK() { return SIG_SETMASK; }
686 #endif /* mingw32_TARGET_OS */
688 #endif /* __HSBASE_H__ */