1a3e47306f9efef2b1f01a927ccf91bf43b5f696
[ghc-hetmet.git] / ghc / lib / std / cbits / ilxstubs.c
1 /* 
2  * (c) The GHC Team 2001
3  *
4  * $Id: ilxstubs.c,v 1.2 2001/07/16 09:23:24 rrt Exp $
5  *
6  * ILX stubs for external function calls
7  */
8
9 /*
10   All foreign imports from the C standard library are stubbed out here,
11   so that they are all in the same DLL (HSstd_cbits), and the ILX code
12   generator doesn't have to be told or guess which DLL they are in.
13   Calls to the Win32 API are annotated with the DLL they come from.
14
15   The general rule is that all foreign imports are assumed to be in
16   <current_package>_cbits.dll unless a DLL is explicitly given.
17 */
18
19
20 #include "Stg.h"
21 #include "HsStd.h"
22 #include <stdlib.h>
23 #include <stddef.h>
24 #include <dirent.h>
25 #include <limits.h>
26
27 /* From the RTS */
28
29     /* StgPrimFloat Add to mini-RTS, which is put in a DLL */
30
31     /* Need to be implemented in ILX RTS */
32      /*foreign label "prog_argv" prog_argv_label :: Ptr (Ptr (Ptr CChar))
33 foreign label "prog_argc" prog_argc_label :: Ptr CInt
34 foreign label "ErrorHdrHook" errorHdrHook :: Ptr ()
35 ../PrelStable.lhs:37:foreign import unsafe freeStablePtr :: StablePtr a -> IO ()
36 ../PrelTopHandler.lhs:49:foreign import ccall "shutdownHaskellAndExit" 
37 ../PrelTopHandler.lhs:77:foreign import ccall "stackOverflow" unsafe
38 ../PrelTopHandler.lhs:80:foreign import ccall "stg_exit" unsafe */
39
40 void
41 stg_exit(I_ n)
42 {
43   fprintf(stderr, "doing stg_exit(%d)\n", n);
44   exit(n);
45 }
46
47 /* The code is in includes/Stable.h [sic] */
48 void
49 freeStablePtr(StgStablePtr sp)
50 {
51   fprintf(stderr, "Freeing stable ptr %p (NOT!)\n", sp);
52 }
53
54 void
55 shutdownHaskellAndExit(int n)
56 {
57   stg_exit(n);
58 }
59
60 void 
61 stackOverflow(void)
62 {
63 }
64
65 void
66 ErrorHdrHook (long fd)
67 {
68     const char msg[] = "\nFail: ";
69     write(fd, msg, sizeof(msg)-1);
70 }
71
72
73
74 /* Import directly from correct DLL */
75
76      /*../CPUTime.hsc:107:foreign import "GetCurrentProcess" unsafe getCurrentProcess :: IO (Ptr HANDLE)
77        ../CPUTime.hsc:108:foreign import "GetProcessTimes" unsafe getProcessTimes :: Ptr HANDLE -> Ptr FILETIME -> Ptr FILETIME -> Ptr FILETIME -> Ptr FILETIME -> IO CInt */
78
79 int s_mkdir(const char *s) { return mkdir(s); }
80 int s_chmod(const char *s, mode_t m) { return chmod(s, m); }
81 int s_access(const char *s, int m) { return access(s, m); }
82 char *s_getcwd(char *s, size_t n) { return getcwd(s, n); }
83 int s_rmdir(const char *s) { return rmdir(s); }
84 int s_chdir(const char *s) { return chdir(s); }
85 int s_unlink(const char *s) { return unlink(s); }
86 int s_rename(const char *s1, const char *s2) { return rename(s1, s2); }
87 DIR *s_opendir(const char *s) { return opendir(s); }
88 struct dirent *s_readdir(DIR *d) { return readdir(d); }
89 int s_closedir(DIR *d) { return closedir(d); }
90 int s_stat(const char *s, struct stat *buf) { return stat(s, buf); }
91 int s_fstat(int f, struct stat* buf) { return fstat(f, buf); }
92 int s_open(const char *s, int f) { return open(s, f); }
93 int s_close(int f) { return close(f); }
94 int s_write(int f, const void *buf, size_t n) { return write(f, buf, n); }
95 int s_read(int f, void *buf, size_t n) { return read(f, buf, n); }
96 int s_lseek(int f, off_t off, int w) { return lseek(f, off, w); }
97 int s_isatty(int f) { return isatty(f); }
98 void *s_memcpy(void *d, const void *s, size_t n) { return memcpy(d, s, n); }
99 void *s_memmove(void *d, const void *s, size_t n) { return memmove(d, s, n); }
100 char *s_strerror(int e) { return strerror(e); }
101 int s_setmode(int a, int b) { return setmode(a,b); }
102 void *s_malloc(size_t n) { return malloc(n); }
103 void *s_realloc(void *p, size_t n) { return realloc(p, n); }
104 void s_free(void *p) { free(p); }
105 char *s_getenv(const char *s) { return getenv(s); }
106 struct tm *s_localtime(const time_t *p) { return localtime(p); }
107 struct tm *s_gmtime(const time_t *p) { return gmtime(p); }
108 time_t s_mktime(struct tm *p) { return mktime(p); }
109 time_t s_time(time_t *p) { return time(p); }
110 void s_ftime(struct timeb *p) { ftime(p); }