string and StringBuilder
This commit is contained in:
@@ -38,7 +38,7 @@ Maybe dir_create(const char* path){
|
||||
{
|
||||
char err[512];
|
||||
sprintf_s(err, sizeof(err), "can't create dicectory <%s>", path);
|
||||
safethrow(err,;);
|
||||
safethrow(err, LinearAllocator_destruct(&_al));
|
||||
}
|
||||
LinearAllocator_destruct(&_al);
|
||||
return MaybeNull;
|
||||
|
||||
@@ -53,7 +53,7 @@ Maybe file_open(const char* path, FileOpenMode mode){
|
||||
LinearAllocator _al; LinearAllocator_construct(&_al, 128);
|
||||
allocator_ptr al=&_al.base;
|
||||
if(!file)
|
||||
safethrow(cptr_concat(al, "can't open file ", (char*)path),;);
|
||||
safethrow(cptr_concat(al, "can't open file ", (char*)path), LinearAllocator_destruct(&_al));
|
||||
LinearAllocator_destruct(&_al);
|
||||
return SUCCESS(UniHeapPtr(FileHandle,file));
|
||||
}
|
||||
@@ -115,7 +115,9 @@ Maybe file_readAll(FileHandle file, char** allBytes){
|
||||
i32 rezult=0;
|
||||
char buffer[256];
|
||||
string bufStr={.ptr=buffer, .length=sizeof(buffer)};
|
||||
StringBuilder* sb=StringBuilder_create();
|
||||
StringBuilder _sb;
|
||||
StringBuilder* sb=&_sb;
|
||||
StringBuilder_construct(sb, NULL);
|
||||
u64 i=0;
|
||||
while(true){
|
||||
rezult=fgetc(file);
|
||||
|
||||
@@ -52,7 +52,8 @@ Maybe path_throwIfEscapes(const char* path){
|
||||
LinearAllocator _al; LinearAllocator_construct(&_al, 128);
|
||||
allocator_ptr al=&_al.base;
|
||||
if(cptr_contains(path,".."))
|
||||
safethrow(cptr_concat(al, "path <",path,"> uses <..>, that's not allowed"),);
|
||||
safethrow(cptr_concat(al, "path <",path,"> uses <..>, that's not allowed"),
|
||||
LinearAllocator_destruct(&_al));
|
||||
LinearAllocator_destruct(&_al);
|
||||
return MaybeNull;
|
||||
}
|
||||
@@ -83,5 +84,5 @@ char* path_basename(allocator_ptr al, char* path, bool with_extension){
|
||||
if(extIndex!=0 && extIndex!=-1)
|
||||
rezult.length=extIndex;
|
||||
}
|
||||
return string_extract(rezult);
|
||||
return string_extract(al, rezult);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user