2 Extern implementation of Nit module file
7 #include "core__file._ffi.h"
9 #include <android/log.h>
10 #define PRINT_ERROR(...) (void)__android_log_print(ANDROID_LOG_WARN, "Nit", __VA_ARGS__)
12 #define PRINT_ERROR(...) fprintf(stderr, __VA_ARGS__)
14 #define Array_of_Int_length core__file___Array_of_Int_length
15 #define Array_of_Int__index core__file___Array_of_Int__index
16 #line 36 "../lib/core/file.nit"
22 long core__file___NativeFile_io_close___impl( FILE* self
)
24 #line 1524 "../lib/core/file.nit"
26 return fclose(self
); }
27 long core__file___NativeFile_set_buffering_type___impl( FILE* self
, long buf_length
, long mode
)
29 #line 1544 "../lib/core/file.nit"
32 return setvbuf(self
, NULL
, (int)mode
, buf_length
);
34 long core__file___NativeFile_io_read___impl( FILE* self
, char* buf
, long len
)
36 #line 1506 "../lib/core/file.nit"
39 return fread(buf
, 1, len
, self
);
41 int core__file___NativeFile_ferror___impl( FILE* self
)
43 #line 1536 "../lib/core/file.nit"
45 return ferror(self
); }
46 long core__file___NativeFile_io_write___impl( FILE* self
, char* buf
, long from
, long len
)
48 #line 1510 "../lib/core/file.nit"
51 size_t res
= fwrite(buf
+from
, 1, len
, self
);
53 // Force flushing buffer because end of line does not trigger a flush
58 long core__file___Sys_buffer_mode_line___impl( Sys self
)
60 #line 1592 "../lib/core/file.nit"
63 int core__file___NativeFileStat_is_dir___impl( struct stat
* self
)
65 #line 1474 "../lib/core/file.nit"
67 return S_ISDIR(self
->st_mode
); }
68 int core__file___CString_file_exists___impl( char* self
)
70 #line 1387 "../lib/core/file.nit"
74 DWORD attribs
= GetFileAttributesA(self
);
75 return attribs
!= INVALID_FILE_ATTRIBUTES
;
77 FILE *hdl
= fopen(self
,"r");
84 struct stat
* core__file___CString_file_stat___impl( char* self
)
86 #line 1400 "../lib/core/file.nit"
90 if(stat(self
, &buff
) != -1) {
91 struct stat
* stat_element
;
92 stat_element
= malloc(sizeof(struct stat
));
93 return memcpy(stat_element
, &buff
, sizeof(struct stat
));
97 char* core__file___CString_file_realpath___impl( char* self
)
99 #line 1440 "../lib/core/file.nit"
103 DWORD len
= GetFullPathName(self
, 0, NULL
, NULL
);
104 char *buf
= malloc(len
+1); // FIXME don't leak memory
105 len
= GetFullPathName(self
, len
+1, buf
, NULL
);
108 return realpath(self
, NULL
);
111 int core__file___CString_file_mkdir___impl( char* self
, long mode
)
113 #line 1424 "../lib/core/file.nit"
119 return !mkdir(self
, mode
);
122 char* core__file___NativeDir_readdir___impl( DIR* self
)
124 #line 1569 "../lib/core/file.nit"
129 if (!de
) return NULL
;
132 void core__file___NativeDir_closedir___impl( DIR* self
)
134 #line 1566 "../lib/core/file.nit"
137 FILE* core__file___new_NativeFile_io_open_read___impl( char* path
)
139 #line 1548 "../lib/core/file.nit"
141 return fopen(path
, "r"); }
142 FILE* core__file___new_NativeFile_io_open_write___impl( char* path
)
144 #line 1550 "../lib/core/file.nit"
146 return fopen(path
, "w"); }
147 FILE* core__file___new_NativeFile_native_stdin___impl( )
149 #line 1552 "../lib/core/file.nit"
152 FILE* core__file___new_NativeFile_native_stdout___impl( )
154 #line 1554 "../lib/core/file.nit"
157 FILE* core__file___new_NativeFile_native_stderr___impl( )
159 #line 1556 "../lib/core/file.nit"
162 DIR* core__file___new_NativeDir_opendir___impl( char* path
)
164 #line 1563 "../lib/core/file.nit"
166 return opendir(path
); }
167 char* core__file___Sys_native_getcwd___impl( Sys self
)
169 #line 1714 "../lib/core/file.nit"
171 return getcwd(NULL
, 0); }