1 /* -----------------------------------------------------------------------------
3 * (c) The University of Glasgow 2001-2002
5 * Definitions for package `base' which are visible in Haskell land.
7 * ---------------------------------------------------------------------------*/
20 #include <sys/types.h>
36 /* Ultra-ugly: OpenBSD uses broken macros for sigemptyset and sigfillset (missing casts) */
54 #if HAVE_SYS_UTSNAME_H
55 #include <sys/utsname.h>
59 # include <sys/time.h>
62 # if HAVE_SYS_TIMERS_H
64 # include <sys/timers.h>
71 #include <sys/timeb.h>
77 #include <sys/times.h>
79 #if HAVE_WINSOCK_H && defined(mingw32_TARGET_OS)
89 #if !defined(mingw32_TARGET_OS) && !defined(irix_TARGET_OS)
90 # if 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
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, HsAddr ptr, HsInt off, int sz )
397 return write(fd,(char *)ptr + off, sz);
401 __hscore_PrelHandle_read( HsInt fd, HsAddr ptr, HsInt off, int sz )
403 return read(fd,(char *)ptr + off, sz);
407 #if defined(mingw32_TARGET_OS) || defined(_MSC_VER)
409 __hscore_Time_ghcTimezone( void ) { return &_timezone; }
412 __hscore_Time_ghcTzname( void ) { return _tzname; }
416 __hscore_mkdir( HsAddr pathName, HsInt mode )
418 #if defined(mingw32_TARGET_OS) || defined(_MSC_VER)
419 return mkdir(pathName);
421 return mkdir(pathName,mode);
426 __hscore_lstat( HsAddr fname, HsAddr st )
429 return lstat((const char*)fname, (struct stat*)st);
431 return stat((const char*)fname, (struct stat*)st);
436 /* A size that will contain many path names, but not necessarily all
437 * (PATH_MAX is not defined on systems with unlimited path length,
440 INLINE HsInt __hscore_long_path_size() { return PATH_MAX; }
442 INLINE HsInt __hscore_long_path_size() { return 4096; }
446 INLINE mode_t __hscore_R_OK() { return R_OK; }
449 INLINE mode_t __hscore_W_OK() { return W_OK; }
452 INLINE mode_t __hscore_X_OK() { return X_OK; }
456 INLINE mode_t __hscore_S_IRUSR() { return S_IRUSR; }
459 INLINE mode_t __hscore_S_IWUSR() { return S_IWUSR; }
462 INLINE mode_t __hscore_S_IXUSR() { return S_IXUSR; }
465 #if !defined(_MSC_VER)
467 __hscore_d_name( struct dirent* d )
469 #if !defined(mingw32_TARGET_OS) && !defined(_MSC_VER)
470 return (HsAddr)(&d->d_name);
472 return (HsAddr)(d->d_name);
478 __hscore_end_of_dir( void )
480 #ifndef mingw32_TARGET_OS
488 __hscore_free_dirent(HsAddr dEnt)
496 __hscore_sizeof_stat( void )
498 return sizeof(struct stat);
501 INLINE time_t __hscore_st_mtime ( struct stat* st ) { return st->st_mtime; }
502 INLINE off_t __hscore_st_size ( struct stat* st ) { return st->st_size; }
503 #if !defined(_MSC_VER)
504 INLINE mode_t __hscore_st_mode ( struct stat* st ) { return st->st_mode; }
508 INLINE tcflag_t __hscore_lflag( struct termios* ts ) { return ts->c_lflag; }
511 __hscore_poke_lflag( struct termios* ts, tcflag_t t ) { ts->c_lflag = t; }
513 INLINE unsigned char*
514 __hscore_ptr_c_cc( struct termios* ts )
515 { return (unsigned char*) &ts->c_cc; }
518 __hscore_sizeof_termios( void )
520 #ifndef mingw32_TARGET_OS
521 return sizeof(struct termios);
528 #if !defined(mingw32_TARGET_OS) && !defined(_MSC_VER)
530 __hscore_sizeof_sigset_t( void )
532 return sizeof(sigset_t);
537 __hscore_echo( void )
548 __hscore_tcsanow( void )
559 __hscore_icanon( void )
568 INLINE int __hscore_vmin( void )
577 INLINE int __hscore_vtime( void )
586 INLINE int __hscore_sigttou( void )
595 INLINE int __hscore_sig_block( void )
604 INLINE int __hscore_sig_setmask( void )
614 __hscore_f_getfl( void )
624 __hscore_f_setfl( void )
633 // defined in rts/RtsStartup.c.
634 extern void* __hscore_get_saved_termios(int fd);
635 extern void __hscore_set_saved_termios(int fd, void* ts);
637 INLINE int __hscore_hs_fileno (FILE *f) { return fileno (f); }
639 #if !defined(mingw32_TARGET_OS) && !defined(_MSC_VER)
640 INLINE int __hsposix_SIGABRT() { return SIGABRT; }
641 INLINE int __hsposix_SIGALRM() { return SIGALRM; }
642 INLINE int __hsposix_SIGBUS() { return SIGBUS; }
643 INLINE int __hsposix_SIGCHLD() { return SIGCHLD; }
644 INLINE int __hsposix_SIGCONT() { return SIGCONT; }
645 INLINE int __hsposix_SIGFPE() { return SIGFPE; }
646 INLINE int __hsposix_SIGHUP() { return SIGHUP; }
647 INLINE int __hsposix_SIGILL() { return SIGILL; }
648 INLINE int __hsposix_SIGINT() { return SIGINT; }
649 INLINE int __hsposix_SIGKILL() { return SIGKILL; }
650 INLINE int __hsposix_SIGPIPE() { return SIGPIPE; }
651 INLINE int __hsposix_SIGQUIT() { return SIGQUIT; }
652 INLINE int __hsposix_SIGSEGV() { return SIGSEGV; }
653 INLINE int __hsposix_SIGSTOP() { return SIGSTOP; }
654 INLINE int __hsposix_SIGTERM() { return SIGTERM; }
655 INLINE int __hsposix_SIGTSTP() { return SIGTSTP; }
656 INLINE int __hsposix_SIGTTIN() { return SIGTTIN; }
657 INLINE int __hsposix_SIGTTOU() { return SIGTTOU; }
658 INLINE int __hsposix_SIGUSR1() { return SIGUSR1; }
659 INLINE int __hsposix_SIGUSR2() { return SIGUSR2; }
661 INLINE int __hsposix_SIGPOLL() { return SIGPOLL; }
663 INLINE int __hsposix_SIGPROF() { return SIGPROF; }
664 INLINE int __hsposix_SIGSYS() { return SIGSYS; }
665 INLINE int __hsposix_SIGTRAP() { return SIGTRAP; }
666 INLINE int __hsposix_SIGURG() { return SIGURG; }
667 INLINE int __hsposix_SIGVTALRM() { return SIGVTALRM; }
668 INLINE int __hsposix_SIGXCPU() { return SIGXCPU; }
669 INLINE int __hsposix_SIGXFSZ() { return SIGXFSZ; }
671 INLINE int __hsposix_SIG_BLOCK() { return SIG_BLOCK; }
672 INLINE int __hsposix_SIG_UNBLOCK() { return SIG_UNBLOCK; }
673 INLINE int __hsposix_SIG_SETMASK() { return SIG_SETMASK; }
674 #endif /* mingw32_TARGET_OS */
676 #endif /* __HSBASE_H__ */