file_openOrCreateReadWrite

This commit is contained in:
2025-08-08 21:38:34 +03:00
parent 223406d4e4
commit fe9e44a660
5 changed files with 38 additions and 19 deletions

View File

@@ -26,8 +26,22 @@ bool file_exists(cstr path){
Result(FILE*) file_open(cstr file_name, cstr fopen_mode){
FILE* f = fopen(file_name, fopen_mode);
if(f == NULL){
return RESULT_ERROR_FMT("Can't open (%s) file '%s': %s",
fopen_mode, file_name, strerror(errno));
return RESULT_ERROR_FMT(
"Can't open (%s) file '%s': %s",
fopen_mode, file_name, strerror(errno));
}
return RESULT_VALUE(p, f);
}
Result(FILE*) file_openOrCreateReadWrite(cstr file_name){
FILE* f = fopen(file_name, "rb+");
if(f == NULL){
f = fopen(file_name, "wb+");
if(f == NULL){
return RESULT_ERROR_FMT(
"Can't create (%s) file: %s",
file_name, strerror(errno));
}
}
return RESULT_VALUE(p, f);
}

View File

@@ -11,7 +11,7 @@ str path_dirname(str path){
i32 sepIndex = str_seekCharReverse(path, path_sep, -1);
if(sepIndex < 0)
return path;
return STR(".");
path.size = sepIndex;
path.isZeroTerminated = false;