i32
This commit is contained in:
@@ -16,7 +16,7 @@ bool dir_exists(const char* path){
|
||||
(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); // file is a directory
|
||||
#else
|
||||
struct stat stats;
|
||||
int rez=stat(path, &stats);
|
||||
i32 rez=stat(path, &stats);
|
||||
return (bool)(
|
||||
(rez!=-1) & // file exists
|
||||
(S_ISDIR(stats.st_mode))); // file is a directory
|
||||
|
||||
@@ -19,7 +19,7 @@ bool file_exists(const char* path){
|
||||
!(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); // file is not directory
|
||||
#else
|
||||
struct stat stats;
|
||||
int rez=stat(path, &stats);
|
||||
i32 rez=stat(path, &stats);
|
||||
return (bool)(
|
||||
(rez!=-1) & // file exists
|
||||
!(S_ISDIR(stats.st_mode))); // file is not directory
|
||||
@@ -68,36 +68,36 @@ Maybe file_close(File* file){
|
||||
safethrow(ERR_IO,;);
|
||||
|
||||
Maybe file_writeChar(File* file, char byte){
|
||||
int rezult=fputc(byte, file);
|
||||
i32 rezult=fputc(byte, file);
|
||||
ioWriteCheck();
|
||||
return MaybeNull;
|
||||
}
|
||||
|
||||
Maybe file_writeBuffer(File* file, char* buffer, uint64 length){
|
||||
int rezult=0;
|
||||
for(uint64 i=0; i<length && !rezult; i++)
|
||||
Maybe file_writeBuffer(File* file, char* buffer, u64 length){
|
||||
i32 rezult=0;
|
||||
for(u64 i=0; i<length && !rezult; i++)
|
||||
rezult=fputc(buffer[i], file);
|
||||
ioWriteCheck();
|
||||
return MaybeNull;
|
||||
}
|
||||
|
||||
Maybe file_writeCptr(File* file, char* cptr){
|
||||
int rezult=fputs(cptr, file);
|
||||
i32 rezult=fputs(cptr, file);
|
||||
ioWriteCheck();
|
||||
return MaybeNull;
|
||||
}
|
||||
|
||||
|
||||
Maybe file_readChar(File* file){
|
||||
int rezult=fgetc(file);
|
||||
i32 rezult=fgetc(file);
|
||||
if(feof(file)) safethrow(ERR_IO_EOF,;);
|
||||
if(ferror(file)) safethrow(ERR_IO,;);
|
||||
return SUCCESS(UniUInt64(rezult));
|
||||
}
|
||||
|
||||
Maybe file_readBuffer(File* file, char* buffer, uint64 length){
|
||||
int rezult=0;
|
||||
uint64 i=0;
|
||||
Maybe file_readBuffer(File* file, char* buffer, u64 length){
|
||||
i32 rezult=0;
|
||||
u64 i=0;
|
||||
for(; i<length && rezult!=EOF; i++){
|
||||
rezult=fgetc(file);
|
||||
buffer[i]=(char)rezult;
|
||||
@@ -107,11 +107,11 @@ Maybe file_readBuffer(File* file, char* buffer, uint64 length){
|
||||
}
|
||||
|
||||
Maybe file_readAll(File* file, char** allBytes){
|
||||
int rezult=0;
|
||||
i32 rezult=0;
|
||||
char buffer[256];
|
||||
string bufStr={.ptr=buffer, .length=sizeof(buffer)};
|
||||
StringBuilder* sb=StringBuilder_create();
|
||||
uint64 i=0;
|
||||
u64 i=0;
|
||||
while(true){
|
||||
rezult=fgetc(file);
|
||||
if(rezult==EOF){
|
||||
|
||||
@@ -48,7 +48,7 @@ Maybe file_writeChar(File* file, char byte);
|
||||
/// @param buffer bytes to write
|
||||
/// @param length buffer length
|
||||
/// @return Maybe<void>
|
||||
Maybe file_writeBuffer(File* file, char* buffer, uint64 length);
|
||||
Maybe file_writeBuffer(File* file, char* buffer, u64 length);
|
||||
|
||||
/// @brief writes all cstring array content to file
|
||||
/// @param cptr zero-terminated cstring
|
||||
@@ -63,12 +63,12 @@ Maybe file_readChar(File* file);
|
||||
/// @brief reads byte array of specofied length
|
||||
/// @param buffer buffer that will be filled with file bytes
|
||||
/// @param length buffer length
|
||||
/// @return Maybe<uint64> total number of successfully read bytes (<=length)
|
||||
Maybe file_readBuffer(File* file, char* buffer, uint64 length);
|
||||
/// @return Maybe<u64> total number of successfully read bytes (<=length)
|
||||
Maybe file_readBuffer(File* file, char* buffer, u64 length);
|
||||
|
||||
/// @brief reads all bytes from file
|
||||
/// @param allBytes ptr to the file's content will be pushed there
|
||||
/// @return Maybe<uint64> total number of successfully read bytes
|
||||
/// @return Maybe<u64> total number of successfully read bytes
|
||||
Maybe file_readAll(File* file, char** allBytes);
|
||||
|
||||
#if __cplusplus
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#include "filesystem.h"
|
||||
|
||||
char* __path_concat(uint16 n, ...){
|
||||
char* __path_concat(u16 n, ...){
|
||||
char** parts=(char**)malloc(n*sizeof(char*));
|
||||
uint32* lengths=malloc(n*sizeof(uint32));
|
||||
uint32 totalLength=0;
|
||||
u32* lengths=malloc(n*sizeof(u32));
|
||||
u32 totalLength=0;
|
||||
|
||||
// reading args from va_list
|
||||
va_list vl;
|
||||
va_start(vl, n);
|
||||
for(uint16 i=0; i<n; i++){
|
||||
for(u16 i=0; i<n; i++){
|
||||
char* part=va_arg(vl,char*);
|
||||
int16 length=cptr_length(part);
|
||||
i16 length=cptr_length(part);
|
||||
parts[i]=part;
|
||||
lengths[i]=length;
|
||||
totalLength+=length;
|
||||
@@ -23,7 +23,7 @@ char* __path_concat(uint16 n, ...){
|
||||
totality[totalLength]=0;
|
||||
|
||||
// copying content of all strings to rezult
|
||||
uint16 k=0;
|
||||
u16 k=0;
|
||||
for(; k<n-1; k++){
|
||||
memcopy(parts[k], totality, lengths[k]);
|
||||
totality+=lengths[k];
|
||||
@@ -56,8 +56,8 @@ Maybe path_throwIfEscapes(const char* path){
|
||||
|
||||
char* path_parentDir(char* dir){
|
||||
char* copy=cptr_copy(dir);
|
||||
uint32 length=cptr_length(copy);
|
||||
int i=cptr_lastIndexOfChar(copy,path_sep);
|
||||
u32 length=cptr_length(copy);
|
||||
i32 i=cptr_lastIndexOfChar(copy,path_sep);
|
||||
if(i==length-1){
|
||||
copy[length-1]=0;
|
||||
i=cptr_lastIndexOfChar(copy,path_sep);
|
||||
|
||||
@@ -14,7 +14,7 @@ static const char path_sep='/';
|
||||
static const char path_notSep='\\';
|
||||
#endif
|
||||
|
||||
char* __path_concat(uint16 n, ...);
|
||||
char* __path_concat(u16 n, ...);
|
||||
/// @brief merges path parts together and places <path_sep> between them
|
||||
/// @return new cstr
|
||||
#define path_concat(PATH_PARTS...) __path_concat(count_args(PATH_PARTS), PATH_PARTS)
|
||||
|
||||
Reference in New Issue
Block a user