[project @ 1999-06-28 16:29:45 by simonpj]
[ghc-hetmet.git] / ghc / interpreter / nHandle.c
1
2 /* This is a hack.  I totally deny writing it.  If this code breaks,
3  * you get to keep all the pieces.  JRS, 23 feb 99.
4  */
5
6 #include <stdio.h>
7 #include <errno.h>
8 #include <assert.h>
9 #include <malloc.h>
10 #include <stdlib.h>
11
12 int nh_stdin ( void )
13 {
14    errno = 0;
15    return (int)stdin;
16 }
17
18 int nh_stdout ( void )
19 {
20    errno = 0;
21    return (int)stdout;
22 }
23
24 int nh_stderr ( void )
25 {
26    errno = 0;
27    return (int)stderr;
28 }
29
30 int nh_open ( char* fname, int wr )
31 {
32    FILE* f;
33    errno = 0;
34    f = fopen ( fname, (wr==0) ? "r":  ((wr==1) ? "w" : "a") );
35    return (int)f;
36 }
37
38 void nh_close ( FILE* f )
39 {
40    errno = 0;
41    fflush ( f );
42    fclose ( f );
43 }
44
45 void nh_flush ( FILE* f )
46 {
47    errno = 0;
48    fflush ( f );
49 }
50
51 void nh_write ( FILE* f, int c )
52 {
53    errno = 0;
54    fputc(c,f);
55    fflush(f);
56 }
57
58 int nh_read ( FILE* f )
59 {
60    errno = 0;
61    return fgetc(f);
62 }
63
64 int nh_errno ( void )
65 {
66    return errno;
67 }
68
69 int nh_malloc ( int n )
70 {
71    char* p = malloc(n);
72    assert(p);
73    return (int)p;
74 }
75
76 void nh_free ( int n )
77 {
78    free ( (char*)n );
79 }
80
81 void nh_store ( int p, int ch )
82 {
83    *(char*)p = (char)ch;
84 }
85
86 int nh_load ( int p )
87 {
88    return (int)(*(char*)p);
89 }
90
91 int nh_getenv ( int p )
92 {
93    return (int)getenv ( (const char *)p );
94 }
95
96 extern int prog_argc;
97 extern char** prog_argv;
98
99 int nh_argc ( void )
100 {
101    return prog_argc;
102 }
103
104 int nh_argvb ( int argno, int offset )
105 {
106    return (int)(prog_argv[argno][offset]);
107 }