Compare commits

..

No commits in common. "5fb2db2380b678381ef455a18c8210a6a3314e60" and "b8017197129eb4c7d0b36605fe686622a2d97a42" have entirely different histories.

5 changed files with 3 additions and 32 deletions

View File

@ -38,12 +38,11 @@ static inline Array_ Array_copy(Array_ src){
#define struct_castTo_Array(STRUCT_PTR) Array_construct_size((STRUCT_PTR), sizeof(*STRUCT_PTR))
///@return a[0..n]
static inline Array(u8) Array_sliceBefore(Array(u8) a, u32 n){
return Array_construct_size(a.data, n);
}
///@return a[n...]
static inline Array(u8) Array_sliceAfter(Array(u8) a, u32 n){
return Array_construct_size((u8*)a.data + n, a.size - n);
}

View File

@ -93,4 +93,4 @@ typedef struct Result_ {
}\
} while(0)
#define try_assert(EXPR) if(!(EXPR)) { Return RESULT_ERROR(("try_assert(" #EXPR ")"), false); }
#define try_assert(EXPR) if(!(EXPR)) { Return RESULT_ERROR((#EXPR), false); }

View File

@ -62,10 +62,6 @@ Result(FILE*) file_open(cstr file_name, cstr fopen_mode);
Result(FILE*) file_openOrCreateReadWrite(cstr file_name);
bool file_exists(cstr path);
///@return current position in file
Result(i64) file_tellPos(FILE* f);
///@return total size of file
Result(i64) file_getSize(FILE* f);
@ -75,7 +71,6 @@ typedef enum SeekOrigin {
SeekOrigin_End = SEEK_END,
} SeekOrigin;
/// @brief changes current position in file
Result(void) file_seek(FILE* f, i64 offset, SeekOrigin origin);

View File

@ -59,14 +59,3 @@ str hex_to_str(Array(u8) buf, bool uppercase);
/// @brief removes blank characters from start and end of the line
void str_trim(str* line, bool set_zero_at_end);
///@return s[0..n]
static inline str str_sliceBefore(str s, u32 n){
return str_construct(s.data, n, false);
}
///@return s[n...]
static inline str str_sliceAfter(str s, u32 n){
return str_construct(s.data + n, s.size - n, s.isZeroTerminated);
}

View File

@ -47,7 +47,7 @@ Result(FILE*) file_openOrCreateReadWrite(cstr file_name){
Result(i64) file_tellPos(FILE* f){
Result(i64) file_getSize(FILE* f){
i64 r = IFWIN(_ftelli64, ftello64)(f);
if(r < 0){
return RESULT_ERROR_ERRNO();
@ -64,18 +64,6 @@ Result(void) file_seek(FILE* f, i64 offset, SeekOrigin origin){
return RESULT_VOID;
}
Result(i64) file_getSize(FILE* f){
Deferral(4);
// get current position
try(i64 original_pos, i, file_tellPos(f));
// seek to end
try_void(file_seek(f, 0, SeekOrigin_End));
try(i64 size, i, file_tellPos(f));
// restore original position
try_void(file_seek(f, original_pos, SeekOrigin_Start));
Return RESULT_VALUE(i, size);
}
Result(void) file_writeStructs(FILE* f, const void* src, u64 struct_size, u64 count){
u64 r = fwrite(src, struct_size, count, f);