[project @ 2005-01-28 23:33:57 by krasimir]
[ghc-base.git] / include / HsBase.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The University of Glasgow 2001-2004
4  *
5  * Definitions for package `base' which are visible in Haskell land.
6  *
7  * ---------------------------------------------------------------------------*/
8
9 #ifndef __HSBASE_H__
10 #define __HSBASE_H__
11
12 #include "ghcconfig.h"
13
14 #include "HsBaseConfig.h"
15
16 /* ultra-evil... */
17 #undef PACKAGE_BUGREPORT
18 #undef PACKAGE_NAME
19 #undef PACKAGE_STRING
20 #undef PACKAGE_TARNAME
21 #undef PACKAGE_VERSION
22
23 #include "HsFFI.h"
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <math.h>
28
29 #if HAVE_SYS_TYPES_H
30 #include <sys/types.h>
31 #endif
32 #if HAVE_UNISTD_H
33 #include <unistd.h>
34 #endif
35 #if HAVE_SYS_STAT_H
36 #include <sys/stat.h>
37 #endif
38 #if HAVE_FCNTL_H
39 # include <fcntl.h>
40 #endif
41 #if HAVE_TERMIOS_H
42 #include <termios.h>
43 #endif
44 #if HAVE_SIGNAL_H
45 #include <signal.h>
46 /* Ultra-ugly: OpenBSD uses broken macros for sigemptyset and sigfillset (missing casts) */
47 #if __OpenBSD__
48 #undef sigemptyset
49 #undef sigfillset
50 #endif
51 #endif
52 #if HAVE_ERRNO_H
53 #include <errno.h>
54 #endif
55 #if HAVE_STRING_H
56 #include <string.h>
57 #endif
58 #if HAVE_DIRENT_H
59 #include <dirent.h>
60 #endif
61 #if HAVE_UTIME_H
62 #include <utime.h>
63 #endif
64 #if HAVE_SYS_UTSNAME_H
65 #include <sys/utsname.h>
66 #endif
67 #if HAVE_GETTIMEOFDAY
68 #  if HAVE_SYS_TIME_H
69 #   include <sys/time.h>
70 #  endif
71 #elif HAVE_GETCLOCK
72 # if HAVE_SYS_TIMERS_H
73 #  define POSIX_4D9 1
74 #  include <sys/timers.h>
75 # endif
76 #endif
77 #if HAVE_TIME_H
78 #include <time.h>
79 #endif
80 #if HAVE_SYS_TIMEB_H
81 #include <sys/timeb.h>
82 #endif
83 #if HAVE_WINDOWS_H
84 #include <windows.h>
85 #endif
86 #if HAVE_SYS_TIMES_H
87 #include <sys/times.h>
88 #endif
89 #if HAVE_WINSOCK_H && defined(mingw32_HOST_OS)
90 #include <winsock.h>
91 #endif
92 #if HAVE_LIMITS_H
93 #include <limits.h>
94 #endif
95 #if HAVE_WCTYPE_H
96 #include <wctype.h>
97 #endif
98
99 #if !defined(mingw32_HOST_OS) && !defined(irix_HOST_OS)
100 # if HAVE_SYS_RESOURCE_H
101 #  include <sys/resource.h>
102 # endif
103 #endif
104
105 #ifdef hpux_HOST_OS
106 #include <sys/syscall.h>
107 #define getrusage(a, b)  syscall(SYS_GETRUSAGE, a, b)
108 #define HAVE_GETRUSAGE
109 #endif
110
111 /* For System */
112 #if HAVE_SYS_WAIT_H
113 #include <sys/wait.h>
114 #endif
115 #if HAVE_VFORK_H
116 #include <vfork.h>
117 #endif
118 #include "lockFile.h"
119 #include "dirUtils.h"
120
121 #include "runProcess.h"
122
123 #if defined(mingw32_HOST_OS)
124 #include <io.h>
125 #include <fcntl.h>
126 #include "timeUtils.h"
127 #include <shlobj.h>
128 #include <share.h>
129 #endif
130
131 #if HAVE_SYS_SELECT_H
132 #include <sys/select.h>
133 #endif
134
135 /* in inputReady.c */
136 int inputReady(int fd, int msecs, int isSock);
137
138 /* in Signals.c */
139 extern HsInt nocldstop;
140
141 #if !defined(mingw32_HOST_OS)
142 /* in execvpe.c */
143 extern int execvpe(char *name, char *const argv[], char **envp);
144 extern void pPrPr_disableITimers (void);
145 #endif
146
147 /* -----------------------------------------------------------------------------
148    64-bit operations, defined in longlong.c
149    -------------------------------------------------------------------------- */
150
151 #ifdef SUPPORT_LONG_LONGS
152
153 StgInt stg_gtWord64 (StgWord64, StgWord64);
154 StgInt stg_geWord64 (StgWord64, StgWord64);
155 StgInt stg_eqWord64 (StgWord64, StgWord64);
156 StgInt stg_neWord64 (StgWord64, StgWord64);
157 StgInt stg_ltWord64 (StgWord64, StgWord64);
158 StgInt stg_leWord64 (StgWord64, StgWord64);
159
160 StgInt stg_gtInt64 (StgInt64, StgInt64);
161 StgInt stg_geInt64 (StgInt64, StgInt64);
162 StgInt stg_eqInt64 (StgInt64, StgInt64);
163 StgInt stg_neInt64 (StgInt64, StgInt64);
164 StgInt stg_ltInt64 (StgInt64, StgInt64);
165 StgInt stg_leInt64 (StgInt64, StgInt64);
166
167 StgWord64 stg_remWord64  (StgWord64, StgWord64);
168 StgWord64 stg_quotWord64 (StgWord64, StgWord64);
169
170 StgInt64 stg_remInt64    (StgInt64, StgInt64);
171 StgInt64 stg_quotInt64   (StgInt64, StgInt64);
172 StgInt64 stg_negateInt64 (StgInt64);
173 StgInt64 stg_plusInt64   (StgInt64, StgInt64);
174 StgInt64 stg_minusInt64  (StgInt64, StgInt64);
175 StgInt64 stg_timesInt64  (StgInt64, StgInt64);
176
177 StgWord64 stg_and64  (StgWord64, StgWord64);
178 StgWord64 stg_or64   (StgWord64, StgWord64);
179 StgWord64 stg_xor64  (StgWord64, StgWord64);
180 StgWord64 stg_not64  (StgWord64);
181
182 StgWord64 stg_uncheckedShiftL64   (StgWord64, StgInt);
183 StgWord64 stg_uncheckedShiftRL64  (StgWord64, StgInt);
184 StgInt64  stg_uncheckedIShiftL64  (StgInt64, StgInt);
185 StgInt64  stg_uncheckedIShiftRL64 (StgInt64, StgInt);
186 StgInt64  stg_uncheckedIShiftRA64 (StgInt64, StgInt);
187
188 StgInt64  stg_intToInt64    (StgInt);
189 StgInt    stg_int64ToInt    (StgInt64);
190 StgWord64 stg_int64ToWord64 (StgInt64);
191
192 StgWord64 stg_wordToWord64  (StgWord);
193 StgWord   stg_word64ToWord  (StgWord64);
194 StgInt64  stg_word64ToInt64 (StgWord64);
195
196 StgInt64  stg_integerToInt64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
197 StgWord64 stg_integerToWord64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da);
198
199 #endif /* SUPPORT_LONG_LONGS */
200
201 /* -----------------------------------------------------------------------------
202    INLINE functions.
203
204    These functions are given as inlines here for when compiling via C,
205    but we also generate static versions into the cbits library for
206    when compiling to native code.
207    -------------------------------------------------------------------------- */
208
209 #ifndef INLINE
210 # if defined(_MSC_VER)
211 #  define INLINE extern __inline
212 # elif defined(__HUGS__)
213 #  define INLINE INLINE_ONLY
214 # else
215 #  define INLINE extern inline
216 # endif
217 #endif
218
219 INLINE int __hscore_get_errno(void) { return errno; }
220 INLINE void __hscore_set_errno(int e) { errno = e; }
221
222 #if !defined(_MSC_VER)
223 INLINE int __hscore_s_isreg(m)  { return S_ISREG(m);  }
224 INLINE int __hscore_s_isdir(m)  { return S_ISDIR(m);  }
225 INLINE int __hscore_s_isfifo(m) { return S_ISFIFO(m); }
226 INLINE int __hscore_s_isblk(m)  { return S_ISBLK(m);  }
227 INLINE int __hscore_s_ischr(m)  { return S_ISCHR(m);  }
228 #ifdef S_ISSOCK
229 INLINE int __hscore_s_issock(m) { return S_ISSOCK(m); }
230 #endif
231 #endif
232
233 #if !defined(mingw32_HOST_OS) && !defined(_MSC_VER)
234 INLINE int
235 __hscore_sigemptyset( sigset_t *set )
236 { return sigemptyset(set); }
237
238 INLINE int
239 __hscore_sigfillset( sigset_t *set )
240 { return sigfillset(set); }
241
242 INLINE int
243 __hscore_sigaddset( sigset_t * set, int s )
244 { return sigaddset(set,s); }
245
246 INLINE int
247 __hscore_sigdelset( sigset_t * set, int s )
248 { return sigdelset(set,s); }
249
250 INLINE int
251 __hscore_sigismember( sigset_t * set, int s )
252 { return sigismember(set,s); }
253 #endif
254
255 INLINE void *
256 __hscore_memcpy_dst_off( char *dst, int dst_off, char *src, size_t sz )
257 { return memcpy(dst+dst_off, src, sz); }
258
259 INLINE void *
260 __hscore_memcpy_src_off( char *dst, char *src, int src_off, size_t sz )
261 { return memcpy(dst, src+src_off, sz); }
262
263 INLINE HsBool
264 __hscore_supportsTextMode()
265 {
266 #if defined(mingw32_HOST_OS)
267   return HS_BOOL_FALSE;
268 #else
269   return HS_BOOL_TRUE;
270 #endif
271 }
272
273 INLINE HsInt
274 __hscore_bufsiz()
275 {
276   return BUFSIZ;
277 }
278
279 INLINE HsInt
280 __hscore_seek_cur()
281 {
282   return SEEK_CUR;
283 }
284
285 INLINE HsInt
286 __hscore_o_binary()
287 {
288 #if defined(_MSC_VER)
289   return O_BINARY;
290 #else
291   return CONST_O_BINARY;
292 #endif
293 }
294
295 INLINE int
296 __hscore_o_rdonly()
297 {
298 #ifdef O_RDONLY
299   return O_RDONLY;
300 #else
301   return 0;
302 #endif
303 }
304
305 INLINE int
306 __hscore_o_wronly( void )
307 {
308 #ifdef O_WRONLY
309   return O_WRONLY;
310 #else
311   return 0;
312 #endif
313 }
314
315 INLINE int
316 __hscore_o_rdwr( void )
317 {
318 #ifdef O_RDWR
319   return O_RDWR;
320 #else
321   return 0;
322 #endif
323 }
324
325 INLINE int
326 __hscore_o_append( void )
327 {
328 #ifdef O_APPEND
329   return O_APPEND;
330 #else
331   return 0;
332 #endif
333 }
334
335 INLINE int
336 __hscore_o_creat( void )
337 {
338 #ifdef O_CREAT
339   return O_CREAT;
340 #else
341   return 0;
342 #endif
343 }
344
345 INLINE int
346 __hscore_o_excl( void )
347 {
348 #ifdef O_EXCL
349   return O_EXCL;
350 #else
351   return 0;
352 #endif
353 }
354
355 INLINE int
356 __hscore_o_trunc( void )
357 {
358 #ifdef O_TRUNC
359   return O_TRUNC;
360 #else
361   return 0;
362 #endif
363 }
364
365 INLINE int
366 __hscore_o_noctty( void )
367 {
368 #ifdef O_NOCTTY
369   return O_NOCTTY;
370 #else
371   return 0;
372 #endif
373 }
374
375 INLINE int
376 __hscore_o_nonblock( void )
377 {
378 #ifdef O_NONBLOCK
379   return O_NONBLOCK;
380 #else
381   return 0;
382 #endif
383 }
384
385 INLINE HsInt
386 __hscore_seek_set( void )
387 {
388   return SEEK_SET;
389 }
390
391 INLINE HsInt
392 __hscore_seek_end( void )
393 {
394   return SEEK_END;
395 }
396
397 INLINE int
398 __hscore_ftruncate( int fd, off_t where )
399 {
400 #if defined(HAVE_FTRUNCATE)
401   return ftruncate(fd,where);
402 #elif defined(HAVE__CHSIZE)
403   return _chsize(fd,where);
404 #else
405 #error at least ftruncate or _chsize functions are required to build
406 #endif
407 }
408
409 INLINE HsInt
410 __hscore_setmode( HsInt fd, HsBool toBin )
411 {
412 #if defined(mingw32_HOST_OS) || defined(_MSC_VER)
413   return setmode(fd,(toBin == HS_BOOL_TRUE) ? _O_BINARY : _O_TEXT);
414 #else
415   return 0;
416 #endif
417 }
418
419 INLINE HsInt
420 __hscore_PrelHandle_write( HsInt fd, HsAddr ptr, HsInt off, int sz )
421 {
422   return write(fd,(char *)ptr + off, sz);
423 }
424
425 INLINE HsInt
426 __hscore_PrelHandle_read( HsInt fd, HsAddr ptr, HsInt off, int sz )
427 {
428   return read(fd,(char *)ptr + off, sz);
429
430 }
431
432 #if defined(mingw32_HOST_OS) || defined(_MSC_VER)
433 INLINE HsInt
434 __hscore_PrelHandle_send( HsInt fd, HsAddr ptr, HsInt off, int sz )
435 {
436     return send(fd,(char *)ptr + off, sz, 0);
437 }
438
439 INLINE HsInt
440 __hscore_PrelHandle_recv( HsInt fd, HsAddr ptr, HsInt off, int sz )
441 {
442     return recv(fd,(char *)ptr + off, sz, 0);
443 }
444 #endif
445
446 #if defined(mingw32_HOST_OS) || defined(_MSC_VER)
447 INLINE long *
448 __hscore_Time_ghcTimezone( void ) { return &_timezone; }
449
450 INLINE char **
451 __hscore_Time_ghcTzname( void ) { return _tzname; }
452 #endif
453
454 INLINE HsInt
455 __hscore_mkdir( HsAddr pathName, HsInt mode )
456 {
457 #if defined(mingw32_HOST_OS) || defined(_MSC_VER)
458   return mkdir(pathName);
459 #else
460   return mkdir(pathName,mode);
461 #endif
462 }
463
464 INLINE HsInt
465 __hscore_lstat( HsAddr fname, HsAddr st )
466 {
467 #if HAVE_LSTAT
468   return lstat((const char*)fname, (struct stat*)st);
469 #else
470   return stat((const char*)fname, (struct stat*)st);
471 #endif
472 }
473
474 #ifdef PATH_MAX
475 /* A size that will contain many path names, but not necessarily all
476  * (PATH_MAX is not defined on systems with unlimited path length,
477  * e.g. the Hurd).
478  */
479 INLINE HsInt __hscore_long_path_size() { return PATH_MAX; }
480 #else
481 INLINE HsInt __hscore_long_path_size() { return 4096; }
482 #endif
483
484 #ifdef R_OK
485 INLINE mode_t __hscore_R_OK() { return R_OK; }
486 #endif
487 #ifdef W_OK
488 INLINE mode_t __hscore_W_OK() { return W_OK; }
489 #endif
490 #ifdef X_OK
491 INLINE mode_t __hscore_X_OK() { return X_OK; }
492 #endif
493
494 #ifdef S_IRUSR
495 INLINE mode_t __hscore_S_IRUSR() { return S_IRUSR; }
496 #endif
497 #ifdef S_IWUSR
498 INLINE mode_t __hscore_S_IWUSR() { return S_IWUSR; }
499 #endif
500 #ifdef S_IXUSR
501 INLINE mode_t __hscore_S_IXUSR() { return S_IXUSR; }
502 #endif
503
504 INLINE HsAddr
505 __hscore_d_name( struct dirent* d )
506 {
507   return (HsAddr)(d->d_name);
508 }
509
510 INLINE HsInt
511 __hscore_end_of_dir( void )
512 {
513   return READDIR_ERRNO_EOF;
514 }
515
516 INLINE void
517 __hscore_free_dirent(HsAddr dEnt)
518 {
519 #if HAVE_READDIR_R
520   free(dEnt);
521 #endif
522 }
523
524 INLINE HsInt
525 __hscore_sizeof_stat( void )
526 {
527   return sizeof(struct stat);
528 }
529
530 INLINE time_t __hscore_st_mtime ( struct stat* st ) { return st->st_mtime; }
531 INLINE off_t  __hscore_st_size  ( struct stat* st ) { return st->st_size; }
532 #if !defined(_MSC_VER)
533 INLINE mode_t __hscore_st_mode  ( struct stat* st ) { return st->st_mode; }
534 #endif
535
536 #if HAVE_TERMIOS_H
537 INLINE tcflag_t __hscore_lflag( struct termios* ts ) { return ts->c_lflag; }
538
539 INLINE void
540 __hscore_poke_lflag( struct termios* ts, tcflag_t t ) { ts->c_lflag = t; }
541
542 INLINE unsigned char*
543 __hscore_ptr_c_cc( struct termios* ts )
544 { return (unsigned char*) &ts->c_cc; }
545
546 INLINE HsInt
547 __hscore_sizeof_termios( void )
548 {
549 #ifndef mingw32_HOST_OS
550   return sizeof(struct termios);
551 #else
552   return 0;
553 #endif
554 }
555 #endif
556
557 #if !defined(mingw32_HOST_OS) && !defined(_MSC_VER)
558 INLINE HsInt
559 __hscore_sizeof_sigset_t( void )
560 {
561   return sizeof(sigset_t);
562 }
563 #endif
564
565 INLINE int
566 __hscore_echo( void )
567 {
568 #ifdef ECHO
569   return ECHO;
570 #else
571   return 0;
572 #endif
573
574 }
575
576 INLINE int
577 __hscore_tcsanow( void )
578 {
579 #ifdef TCSANOW
580   return TCSANOW;
581 #else
582   return 0;
583 #endif
584
585 }
586
587 INLINE int
588 __hscore_icanon( void )
589 {
590 #ifdef ICANON
591   return ICANON;
592 #else
593   return 0;
594 #endif
595 }
596
597 INLINE int __hscore_vmin( void )
598 {
599 #ifdef VMIN
600   return VMIN;
601 #else
602   return 0;
603 #endif
604 }
605
606 INLINE int __hscore_vtime( void )
607 {
608 #ifdef VTIME
609   return VTIME;
610 #else
611   return 0;
612 #endif
613 }
614
615 INLINE int __hscore_sigttou( void )
616 {
617 #ifdef SIGTTOU
618   return SIGTTOU;
619 #else
620   return 0;
621 #endif
622 }
623
624 INLINE int __hscore_sig_block( void )
625 {
626 #ifdef SIG_BLOCK
627   return SIG_BLOCK;
628 #else
629   return 0;
630 #endif
631 }
632
633 INLINE int __hscore_sig_setmask( void )
634 {
635 #ifdef SIG_SETMASK
636   return SIG_SETMASK;
637 #else
638   return 0;
639 #endif
640 }
641
642 INLINE int
643 __hscore_f_getfl( void )
644 {
645 #ifdef F_GETFL
646   return F_GETFL;
647 #else
648   return 0;
649 #endif
650 }
651
652 INLINE int
653 __hscore_f_setfl( void )
654 {
655 #ifdef F_SETFL
656   return F_SETFL;
657 #else
658   return 0;
659 #endif
660 }
661
662 // defined in rts/RtsStartup.c.
663 extern void* __hscore_get_saved_termios(int fd);
664 extern void __hscore_set_saved_termios(int fd, void* ts);
665
666 INLINE int __hscore_hs_fileno (FILE *f) { return fileno (f); }
667
668 #if !defined(mingw32_HOST_OS) && !defined(_MSC_VER)
669 INLINE int __hsposix_SIGABRT()   { return SIGABRT; }
670 INLINE int __hsposix_SIGALRM()   { return SIGALRM; }
671 INLINE int __hsposix_SIGBUS()    { return SIGBUS; }
672 INLINE int __hsposix_SIGCHLD()   { return SIGCHLD; }
673 INLINE int __hsposix_SIGCONT()   { return SIGCONT; }
674 INLINE int __hsposix_SIGFPE()    { return SIGFPE; }
675 INLINE int __hsposix_SIGHUP()    { return SIGHUP; }
676 INLINE int __hsposix_SIGILL()    { return SIGILL; }
677 INLINE int __hsposix_SIGINT()    { return SIGINT; }
678 INLINE int __hsposix_SIGKILL()   { return SIGKILL; }
679 INLINE int __hsposix_SIGPIPE()   { return SIGPIPE; }
680 INLINE int __hsposix_SIGQUIT()   { return SIGQUIT; }
681 INLINE int __hsposix_SIGSEGV()   { return SIGSEGV; }
682 INLINE int __hsposix_SIGSTOP()   { return SIGSTOP; }
683 INLINE int __hsposix_SIGTERM()   { return SIGTERM; }
684 INLINE int __hsposix_SIGTSTP()   { return SIGTSTP; }
685 INLINE int __hsposix_SIGTTIN()   { return SIGTTIN; }
686 INLINE int __hsposix_SIGTTOU()   { return SIGTTOU; }
687 INLINE int __hsposix_SIGUSR1()   { return SIGUSR1; }
688 INLINE int __hsposix_SIGUSR2()   { return SIGUSR2; }
689 #ifdef SIGPOLL
690 INLINE int __hsposix_SIGPOLL()   { return SIGPOLL; }
691 #endif
692 INLINE int __hsposix_SIGPROF()   { return SIGPROF; }
693 INLINE int __hsposix_SIGSYS()    { return SIGSYS; }
694 INLINE int __hsposix_SIGTRAP()   { return SIGTRAP; }
695 INLINE int __hsposix_SIGURG()    { return SIGURG; }
696 INLINE int __hsposix_SIGVTALRM() { return SIGVTALRM; }
697 INLINE int __hsposix_SIGXCPU()   { return SIGXCPU; }
698 INLINE int __hsposix_SIGXFSZ()   { return SIGXFSZ; }
699
700 INLINE int __hsposix_SIG_BLOCK()   { return SIG_BLOCK; }
701 INLINE int __hsposix_SIG_UNBLOCK() { return SIG_UNBLOCK; }
702 INLINE int __hsposix_SIG_SETMASK() { return SIG_SETMASK; }
703
704 #endif /* mingw32_HOST_OS */
705
706 INLINE int __hscore_open(char *file, int how, mode_t mode) {
707 #ifdef mingw32_HOST_OS
708         if ((how & O_WRONLY) || (how & O_RDWR) || (how & O_APPEND))
709           return _sopen(file,how,_SH_DENYRW,mode);
710         else
711           return _sopen(file,how,_SH_DENYWR,mode);
712 #else
713         return open(file,how,mode);
714 #endif
715 }
716
717 // These are wrapped because on some OSs (eg. Linux) they are
718 // macros which redirect to the 64-bit-off_t versions when large file
719 // support is enabled.
720 //
721 INLINE off_t __hscore_lseek(int fd, off_t off, int whence) {
722         return (lseek(fd,off,whence));
723 }
724
725 INLINE int __hscore_stat(char *file, struct stat *buf) {
726         return (stat(file,buf));
727 }
728
729 INLINE int __hscore_fstat(int fd, struct stat *buf) {
730         return (fstat(fd,buf));
731 }
732
733 // select-related stuff
734
735 #if !defined(mingw32_HOST_OS)
736 INLINE void hsFD_CLR(int fd, fd_set *fds) { FD_CLR(fd, fds); }
737 INLINE int  hsFD_ISSET(int fd, fd_set *fds) { return FD_ISSET(fd, fds); }
738 INLINE void hsFD_SET(int fd, fd_set *fds) { FD_SET(fd, fds); }
739 INLINE int  sizeof_fd_set(void) { return sizeof(fd_set); }
740 extern void hsFD_ZERO(fd_set *fds);
741 #endif
742
743 // gettimeofday()-related
744
745 #if !defined(mingw32_HOST_OS)
746 #define TICK_FREQ  50
747
748 INLINE HsInt sizeofTimeVal(void) { return sizeof(struct timeval); }
749
750 INLINE HsInt getTicksOfDay(void)
751 {
752     struct timeval tv;
753     gettimeofday(&tv, (struct timezone *) NULL);
754     return (tv.tv_sec * TICK_FREQ +
755             tv.tv_usec * TICK_FREQ / 1000000);
756 }
757
758 INLINE void setTimevalTicks(struct timeval *p, HsInt ticks)
759 {
760     p->tv_sec  = ticks / TICK_FREQ;
761     p->tv_usec = (ticks % TICK_FREQ) * (1000000 / TICK_FREQ);
762 }
763 #endif // !defined(mingw32_HOST_OS)
764
765 // Directory-related
766
767 #if defined(mingw32_HOST_OS)
768
769 /* Make sure we've got the reqd CSIDL_ constants in scope;
770  * w32api header files are lagging a bit in defining the full set.
771  */
772 #if !defined(CSIDL_APPDATA)
773 #define CSIDL_APPDATA 0x001a
774 #endif
775 #if !defined(CSIDL_PERSONAL)
776 #define CSIDL_PERSONAL 0x0005
777 #endif
778 #if !defined(CSIDL_PROFILE)
779 #define CSIDL_PROFILE 0x0028
780 #endif
781 #if !defined(CSIDL_WINDOWS)
782 #define CSIDL_WINDOWS 0x0024
783 #endif
784
785 INLINE int __hscore_CSIDL_PROFILE()  { return CSIDL_PROFILE;  }
786 INLINE int __hscore_CSIDL_APPDATA()  { return CSIDL_APPDATA;  }
787 INLINE int __hscore_CSIDL_WINDOWS()  { return CSIDL_WINDOWS;  }
788 INLINE int __hscore_CSIDL_PERSONAL() { return CSIDL_PERSONAL; }
789 #endif
790
791 /* ToDo: write a feature test that doesn't assume 'environ' to
792  *    be in scope at link-time. */
793 extern char** environ;
794 INLINE char **__hscore_environ() { return environ; }
795
796 #endif /* __HSBASE_H__ */
797