X-Git-Url: http://nitlanguage.org diff --git a/c_src/core__file._ffi.c b/c_src/core__file._ffi.c index 6b734d5..9fc9c87 100644 --- a/c_src/core__file._ffi.c +++ b/c_src/core__file._ffi.c @@ -11,63 +11,79 @@ #else #define PRINT_ERROR(...) fprintf(stderr, __VA_ARGS__) #endif -#define Array_of_Int_length file___Array_of_Int_length -#define Array_of_Int__index file___Array_of_Int__index -long file___NativeFile_io_close___impl( FILE* self ) +#define Array_of_Int_length core__file___Array_of_Int_length +#define Array_of_Int__index core__file___Array_of_Int__index +#line 36 "../lib/core/file.nit" + + +#ifdef _WIN32 + #include +#endif +long core__file___NativeFile_io_close___impl( FILE* self ) { -#line 1396 "../lib/core/file.nit" +#line 1524 "../lib/core/file.nit" return fclose(self); } -long file___NativeFile_set_buffering_type___impl( FILE* self, long buf_length, long mode ) +long core__file___NativeFile_set_buffering_type___impl( FILE* self, long buf_length, long mode ) { -#line 1416 "../lib/core/file.nit" +#line 1544 "../lib/core/file.nit" - return setvbuf(self, NULL, mode, buf_length); + return setvbuf(self, NULL, (int)mode, buf_length); } -long file___NativeFile_io_read___impl( FILE* self, char* buf, long len ) +long core__file___NativeFile_io_read___impl( FILE* self, char* buf, long len ) { -#line 1383 "../lib/core/file.nit" +#line 1506 "../lib/core/file.nit" return fread(buf, 1, len, self); } -int file___NativeFile_ferror___impl( FILE* self ) +int core__file___NativeFile_ferror___impl( FILE* self ) { -#line 1408 "../lib/core/file.nit" +#line 1536 "../lib/core/file.nit" return ferror(self); } -long file___NativeFile_io_write___impl( FILE* self, char* buf, long from, long len ) +long core__file___NativeFile_io_write___impl( FILE* self, char* buf, long from, long len ) { -#line 1387 "../lib/core/file.nit" +#line 1510 "../lib/core/file.nit" - return fwrite(buf+from, 1, len, self); + size_t res = fwrite(buf+from, 1, len, self); +#ifdef _WIN32 + // Force flushing buffer because end of line does not trigger a flush + fflush(self); +#endif + return (long)res; } -long file___Sys_buffer_mode_line___impl( Sys self ) +long core__file___Sys_buffer_mode_line___impl( Sys self ) { -#line 1464 "../lib/core/file.nit" +#line 1592 "../lib/core/file.nit" return _IONBF; } -int file___NativeFileStat_is_dir___impl( struct stat * self ) +int core__file___NativeFileStat_is_dir___impl( struct stat * self ) { -#line 1363 "../lib/core/file.nit" +#line 1474 "../lib/core/file.nit" return S_ISDIR(self->st_mode); } -int file___NativeString_file_exists___impl( char* self ) +int core__file___CString_file_exists___impl( char* self ) { -#line 1301 "../lib/core/file.nit" +#line 1387 "../lib/core/file.nit" +#ifdef _WIN32 + DWORD attribs = GetFileAttributesA(self); + return attribs != INVALID_FILE_ATTRIBUTES; +#else FILE *hdl = fopen(self,"r"); if(hdl != NULL){ fclose(hdl); } return hdl != NULL; +#endif } - struct stat * file___NativeString_file_stat___impl( char* self ) + struct stat * core__file___CString_file_stat___impl( char* self ) { -#line 1309 "../lib/core/file.nit" +#line 1400 "../lib/core/file.nit" struct stat buff; @@ -78,19 +94,34 @@ int file___NativeString_file_exists___impl( char* self ) } return 0; } -char* file___NativeString_file_realpath___impl( char* self ) +char* core__file___CString_file_realpath___impl( char* self ) { -#line 1338 "../lib/core/file.nit" +#line 1440 "../lib/core/file.nit" + - return realpath(self, NULL); } -int file___NativeString_file_mkdir___impl( char* self ) +#ifdef _WIN32 + DWORD len = GetFullPathName(self, 0, NULL, NULL); + char *buf = malloc(len+1); // FIXME don't leak memory + len = GetFullPathName(self, len+1, buf, NULL); + return buf; +#else + return realpath(self, NULL); +#endif + } +int core__file___CString_file_mkdir___impl( char* self, long mode ) { -#line 1328 "../lib/core/file.nit" +#line 1424 "../lib/core/file.nit" + - return !mkdir(self, 0777); } -char* file___NativeDir_readdir___impl( DIR* self ) +#ifdef _WIN32 + return !mkdir(self); +#else + return !mkdir(self, mode); +#endif + } +char* core__file___NativeDir_readdir___impl( DIR* self ) { -#line 1441 "../lib/core/file.nit" +#line 1569 "../lib/core/file.nit" struct dirent *de; @@ -98,43 +129,43 @@ char* file___NativeDir_readdir___impl( DIR* self ) if (!de) return NULL; return de->d_name; } -void file___NativeDir_closedir___impl( DIR* self ) +void core__file___NativeDir_closedir___impl( DIR* self ) { -#line 1438 "../lib/core/file.nit" +#line 1566 "../lib/core/file.nit" closedir(self); } - FILE* file___new_NativeFile_io_open_read___impl( char* path ) + FILE* core__file___new_NativeFile_io_open_read___impl( char* path ) { -#line 1420 "../lib/core/file.nit" +#line 1548 "../lib/core/file.nit" return fopen(path, "r"); } - FILE* file___new_NativeFile_io_open_write___impl( char* path ) + FILE* core__file___new_NativeFile_io_open_write___impl( char* path ) { -#line 1422 "../lib/core/file.nit" +#line 1550 "../lib/core/file.nit" return fopen(path, "w"); } - FILE* file___new_NativeFile_native_stdin___impl( ) + FILE* core__file___new_NativeFile_native_stdin___impl( ) { -#line 1424 "../lib/core/file.nit" +#line 1552 "../lib/core/file.nit" return stdin; } - FILE* file___new_NativeFile_native_stdout___impl( ) + FILE* core__file___new_NativeFile_native_stdout___impl( ) { -#line 1426 "../lib/core/file.nit" +#line 1554 "../lib/core/file.nit" return stdout; } - FILE* file___new_NativeFile_native_stderr___impl( ) + FILE* core__file___new_NativeFile_native_stderr___impl( ) { -#line 1428 "../lib/core/file.nit" +#line 1556 "../lib/core/file.nit" return stderr; } - DIR* file___new_NativeDir_opendir___impl( char* path ) + DIR* core__file___new_NativeDir_opendir___impl( char* path ) { -#line 1435 "../lib/core/file.nit" +#line 1563 "../lib/core/file.nit" return opendir(path); } -char* file___Sys_native_getcwd___impl( Sys self ) +char* core__file___Sys_native_getcwd___impl( Sys self ) { -#line 1584 "../lib/core/file.nit" +#line 1714 "../lib/core/file.nit" return getcwd(NULL, 0); }