add more comments
[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 #include "runtime.h"
9
10 void CALL12(___FileOutputStream______nativeWrite____I__AR_B, int fd, int fd, struct ArrayObject * ___array___) {
11   int length=VAR(___array___)->___length___;
12   char * string= (((char *)& VAR(___array___)->___length___)+sizeof(int));
13   int status=write(fd, string, length);
14 }
15
16 void CALL11(___FileOutputStream______nativeClose____I, int fd, int fd) {
17   close(fd);
18 }
19
20 void CALL11(___FileOutputStream______nativeFlush____I, int fd, int fd) {
21   fsync(fd);
22 }
23
24 int CALL01(___FileOutputStream______nativeOpen_____AR_B, struct ArrayObject * ___filename___) {
25   int length=VAR(___filename___)->___length___;
26   char* filename= (((char *)& VAR(___filename___)->___length___)+sizeof(int));
27   int fd=open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU);
28   return fd;
29 }
30
31 int CALL01(___FileOutputStream______nativeAppend_____AR_B, struct ArrayObject * ___filename___) {
32   int length=VAR(___filename___)->___length___;
33   char* filename= (((char *)& VAR(___filename___)->___length___)+sizeof(int));
34   int fd=open(filename, O_WRONLY|O_CREAT|O_APPEND, S_IRWXU);
35   return fd;
36 }
37
38 int CALL01(___FileInputStream______nativeOpen_____AR_B, struct ArrayObject * ___filename___) {
39   int length=VAR(___filename___)->___length___;
40   char* filename= (((char *)& VAR(___filename___)->___length___)+sizeof(int));
41   int fd=open(filename, O_RDONLY, 0);
42   return fd;
43 }
44
45 void CALL11(___FileInputStream______nativeClose____I, int fd, int fd) {
46   close(fd);
47 }
48
49 int CALL23(___FileInputStream______nativeRead____I__AR_B_I, int fd, int numBytes, int fd, struct ArrayObject * ___array___, int numBytes) {
50   int toread=VAR(___array___)->___length___;
51   char* string= (((char *)& VAR(___array___)->___length___)+sizeof(int));
52   int status;
53
54   if (numBytes<toread)
55     toread=numBytes;
56
57   status=read(fd, string, toread);
58   return status;
59 }
60
61 long long CALL01(___File______nativeLength_____AR_B, struct ArrayObject * ___pathname___) {
62   int length=VAR(___pathname___)->___length___;
63   char* filename= (((char *)& VAR(___pathname___)->___length___)+sizeof(int));
64   struct stat st;
65   stat(filename, &st);
66   return st.st_size;
67 }