Compare commits

...

3 Commits

Author SHA1 Message Date
bf56984482 try_stderrcode 2025-08-10 21:33:16 +03:00
8eeaff4245 made str_equals faster 2025-08-10 17:21:55 +03:00
a097d5aff9 header fix for linux 2025-08-10 03:22:10 +03:00
5 changed files with 18 additions and 8 deletions

View File

@@ -85,3 +85,10 @@ typedef struct Result_ {
Error_printAndExit(_rname(N).error);\ Error_printAndExit(_rname(N).error);\
};\ };\
} while(0) } while(0)
#define try_stderrcode(CALL) do {\
int r = CALL;\
if(r != 0){\
Return RESULT_ERROR(strerror(r), false);\
}\
} while(0)

View File

@@ -1,4 +1,3 @@
#include "tlibc/filesystem.h"
#include "internal.h" #include "internal.h"
bool dir_exists(cstr path){ bool dir_exists(cstr path){

View File

@@ -1,4 +1,3 @@
#include "tlibc/filesystem.h"
#include "internal.h" #include "internal.h"
bool file_exists(cstr path){ bool file_exists(cstr path){
@@ -46,6 +45,8 @@ Result(FILE*) file_openOrCreateReadWrite(cstr file_name){
return RESULT_VALUE(p, f); return RESULT_VALUE(p, f);
} }
Result(i64) file_getSize(FILE* f){ Result(i64) file_getSize(FILE* f){
i64 r = IFWIN(_ftelli64, ftello64)(f); i64 r = IFWIN(_ftelli64, ftello64)(f);
if(r < 0){ if(r < 0){

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#define _LARGEFILE64_SOURCE 1
#include "tlibc/filesystem.h" #include "tlibc/filesystem.h"
#if TLIBC_FS_USE_WINDOWS_H #if TLIBC_FS_USE_WINDOWS_H
#include <windows.h> #include <windows.h>

View File

@@ -14,12 +14,14 @@ str str_copy(str src){
bool str_equals(str s0, str s1){ bool str_equals(str s0, str s1){
if(s0.size != s1.size) if(s0.size != s1.size)
return false; return false;
/*
for(u32 i = 0; i < s0.size; i++) BENCHMARK:
if(s0.data[i] != s1.data[i]) str_equals64: 2.967s
return false; strcmp: 4.143s
strncmp: 1.611s
return true; memcmp: 0.710s
*/
return memcmp(s0.data, s1.data, s0.size) == 0;
} }
str str_reverse(str s){ str str_reverse(str s){