1 /* -----------------------------------------------------------------------------
2 * $Id: HsBase.h,v 1.8 2002/07/04 12:57:39 simonmar Exp $
4 * (c) The University of Glasgow 2001-2002
6 * Definitions for package `core' which are visible in Haskell land.
8 * ---------------------------------------------------------------------------*/
16 // The following is required on Solaris to force the POSIX versions of
17 // the various _r functions instead of the Solaris versions.
18 #ifdef solaris_TARGET_OS
19 #define _POSIX_PTHREAD_SEMANTICS
25 #ifdef HAVE_SYS_TYPES_H
26 #include <sys/types.h>
31 #ifdef HAVE_SYS_STAT_H
55 #if defined(HAVE_GETTIMEOFDAY)
56 # ifdef HAVE_SYS_TIME_H
57 # include <sys/time.h>
59 #elif defined(HAVE_GETCLOCK)
60 # ifdef HAVE_SYS_TIMERS_H
62 # include <sys/timers.h>
65 #if defined(HAVE_TIME_H)
68 #ifdef HAVE_SYS_TIMEB_H
69 #include <sys/timeb.h>
74 #ifdef HAVE_SYS_TIMES_H
75 #include <sys/times.h>
77 #if defined(HAVE_WINSOCK_H) && defined(__MINGW32__)
84 #if !defined(mingw32_TARGET_OS) && !defined(irix_TARGET_OS)
85 # if defined(HAVE_SYS_RESOURCE_H)
86 # include <sys/resource.h>
91 #include <sys/syscall.h>
92 #define getrusage(a, b) syscall(SYS_GETRUSAGE, a, b)
93 #define HAVE_GETRUSAGE
97 #ifdef HAVE_SYS_WAIT_H
103 #include "lockFile.h"
104 #include "dirUtils.h"
105 #include "errUtils.h"
107 #if defined(__MINGW32__)
110 #include "timeUtils.h"
117 HsInt systemCmd(HsAddr cmd);
119 /* in inputReady.c */
120 int inputReady(int fd, int msecs, int isSock);
122 /* -----------------------------------------------------------------------------
123 64-bit operations, defined in longlong.c
124 -------------------------------------------------------------------------- */
126 #ifdef SUPPORT_LONG_LONGS
128 StgInt stg_gtWord64 (StgWord64, StgWord64);
129 StgInt stg_geWord64 (StgWord64, StgWord64);
130 StgInt stg_eqWord64 (StgWord64, StgWord64);
131 StgInt stg_neWord64 (StgWord64, StgWord64);
132 StgInt stg_ltWord64 (StgWord64, StgWord64);
133 StgInt stg_leWord64 (StgWord64, StgWord64);
135 StgInt stg_gtInt64 (StgInt64, StgInt64);
136 StgInt stg_geInt64 (StgInt64, StgInt64);
137 StgInt stg_eqInt64 (StgInt64, StgInt64);
138 StgInt stg_neInt64 (StgInt64, StgInt64);
139 StgInt stg_ltInt64 (StgInt64, StgInt64);
140 StgInt stg_leInt64 (StgInt64, StgInt64);
142 StgWord64 stg_remWord64 (StgWord64, StgWord64);
143 StgWord64 stg_quotWord64 (StgWord64, StgWord64);
145 StgInt64 stg_remInt64 (StgInt64, StgInt64);
146 StgInt64 stg_quotInt64 (StgInt64, StgInt64);
147 StgInt64 stg_negateInt64 (StgInt64);
148 StgInt64 stg_plusInt64 (StgInt64, StgInt64);
149 StgInt64 stg_minusInt64 (StgInt64, StgInt64);
150 StgInt64 stg_timesInt64 (StgInt64, StgInt64);
152 StgWord64 stg_and64 (StgWord64, StgWord64);
153 StgWord64 stg_or64 (StgWord64, StgWord64);
154 StgWord64 stg_xor64 (StgWord64, StgWord64);
155 StgWord64 stg_not64 (StgWord64);
157 StgWord64 stg_uncheckedShiftL64 (StgWord64, StgInt);
158 StgWord64 stg_uncheckedShiftRL64 (StgWord64, StgInt);
159 StgInt64 stg_uncheckedIShiftL64 (StgInt64, StgInt);
160 StgInt64 stg_uncheckedIShiftRL64 (StgInt64, StgInt);
161 StgInt64 stg_uncheckedIShiftRA64 (StgInt64, StgInt);
163 StgInt64 stg_intToInt64 (StgInt);
164 StgInt stg_int64ToInt (StgInt64);
165 StgWord64 stg_int64ToWord64 (StgInt64);
167 StgWord64 stg_wordToWord64 (StgWord);
168 StgWord stg_word64ToWord (StgWord64);
169 StgInt64 stg_word64ToInt64 (StgWord64);
171 StgInt64 stg_integerToInt64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
172 StgWord64 stg_integerToWord64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
174 #endif /* SUPPORT_LONG_LONGS */
176 /* -----------------------------------------------------------------------------
179 These functions are given as inlines here for when compiling via C,
180 but we also generate static versions into the cbits library for
181 when compiling to native code.
182 -------------------------------------------------------------------------- */
185 #define INLINE extern inline
188 #if !defined(mingw32_TARGET_OS)
190 __hscore_sigaddset( sigset_t * set, int s )
191 { return sigaddset(set,s); }
194 INLINE int __hscore_s_isreg(m) { return S_ISREG(m); }
195 INLINE int __hscore_s_isdir(m) { return S_ISDIR(m); }
196 INLINE int __hscore_s_isfifo(m) { return S_ISFIFO(m); }
197 INLINE int __hscore_s_isblk(m) { return S_ISBLK(m); }
198 INLINE int __hscore_s_ischr(m) { return S_ISCHR(m); }
200 INLINE int __hscore_s_issock(m) { return S_ISSOCK(m); }
203 #ifndef mingw32_TARGET_OS
205 __hscore_sigemptyset( sigset_t *set )
206 { sigemptyset(set); }
210 __hscore_memcpy_dst_off( char *dst, int dst_off, char *src, size_t sz )
211 { return memcpy(dst+dst_off, src, sz); }
214 __hscore_memcpy_src_off( char *dst, char *src, int src_off, size_t sz )
215 { return memcpy(dst, src+src_off, sz); }
218 __hscore_supportsTextMode()
220 #if defined(mingw32_TARGET_OS)
221 return HS_BOOL_FALSE;
260 __hscore_o_wronly( void )
270 __hscore_o_rdwr( void )
280 __hscore_o_append( void )
290 __hscore_o_creat( void )
300 __hscore_o_excl( void )
310 __hscore_o_trunc( void )
320 __hscore_o_noctty( void )
330 __hscore_o_nonblock( void )
340 __hscore_seek_set( void )
346 __hscore_seek_end( void )
352 __hscore_setmode( HsInt fd, HsBool toBin )
354 #if defined(__MINGW32__)
355 return setmode(fd,(toBin == HS_BOOL_TRUE) ? _O_BINARY : _O_TEXT);
362 __hscore_PrelHandle_write( HsInt fd, HsBool isSock, HsAddr ptr,
365 #if defined(__MINGW32__)
367 return send(fd,ptr + off, sz, 0);
370 return write(fd,ptr + off, sz);
374 __hscore_PrelHandle_read( HsInt fd, HsBool isSock, HsAddr ptr,
377 #if defined(__MINGW32__)
379 return recv(fd,ptr + off, sz, 0);
382 return read(fd,ptr + off, sz);
386 #if defined(__MINGW32__)
388 __hscore_Time_ghcTimezone( void ) { return &_timezone; }
391 __hscore_Time_ghcTzname( void ) { return _tzname; }
395 __hscore_mkdir( HsAddr pathName, HsInt mode )
397 #if defined(__MINGW32__)
398 return mkdir(pathName);
400 return mkdir(pathName,mode);
405 __hscore_lstat( HsAddr fname, HsAddr st )
408 return lstat((const char*)fname, (struct stat*)st);
410 return stat((const char*)fname, (struct stat*)st);
414 INLINE HsInt __hscore_path_max() { return PATH_MAX; }
416 INLINE mode_t __hscore_R_OK() { return R_OK; }
417 INLINE mode_t __hscore_W_OK() { return W_OK; }
418 INLINE mode_t __hscore_X_OK() { return X_OK; }
420 INLINE mode_t __hscore_S_IRUSR() { return S_IRUSR; }
421 INLINE mode_t __hscore_S_IWUSR() { return S_IWUSR; }
422 INLINE mode_t __hscore_S_IXUSR() { return S_IXUSR; }
425 __hscore_d_name( struct dirent* d )
427 #ifndef mingw32_TARGET_OS
428 return (HsAddr)(&d->d_name);
430 return (HsAddr)(d->d_name);
435 __hscore_end_of_dir( void )
437 #ifndef mingw32_TARGET_OS
445 __hscore_free_dirent(HsAddr dEnt)
453 __hscore_sizeof_stat( void )
455 return sizeof(struct stat);
458 INLINE time_t __hscore_st_mtime ( struct stat* st ) { return st->st_mtime; }
459 INLINE off_t __hscore_st_size ( struct stat* st ) { return st->st_size; }
460 INLINE mode_t __hscore_st_mode ( struct stat* st ) { return st->st_mode; }
463 INLINE tcflag_t __hscore_lflag( struct termios* ts ) { return ts->c_lflag; }
466 __hscore_poke_lflag( struct termios* ts, tcflag_t t ) { ts->c_lflag = t; }
468 INLINE unsigned char*
469 __hscore_ptr_c_cc( struct termios* ts )
470 { return (unsigned char*) &ts->c_cc; }
474 __hscore_sizeof_termios( void )
476 #ifndef mingw32_TARGET_OS
477 return sizeof(struct termios);
484 __hscore_sizeof_sigset_t( void )
486 #ifndef mingw32_TARGET_OS
487 return sizeof(sigset_t);
494 __hscore_echo( void )
505 __hscore_tcsanow( void )
516 __hscore_icanon( void )
525 INLINE int __hscore_vmin( void )
534 INLINE int __hscore_vtime( void )
543 INLINE int __hscore_sigttou( void )
552 INLINE int __hscore_sig_block( void )
561 INLINE int __hscore_sig_setmask( void )
571 __hscore_f_getfl( void )
581 __hscore_f_setfl( void )