1 /* -----------------------------------------------------------------------------
2 * $Id: HsBase.h,v 1.25 2003/09/02 16:07:11 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__)
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);
132 /* -----------------------------------------------------------------------------
133 64-bit operations, defined in longlong.c
134 -------------------------------------------------------------------------- */
136 #ifdef SUPPORT_LONG_LONGS
138 StgInt stg_gtWord64 (StgWord64, StgWord64);
139 StgInt stg_geWord64 (StgWord64, StgWord64);
140 StgInt stg_eqWord64 (StgWord64, StgWord64);
141 StgInt stg_neWord64 (StgWord64, StgWord64);
142 StgInt stg_ltWord64 (StgWord64, StgWord64);
143 StgInt stg_leWord64 (StgWord64, StgWord64);
145 StgInt stg_gtInt64 (StgInt64, StgInt64);
146 StgInt stg_geInt64 (StgInt64, StgInt64);
147 StgInt stg_eqInt64 (StgInt64, StgInt64);
148 StgInt stg_neInt64 (StgInt64, StgInt64);
149 StgInt stg_ltInt64 (StgInt64, StgInt64);
150 StgInt stg_leInt64 (StgInt64, StgInt64);
152 StgWord64 stg_remWord64 (StgWord64, StgWord64);
153 StgWord64 stg_quotWord64 (StgWord64, StgWord64);
155 StgInt64 stg_remInt64 (StgInt64, StgInt64);
156 StgInt64 stg_quotInt64 (StgInt64, StgInt64);
157 StgInt64 stg_negateInt64 (StgInt64);
158 StgInt64 stg_plusInt64 (StgInt64, StgInt64);
159 StgInt64 stg_minusInt64 (StgInt64, StgInt64);
160 StgInt64 stg_timesInt64 (StgInt64, StgInt64);
162 StgWord64 stg_and64 (StgWord64, StgWord64);
163 StgWord64 stg_or64 (StgWord64, StgWord64);
164 StgWord64 stg_xor64 (StgWord64, StgWord64);
165 StgWord64 stg_not64 (StgWord64);
167 StgWord64 stg_uncheckedShiftL64 (StgWord64, StgInt);
168 StgWord64 stg_uncheckedShiftRL64 (StgWord64, StgInt);
169 StgInt64 stg_uncheckedIShiftL64 (StgInt64, StgInt);
170 StgInt64 stg_uncheckedIShiftRL64 (StgInt64, StgInt);
171 StgInt64 stg_uncheckedIShiftRA64 (StgInt64, StgInt);
173 StgInt64 stg_intToInt64 (StgInt);
174 StgInt stg_int64ToInt (StgInt64);
175 StgWord64 stg_int64ToWord64 (StgInt64);
177 StgWord64 stg_wordToWord64 (StgWord);
178 StgWord stg_word64ToWord (StgWord64);
179 StgInt64 stg_word64ToInt64 (StgWord64);
181 StgInt64 stg_integerToInt64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
182 StgWord64 stg_integerToWord64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
184 #endif /* SUPPORT_LONG_LONGS */
186 /* -----------------------------------------------------------------------------
189 These functions are given as inlines here for when compiling via C,
190 but we also generate static versions into the cbits library for
191 when compiling to native code.
192 -------------------------------------------------------------------------- */
195 #define INLINE extern inline
198 INLINE int __hscore_s_isreg(m) { return S_ISREG(m); }
199 INLINE int __hscore_s_isdir(m) { return S_ISDIR(m); }
200 INLINE int __hscore_s_isfifo(m) { return S_ISFIFO(m); }
201 INLINE int __hscore_s_isblk(m) { return S_ISBLK(m); }
202 INLINE int __hscore_s_ischr(m) { return S_ISCHR(m); }
204 INLINE int __hscore_s_issock(m) { return S_ISSOCK(m); }
207 #ifndef mingw32_TARGET_OS
209 __hscore_sigemptyset( sigset_t *set )
210 { return sigemptyset(set); }
213 __hscore_sigfillset( sigset_t *set )
214 { return sigfillset(set); }
217 __hscore_sigaddset( sigset_t * set, int s )
218 { return sigaddset(set,s); }
221 __hscore_sigdelset( sigset_t * set, int s )
222 { return sigdelset(set,s); }
225 __hscore_sigismember( sigset_t * set, int s )
226 { return sigismember(set,s); }
230 __hscore_memcpy_dst_off( char *dst, int dst_off, char *src, size_t sz )
231 { return memcpy(dst+dst_off, src, sz); }
234 __hscore_memcpy_src_off( char *dst, char *src, int src_off, size_t sz )
235 { return memcpy(dst, src+src_off, sz); }
238 __hscore_supportsTextMode()
240 #if defined(mingw32_TARGET_OS)
241 return HS_BOOL_FALSE;
262 return CONST_O_BINARY;
276 __hscore_o_wronly( void )
286 __hscore_o_rdwr( void )
296 __hscore_o_append( void )
306 __hscore_o_creat( void )
316 __hscore_o_excl( void )
326 __hscore_o_trunc( void )
336 __hscore_o_noctty( void )
346 __hscore_o_nonblock( void )
356 __hscore_seek_set( void )
362 __hscore_seek_end( void )
368 __hscore_setmode( HsInt fd, HsBool toBin )
370 #if defined(__MINGW32__)
371 return setmode(fd,(toBin == HS_BOOL_TRUE) ? _O_BINARY : _O_TEXT);
378 __hscore_PrelHandle_write( HsInt fd, HsBool isSock, HsAddr ptr,
381 #if defined(__MINGW32__)
383 return send(fd,(char *)ptr + off, sz, 0);
386 return write(fd,(char *)ptr + off, sz);
390 __hscore_PrelHandle_read( HsInt fd, HsBool isSock, HsAddr ptr,
393 #if defined(__MINGW32__)
395 return recv(fd,(char *)ptr + off, sz, 0);
398 return read(fd,(char *)ptr + off, sz);
402 #if defined(__MINGW32__)
404 __hscore_Time_ghcTimezone( void ) { return &_timezone; }
407 __hscore_Time_ghcTzname( void ) { return _tzname; }
411 __hscore_mkdir( HsAddr pathName, HsInt mode )
413 #if defined(__MINGW32__)
414 return mkdir(pathName);
416 return mkdir(pathName,mode);
421 __hscore_lstat( HsAddr fname, HsAddr st )
424 return lstat((const char*)fname, (struct stat*)st);
426 return stat((const char*)fname, (struct stat*)st);
431 /* A size that will contain many path names, but not necessarily all
432 * (PATH_MAX is not defined on systems with unlimited path length,
435 INLINE HsInt __hscore_long_path_size() { return PATH_MAX; }
437 INLINE HsInt __hscore_long_path_size() { return 4096; }
440 INLINE mode_t __hscore_R_OK() { return R_OK; }
441 INLINE mode_t __hscore_W_OK() { return W_OK; }
442 INLINE mode_t __hscore_X_OK() { return X_OK; }
444 INLINE mode_t __hscore_S_IRUSR() { return S_IRUSR; }
445 INLINE mode_t __hscore_S_IWUSR() { return S_IWUSR; }
446 INLINE mode_t __hscore_S_IXUSR() { return S_IXUSR; }
449 __hscore_d_name( struct dirent* d )
451 #ifndef mingw32_TARGET_OS
452 return (HsAddr)(&d->d_name);
454 return (HsAddr)(d->d_name);
459 __hscore_end_of_dir( void )
461 #ifndef mingw32_TARGET_OS
469 __hscore_free_dirent(HsAddr dEnt)
477 __hscore_sizeof_stat( void )
479 return sizeof(struct stat);
482 INLINE time_t __hscore_st_mtime ( struct stat* st ) { return st->st_mtime; }
483 INLINE off_t __hscore_st_size ( struct stat* st ) { return st->st_size; }
484 INLINE mode_t __hscore_st_mode ( struct stat* st ) { return st->st_mode; }
487 INLINE tcflag_t __hscore_lflag( struct termios* ts ) { return ts->c_lflag; }
490 __hscore_poke_lflag( struct termios* ts, tcflag_t t ) { ts->c_lflag = t; }
492 INLINE unsigned char*
493 __hscore_ptr_c_cc( struct termios* ts )
494 { return (unsigned char*) &ts->c_cc; }
498 __hscore_sizeof_termios( void )
500 #ifndef mingw32_TARGET_OS
501 return sizeof(struct termios);
508 __hscore_sizeof_sigset_t( void )
510 #ifndef mingw32_TARGET_OS
511 return sizeof(sigset_t);
518 __hscore_echo( void )
529 __hscore_tcsanow( void )
540 __hscore_icanon( void )
549 INLINE int __hscore_vmin( void )
558 INLINE int __hscore_vtime( void )
567 INLINE int __hscore_sigttou( void )
576 INLINE int __hscore_sig_block( void )
585 INLINE int __hscore_sig_setmask( void )
595 __hscore_f_getfl( void )
605 __hscore_f_setfl( void )
614 INLINE int __hscore_hs_fileno (FILE *f) { return fileno (f); }
616 #ifndef mingw32_TARGET_OS
617 INLINE int __hsposix_SIGABRT() { return SIGABRT; }
618 INLINE int __hsposix_SIGALRM() { return SIGALRM; }
619 INLINE int __hsposix_SIGBUS() { return SIGBUS; }
620 INLINE int __hsposix_SIGCHLD() { return SIGCHLD; }
621 INLINE int __hsposix_SIGCONT() { return SIGCONT; }
622 INLINE int __hsposix_SIGFPE() { return SIGFPE; }
623 INLINE int __hsposix_SIGHUP() { return SIGHUP; }
624 INLINE int __hsposix_SIGILL() { return SIGILL; }
625 INLINE int __hsposix_SIGINT() { return SIGINT; }
626 INLINE int __hsposix_SIGKILL() { return SIGKILL; }
627 INLINE int __hsposix_SIGPIPE() { return SIGPIPE; }
628 INLINE int __hsposix_SIGQUIT() { return SIGQUIT; }
629 INLINE int __hsposix_SIGSEGV() { return SIGSEGV; }
630 INLINE int __hsposix_SIGSTOP() { return SIGSTOP; }
631 INLINE int __hsposix_SIGTERM() { return SIGTERM; }
632 INLINE int __hsposix_SIGTSTP() { return SIGTSTP; }
633 INLINE int __hsposix_SIGTTIN() { return SIGTTIN; }
634 INLINE int __hsposix_SIGTTOU() { return SIGTTOU; }
635 INLINE int __hsposix_SIGUSR1() { return SIGUSR1; }
636 INLINE int __hsposix_SIGUSR2() { return SIGUSR2; }
638 INLINE int __hsposix_SIGPOLL() { return SIGPOLL; }
640 INLINE int __hsposix_SIGPROF() { return SIGPROF; }
641 INLINE int __hsposix_SIGSYS() { return SIGSYS; }
642 INLINE int __hsposix_SIGTRAP() { return SIGTRAP; }
643 INLINE int __hsposix_SIGURG() { return SIGURG; }
644 INLINE int __hsposix_SIGVTALRM() { return SIGVTALRM; }
645 INLINE int __hsposix_SIGXCPU() { return SIGXCPU; }
646 INLINE int __hsposix_SIGXFSZ() { return SIGXFSZ; }
648 INLINE int __hsposix_SIG_BLOCK() { return SIG_BLOCK; }
649 INLINE int __hsposix_SIG_UNBLOCK() { return SIG_SETMASK; }
650 INLINE int __hsposix_SIG_SETMASK() { return SIG_UNBLOCK; }
651 #endif /* mingw32_TARGET_OS */
653 #endif /* __HSBASE_H__ */