Support for reading/writing files via FileInputStream and FileOutputStream.java classes.
[IRC.git] / Robust / src / Runtime / file.c
1 #include <fcntl.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <sys/uio.h>
5 #include <unistd.h>
6 #include "structdefs.h"
7 #include "mem.h"
8
9
10 void ___FileOutputStream______nativeWrite____I__AR_B(int fd, struct ArrayObject * ao) {
11   int length=ao->___length___;
12   char * string= (((char *)& ao->___length___)+sizeof(int));
13   int status=write(fd, string, length);
14 }
15
16 void ___FileOutputStream______nativeClose____I(int fd) {
17   close(fd);
18 }
19
20 int ___FileOutputStream______nativeOpen_____AR_B(struct ArrayObject * ao) {
21   int length=ao->___length___;
22   char* filename= (((char *)& ao->___length___)+sizeof(int));
23   int fd=open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU);
24   return fd;
25 }
26
27 int ___FileInputStream______nativeOpen_____AR_B(struct ArrayObject * ao) {
28   int length=ao->___length___;
29   char* filename= (((char *)& ao->___length___)+sizeof(int));
30   int fd=open(filename, O_RDONLY, 0);
31   return fd;
32 }
33
34 void ___FileInputStream______nativeClose____I(int fd) {
35   close(fd);
36 }
37
38 int ___FileInputStream______nativeRead____I__AR_B_I(int fd, struct ArrayObject * ao, int numBytes) {
39   int toread=ao->___length___;
40   char* string= (((char *)& ao->___length___)+sizeof(int));
41   int status;
42
43   if (numBytes<toread)
44     toread=numBytes;
45
46   status=read(fd, string, toread);
47   return status;
48 }