1 /* -----------------------------------------------------------------------------
2 * $Id: HsBase.h,v 1.7 2002/04/02 15:33:34 sof Exp $
4 * (c) The University of Glasgow 2001-2002
6 * Definitions for package `core' which are visible in Haskell land.
8 * ---------------------------------------------------------------------------*/
19 #ifdef HAVE_SYS_TYPES_H
20 #include <sys/types.h>
25 #ifdef HAVE_SYS_STAT_H
49 #if defined(HAVE_GETTIMEOFDAY)
50 # ifdef HAVE_SYS_TIME_H
51 # include <sys/time.h>
53 #elif defined(HAVE_GETCLOCK)
54 # ifdef HAVE_SYS_TIMERS_H
56 # include <sys/timers.h>
59 #if defined(HAVE_TIME_H)
62 #ifdef HAVE_SYS_TIMEB_H
63 #include <sys/timeb.h>
68 #ifdef HAVE_SYS_TIMES_H
69 #include <sys/times.h>
71 #if defined(HAVE_WINSOCK_H) && defined(__MINGW32__)
78 #if !defined(mingw32_TARGET_OS) && !defined(irix_TARGET_OS)
79 # if defined(HAVE_SYS_RESOURCE_H)
80 # include <sys/resource.h>
85 #include <sys/syscall.h>
86 #define getrusage(a, b) syscall(SYS_GETRUSAGE, a, b)
87 #define HAVE_GETRUSAGE
91 #ifdef HAVE_SYS_WAIT_H
101 #if defined(__MINGW32__)
104 #include "timeUtils.h"
111 HsInt
systemCmd(HsAddr cmd
);
113 /* in inputReady.c */
114 int inputReady(int fd
, int msecs
, int isSock
);
116 /* -----------------------------------------------------------------------------
117 64-bit operations, defined in longlong.c
118 -------------------------------------------------------------------------- */
120 #ifdef SUPPORT_LONG_LONGS
122 StgInt
stg_gtWord64 (StgWord64
, StgWord64
);
123 StgInt
stg_geWord64 (StgWord64
, StgWord64
);
124 StgInt
stg_eqWord64 (StgWord64
, StgWord64
);
125 StgInt
stg_neWord64 (StgWord64
, StgWord64
);
126 StgInt
stg_ltWord64 (StgWord64
, StgWord64
);
127 StgInt
stg_leWord64 (StgWord64
, StgWord64
);
129 StgInt
stg_gtInt64 (StgInt64
, StgInt64
);
130 StgInt
stg_geInt64 (StgInt64
, StgInt64
);
131 StgInt
stg_eqInt64 (StgInt64
, StgInt64
);
132 StgInt
stg_neInt64 (StgInt64
, StgInt64
);
133 StgInt
stg_ltInt64 (StgInt64
, StgInt64
);
134 StgInt
stg_leInt64 (StgInt64
, StgInt64
);
136 StgWord64
stg_remWord64 (StgWord64
, StgWord64
);
137 StgWord64
stg_quotWord64 (StgWord64
, StgWord64
);
139 StgInt64
stg_remInt64 (StgInt64
, StgInt64
);
140 StgInt64
stg_quotInt64 (StgInt64
, StgInt64
);
141 StgInt64
stg_negateInt64 (StgInt64
);
142 StgInt64
stg_plusInt64 (StgInt64
, StgInt64
);
143 StgInt64
stg_minusInt64 (StgInt64
, StgInt64
);
144 StgInt64
stg_timesInt64 (StgInt64
, StgInt64
);
146 StgWord64
stg_and64 (StgWord64
, StgWord64
);
147 StgWord64
stg_or64 (StgWord64
, StgWord64
);
148 StgWord64
stg_xor64 (StgWord64
, StgWord64
);
149 StgWord64
stg_not64 (StgWord64
);
151 StgWord64
stg_uncheckedShiftL64 (StgWord64
, StgInt
);
152 StgWord64
stg_uncheckedShiftRL64 (StgWord64
, StgInt
);
153 StgInt64
stg_uncheckedIShiftL64 (StgInt64
, StgInt
);
154 StgInt64
stg_uncheckedIShiftRL64 (StgInt64
, StgInt
);
155 StgInt64
stg_uncheckedIShiftRA64 (StgInt64
, StgInt
);
157 StgInt64
stg_intToInt64 (StgInt
);
158 StgInt
stg_int64ToInt (StgInt64
);
159 StgWord64
stg_int64ToWord64 (StgInt64
);
161 StgWord64
stg_wordToWord64 (StgWord
);
162 StgWord
stg_word64ToWord (StgWord64
);
163 StgInt64
stg_word64ToInt64 (StgWord64
);
165 StgInt64
stg_integerToInt64 (StgInt sa
, StgByteArray
/* Really: mp_limb_t* */ da
);
166 StgWord64
stg_integerToWord64 (StgInt sa
, StgByteArray
/* Really: mp_limb_t* */ da
);
168 #endif /* SUPPORT_LONG_LONGS */
170 /* -----------------------------------------------------------------------------
173 These functions are given as inlines here for when compiling via C,
174 but we also generate static versions into the cbits library for
175 when compiling to native code.
176 -------------------------------------------------------------------------- */
179 #define INLINE extern inline
182 #if !defined(mingw32_TARGET_OS)
184 __hscore_sigaddset( sigset_t
* set
, int s
)
185 { return sigaddset(set
,s
); }
188 INLINE
int __hscore_s_isreg(m
) { return S_ISREG(m
); }
189 INLINE
int __hscore_s_isdir(m
) { return S_ISDIR(m
); }
190 INLINE
int __hscore_s_isfifo(m
) { return S_ISFIFO(m
); }
191 INLINE
int __hscore_s_isblk(m
) { return S_ISBLK(m
); }
192 INLINE
int __hscore_s_ischr(m
) { return S_ISCHR(m
); }
194 INLINE
int __hscore_s_issock(m
) { return S_ISSOCK(m
); }
197 #ifndef mingw32_TARGET_OS
199 __hscore_sigemptyset( sigset_t
*set
)
200 { sigemptyset(set
); }
204 __hscore_memcpy_dst_off( char *dst
, int dst_off
, char *src
, size_t sz
)
205 { return memcpy(dst
+dst_off
, src
, sz
); }
208 __hscore_memcpy_src_off( char *dst
, char *src
, int src_off
, size_t sz
)
209 { return memcpy(dst
, src
+src_off
, sz
); }
212 __hscore_supportsTextMode()
214 #if defined(mingw32_TARGET_OS)
215 return HS_BOOL_FALSE
;
254 __hscore_o_wronly( void )
264 __hscore_o_rdwr( void )
274 __hscore_o_append( void )
284 __hscore_o_creat( void )
294 __hscore_o_excl( void )
304 __hscore_o_trunc( void )
314 __hscore_o_noctty( void )
324 __hscore_o_nonblock( void )
334 __hscore_seek_set( void )
340 __hscore_seek_end( void )
346 __hscore_setmode( HsInt fd
, HsBool toBin
)
348 #if defined(__MINGW32__)
349 return setmode(fd
,(toBin
== HS_BOOL_TRUE
) ? _O_BINARY
: _O_TEXT
);
356 __hscore_PrelHandle_write( HsInt fd
, HsBool isSock
, HsAddr ptr
,
359 #if defined(__MINGW32__)
361 return send(fd
,ptr
+ off
, sz
, 0);
364 return write(fd
,ptr
+ off
, sz
);
368 __hscore_PrelHandle_read( HsInt fd
, HsBool isSock
, HsAddr ptr
,
371 #if defined(__MINGW32__)
373 return recv(fd
,ptr
+ off
, sz
, 0);
376 return read(fd
,ptr
+ off
, sz
);
380 #if defined(__MINGW32__)
382 __hscore_Time_ghcTimezone( void ) { return &_timezone
; }
385 __hscore_Time_ghcTzname( void ) { return _tzname
; }
389 __hscore_mkdir( HsAddr pathName
, HsInt mode
)
391 #if defined(__MINGW32__)
392 return mkdir(pathName
);
394 return mkdir(pathName
,mode
);
399 __hscore_lstat( HsAddr fname
, HsAddr st
)
402 return lstat((const char*)fname
, (struct stat
*)st
);
404 return stat((const char*)fname
, (struct stat
*)st
);
408 INLINE HsInt
__hscore_path_max() { return PATH_MAX
; }
410 INLINE mode_t
__hscore_R_OK() { return R_OK
; }
411 INLINE mode_t
__hscore_W_OK() { return W_OK
; }
412 INLINE mode_t
__hscore_X_OK() { return X_OK
; }
414 INLINE mode_t
__hscore_S_IRUSR() { return S_IRUSR
; }
415 INLINE mode_t
__hscore_S_IWUSR() { return S_IWUSR
; }
416 INLINE mode_t
__hscore_S_IXUSR() { return S_IXUSR
; }
419 __hscore_d_name( struct dirent
* d
)
421 #ifndef mingw32_TARGET_OS
422 return (HsAddr
)(&d
->d_name
);
424 return (HsAddr
)(d
->d_name
);
429 __hscore_end_of_dir( void )
431 #ifndef mingw32_TARGET_OS
439 __hscore_free_dirent(HsAddr dEnt
)
447 __hscore_sizeof_stat( void )
449 return sizeof(struct stat
);
452 INLINE
time_t __hscore_st_mtime ( struct stat
* st
) { return st
->st_mtime
; }
453 INLINE off_t
__hscore_st_size ( struct stat
* st
) { return st
->st_size
; }
454 INLINE mode_t
__hscore_st_mode ( struct stat
* st
) { return st
->st_mode
; }
457 INLINE tcflag_t
__hscore_lflag( struct termios
* ts
) { return ts
->c_lflag
; }
460 __hscore_poke_lflag( struct termios
* ts
, tcflag_t t
) { ts
->c_lflag
= t
; }
462 INLINE
unsigned char*
463 __hscore_ptr_c_cc( struct termios
* ts
)
464 { return (unsigned char*) &ts
->c_cc
; }
468 __hscore_sizeof_termios( void )
470 #ifndef mingw32_TARGET_OS
471 return sizeof(struct termios
);
478 __hscore_sizeof_sigset_t( void )
480 #ifndef mingw32_TARGET_OS
481 return sizeof(sigset_t
);
488 __hscore_echo( void )
499 __hscore_tcsanow( void )
510 __hscore_icanon( void )
519 INLINE
int __hscore_vmin( void )
528 INLINE
int __hscore_vtime( void )
537 INLINE
int __hscore_sigttou( void )
546 INLINE
int __hscore_sig_block( void )
555 INLINE
int __hscore_sig_setmask( void )
565 __hscore_f_getfl( void )
575 __hscore_f_setfl( void )