898b41a3d11977ea2e8b0062b8137b8edc06724b
1 // Low level disk reading
2 //=======================================================================================================================
4 i64
fs_file_size( FILE *fileptr
)
6 fseek( fileptr
, 0, SEEK_END
);
7 i64 fsize
= ftell( fileptr
);
8 fseek( fileptr
, 0, SEEK_SET
);
13 void *fs_disk_open_read( const char *path
, int const reserve_end
, i64
*size
)
15 FILE *f
= fopen( path
, "rb" );
18 i64 fsize
= fs_file_size( f
);
19 void *buf
= csr_malloc( fsize
+ reserve_end
);
23 // Invalid / corrupt read
24 if( fread( buf
, 1, fsize
, f
) != fsize
)
42 char *fs_disk_load_text( const char *path
, i64
*size
)
47 if( (buf
= fs_disk_open_read( path
, 1, &fsize
)) )
58 void *csr_asset_read_s( const char *path
, i64
*size
)
60 return fs_disk_open_read( path
, 0, size
);
63 void *csr_asset_read( const char *path
)
66 return fs_disk_open_read( path
, 0, &size
);
69 char *csr_textasset_read_s( const char *path
, i64
*size
)
71 return fs_disk_load_text( path
, size
);
74 char *csr_textasset_read( const char *name
)
77 return fs_disk_load_text( name
, &size
);
80 // Find file path extension, returns NULL if no ext (0x00)
81 char *csr_findext( char *path
, char const delim
)
101 // gets rid of extension on string only left with folder/filename
102 void csr_stripext( char *path
)
107 if( !(start
= csr_findext( path
, '/' )) )
112 if( (point
= csr_findext( start
, '.' )) )
121 // Convert windows paths to unix-ish ( \something\\blahblah .. ) -> /something/blahblah/
122 void csr_path_winunix( char *path
)
136 if( *(idx
-1) == '/' && *idx
== '/') idx
++;
147 int csr_path_is_abs( char const *path
)
150 if( strlen( path
) < 2 ) return 0;
151 return path
[1] == ':';
153 if( strlen( path
) < 1 ) return 0;
154 return path
[0] == '/';
159 #define GetWorkingDir _getcwd
161 #define GetWorkingDir getcwd