kerep-headers
This commit is contained in:
28
kerep-headers/Filesystem/dir.h
Normal file
28
kerep-headers/Filesystem/dir.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../base/base.h"
|
||||
#include "file.h"
|
||||
|
||||
bool dir_exists(const char* path);
|
||||
///@return Maybe<void>
|
||||
Maybe dir_create(const char* path);
|
||||
///@return Maybe<void>
|
||||
Maybe dir_delete(const char* path);
|
||||
|
||||
///@return Maybe<Array_string>
|
||||
Maybe dir_getFiles(const char* path, bool recursive);
|
||||
///@return Maybe<Array_string>
|
||||
Maybe dir_getDirs(const char* path, bool recursive);
|
||||
|
||||
///@return Maybe<Array_string>
|
||||
Maybe dir_findFiles(const char* path, char* searchPattern, bool recursive);
|
||||
///@return Maybe<Array_string>
|
||||
Maybe dir_findDirs(const char* path, char* searchPattern, bool recursive);
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
75
kerep-headers/Filesystem/file.h
Normal file
75
kerep-headers/Filesystem/file.h
Normal file
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../base/base.h"
|
||||
#include "../String/string.h"
|
||||
|
||||
typedef FILE* FileHandle;
|
||||
kt_declare(FileHandle);
|
||||
|
||||
bool file_exists(const char* path);
|
||||
|
||||
///@return Maybe<void>
|
||||
Maybe file_delete(const char* path, bool recursive);
|
||||
|
||||
PACKED_ENUM(FileOpenMode,
|
||||
// open a file for reading
|
||||
FileOpenMode_Read=1,
|
||||
// (re)create a file for writing
|
||||
FileOpenMode_Write=2,
|
||||
// opens file for writing additional data to the end / creates new file
|
||||
FileOpenMode_Append=4,
|
||||
// (re)creates file for reading/writing
|
||||
FileOpenMode_ReadWrite=FileOpenMode_Read|FileOpenMode_Write,
|
||||
// opens file for readng/writing additional data to the end / creates new file
|
||||
FileOpenMode_ReadAppend=FileOpenMode_Read|FileOpenMode_Append
|
||||
)
|
||||
|
||||
/// @brief opens file
|
||||
/// @param path path to file
|
||||
/// @param mode Read/Write/Append/ReadWrite/ReadAppend
|
||||
/// @return Maybe<FileHandle>
|
||||
Maybe file_open(const char* path, FileOpenMode mode);
|
||||
|
||||
/// @brief closes file descriptor
|
||||
/// @return Maybe<void>
|
||||
Maybe file_close(FileHandle file);
|
||||
|
||||
/// @brief closes file descriptor
|
||||
/// @param byte byte to write
|
||||
/// @return Maybe<void>
|
||||
Maybe file_writeChar(FileHandle file, char byte);
|
||||
|
||||
/// @brief closes file descriptor
|
||||
/// @param buffer bytes to write
|
||||
/// @param length buffer length
|
||||
/// @return Maybe<void>
|
||||
Maybe file_writeBuffer(FileHandle file, char* buffer, u64 length);
|
||||
|
||||
/// @brief writes all cstring array content to file
|
||||
/// @param cptr zero-terminated cstring
|
||||
/// @return Maybe<void>
|
||||
Maybe file_writeCptr(FileHandle file, char* cptr);
|
||||
|
||||
|
||||
/// @brief reads single byte from file
|
||||
/// @return Maybe<char>
|
||||
Maybe file_readChar(FileHandle file);
|
||||
|
||||
/// @brief reads byte array of specofied length
|
||||
/// @param buffer buffer that will be filled with file bytes
|
||||
/// @param length buffer length
|
||||
/// @return Maybe<u64> total number of successfully read bytes (<=length)
|
||||
Maybe file_readBuffer(FileHandle 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<u64> total number of successfully read bytes
|
||||
Maybe file_readAll(FileHandle file, char** allBytes);
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
3
kerep-headers/Filesystem/filesystem.h
Normal file
3
kerep-headers/Filesystem/filesystem.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#include "path.h"
|
||||
#include "dir.h"
|
||||
#include "file.h"
|
||||
15
kerep-headers/Filesystem/io_includes.h
Normal file
15
kerep-headers/Filesystem/io_includes.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "../base/std.h"
|
||||
|
||||
#if defined(_WIN64) || defined(_WIN32)
|
||||
#define KFS_USE_WINDOWS_H 1
|
||||
#else
|
||||
#define KFS_USE_WINDOWS_H 0
|
||||
#endif
|
||||
|
||||
#if KFS_USE_WINDOWS_H
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
42
kerep-headers/Filesystem/path.h
Normal file
42
kerep-headers/Filesystem/path.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../base/base.h"
|
||||
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
static const char path_sep='\\';
|
||||
static const char path_notSep='/';
|
||||
#else
|
||||
static const char path_sep='/';
|
||||
static const char path_notSep='\\';
|
||||
#endif
|
||||
|
||||
char* __path_concat(u32 n, ...);
|
||||
/// @brief merges path parts together and puts <path_sep> between them
|
||||
/// @return new cstr
|
||||
#define path_concat(PATH_PARTS...) __path_concat(count_args(PATH_PARTS), PATH_PARTS)
|
||||
|
||||
/// @brief fixes path separators
|
||||
/// @param cstr where can be <path_notSep>
|
||||
/// @return new cstr with correct separators
|
||||
char* path_fixSeparators(const char* path);
|
||||
|
||||
#define path_resolve(PATH_PARTS...) path_fixSeparators(path_concat(PATH_PARTS))
|
||||
|
||||
/// @brief calls safethrow() if finds escape sequense in path
|
||||
/// @param path cstr where can be <..>
|
||||
/// @return Maybe<void>
|
||||
Maybe path_throwIfEscapes(const char* path);
|
||||
|
||||
///@return path of parent dir
|
||||
char* path_parentDir(char* path);
|
||||
|
||||
///@return file name
|
||||
char* path_basename(char* path, bool with_extension);
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user