Log the webserver requests
[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 ___FileOutputStream______nativeAppend_____AR_B(struct ArrayObject * ao) {
28   int length=ao->___length___;
29   char* filename= (((char *)& ao->___length___)+sizeof(int));
30   int fd=open(filename, O_WRONLY|O_CREAT|O_APPEND, S_IRWXU);
31   return fd;
32 }
33
34 int ___FileInputStream______nativeOpen_____AR_B(struct ArrayObject * ao) {
35   int length=ao->___length___;
36   char* filename= (((char *)& ao->___length___)+sizeof(int));
37   int fd=open(filename, O_RDONLY, 0);
38   return fd;
39 }
40
41 void ___FileInputStream______nativeClose____I(int fd) {
42   close(fd);
43 }
44
45 int ___FileInputStream______nativeRead____I__AR_B_I(int fd, struct ArrayObject * ao, int numBytes) {
46   int toread=ao->___length___;
47   char* string= (((char *)& ao->___length___)+sizeof(int));
48   int status;
49
50   if (numBytes<toread)
51     toread=numBytes;
52
53   status=read(fd, string, toread);
54   return status;
55 }
56
57 long long ___File______nativeLength_____AR_B(struct ArrayObject * ao) {
58   int length=ao->___length___;
59   char* filename= (((char *)& ao->___length___)+sizeof(int));
60   struct stat st;
61   stat(filename, &st);
62   return st.st_size;
63 }