README: Update libgc's URL
[nit.git] / c_src / core__file._ffi.c
1 /*
2 Extern implementation of Nit module file
3 */
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <stdint.h>
7 #include "core__file._ffi.h"
8 #ifdef ANDROID
9 #include <android/log.h>
10 #define PRINT_ERROR(...) (void)__android_log_print(ANDROID_LOG_WARN, "Nit", __VA_ARGS__)
11 #else
12 #define PRINT_ERROR(...) fprintf(stderr, __VA_ARGS__)
13 #endif
14 #define Array_of_Int_length file___Array_of_Int_length
15 #define Array_of_Int__index file___Array_of_Int__index
16 long file___NativeFile_io_close___impl( FILE* self )
17 {
18 #line 1396 "../lib/core/file.nit"
19
20 return fclose(self); }
21 long file___NativeFile_set_buffering_type___impl( FILE* self, long buf_length, long mode )
22 {
23 #line 1416 "../lib/core/file.nit"
24
25
26 return setvbuf(self, NULL, mode, buf_length);
27 }
28 long file___NativeFile_io_read___impl( FILE* self, char* buf, long len )
29 {
30 #line 1383 "../lib/core/file.nit"
31
32
33 return fread(buf, 1, len, self);
34 }
35 int file___NativeFile_ferror___impl( FILE* self )
36 {
37 #line 1408 "../lib/core/file.nit"
38
39 return ferror(self); }
40 long file___NativeFile_io_write___impl( FILE* self, char* buf, long from, long len )
41 {
42 #line 1387 "../lib/core/file.nit"
43
44
45 return fwrite(buf+from, 1, len, self);
46 }
47 long file___Sys_buffer_mode_line___impl( Sys self )
48 {
49 #line 1464 "../lib/core/file.nit"
50
51 return _IONBF; }
52 int file___NativeFileStat_is_dir___impl( struct stat * self )
53 {
54 #line 1363 "../lib/core/file.nit"
55
56 return S_ISDIR(self->st_mode); }
57 int file___NativeString_file_exists___impl( char* self )
58 {
59 #line 1301 "../lib/core/file.nit"
60
61
62 FILE *hdl = fopen(self,"r");
63 if(hdl != NULL){
64 fclose(hdl);
65 }
66 return hdl != NULL;
67 }
68 struct stat * file___NativeString_file_stat___impl( char* self )
69 {
70 #line 1309 "../lib/core/file.nit"
71
72
73 struct stat buff;
74 if(stat(self, &buff) != -1) {
75 struct stat* stat_element;
76 stat_element = malloc(sizeof(struct stat));
77 return memcpy(stat_element, &buff, sizeof(struct stat));
78 }
79 return 0;
80 }
81 char* file___NativeString_file_realpath___impl( char* self )
82 {
83 #line 1338 "../lib/core/file.nit"
84
85 return realpath(self, NULL); }
86 int file___NativeString_file_mkdir___impl( char* self )
87 {
88 #line 1328 "../lib/core/file.nit"
89
90 return !mkdir(self, 0777); }
91 char* file___NativeDir_readdir___impl( DIR* self )
92 {
93 #line 1441 "../lib/core/file.nit"
94
95
96 struct dirent *de;
97 de = readdir(self);
98 if (!de) return NULL;
99 return de->d_name;
100 }
101 void file___NativeDir_closedir___impl( DIR* self )
102 {
103 #line 1438 "../lib/core/file.nit"
104
105 closedir(self); }
106 FILE* file___new_NativeFile_io_open_read___impl( char* path )
107 {
108 #line 1420 "../lib/core/file.nit"
109
110 return fopen(path, "r"); }
111 FILE* file___new_NativeFile_io_open_write___impl( char* path )
112 {
113 #line 1422 "../lib/core/file.nit"
114
115 return fopen(path, "w"); }
116 FILE* file___new_NativeFile_native_stdin___impl( )
117 {
118 #line 1424 "../lib/core/file.nit"
119
120 return stdin; }
121 FILE* file___new_NativeFile_native_stdout___impl( )
122 {
123 #line 1426 "../lib/core/file.nit"
124
125 return stdout; }
126 FILE* file___new_NativeFile_native_stderr___impl( )
127 {
128 #line 1428 "../lib/core/file.nit"
129
130 return stderr; }
131 DIR* file___new_NativeDir_opendir___impl( char* path )
132 {
133 #line 1435 "../lib/core/file.nit"
134
135 return opendir(path); }
136 char* file___Sys_native_getcwd___impl( Sys self )
137 {
138 #line 1584 "../lib/core/file.nit"
139
140 return getcwd(NULL, 0); }