[project @ 1999-03-01 14:46:42 by sewardj]
[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
11 int nh_stdin ( void )
12 {
13    errno = 0;
14    return (int)stdin;
15 }
16
17 int nh_stdout ( void )
18 {
19    errno = 0;
20    return (int)stdout;
21 }
22
23 int nh_open ( char* fname, int wr )
24 {
25    FILE* f;
26    errno = 0;
27    f = fopen ( fname, (wr==0) ? "r":  ((wr==1) ? "w" : "a") );
28    return (int)f;
29 }
30
31 void nh_close ( FILE* f )
32 {
33    errno = 0;
34    fflush ( f );
35    fclose ( f );
36 }
37
38 void nh_write ( FILE* f, int c )
39 {
40    errno = 0;
41    fputc(c,f);
42    fflush(f);
43 }
44
45 int nh_read ( FILE* f )
46 {
47    errno = 0;
48    return fgetc(f);
49 }
50
51 int nh_errno ( void )
52 {
53    return errno;
54 }
55
56 int nh_malloc ( int n )
57 {
58    char* p = malloc(n);
59    assert(p);
60    return (int)p;
61 }
62
63 void nh_free ( int n )
64 {
65    free ( (char*)n );
66 }
67
68 void nh_assign ( int p, int offset, int ch )
69 {
70    ((char*)p)[offset] = (char)ch;
71 }