Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/SoftEtherVPN/libhamcore.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavide Beatrici <git@davidebeatrici.dev>2021-03-10 00:06:53 +0300
committerDavide Beatrici <git@davidebeatrici.dev>2021-03-10 00:06:53 +0300
commitc798511e419ededd0cbe34a09f2aaca5111d9576 (patch)
tree040b3dde21f4e86509087330b8b40e7fe6d1ee82 /FileSystem.c
parentafe882a6739dcb0efba5cc9fabd7647b98a9fbba (diff)
Introduce HamcoreBuild(), for building archives
Diffstat (limited to 'FileSystem.c')
-rwxr-xr-xFileSystem.c55
1 files changed, 53 insertions, 2 deletions
diff --git a/FileSystem.c b/FileSystem.c
index b691746..cb64fe5 100755
--- a/FileSystem.c
+++ b/FileSystem.c
@@ -1,13 +1,17 @@
#include "FileSystem.h"
-FILE *FileOpen(const char *path)
+#include <string.h>
+
+#include <sys/stat.h>
+
+FILE *FileOpen(const char *path, const bool write)
{
if (!path)
{
return NULL;
}
- return fopen(path, "rb");
+ return fopen(path, write ? "wb" : "rb");
}
bool FileClose(FILE *file)
@@ -30,6 +34,16 @@ bool FileRead(FILE *file, void *dst, const size_t size)
return fread(dst, 1, size, file) == size;
}
+bool FileWrite(FILE *file, const void *src, const size_t size)
+{
+ if (!file || !src || size == 0)
+ {
+ return false;
+ }
+
+ return fwrite(src, 1, size, file) == size;
+}
+
bool FileSeek(FILE *file, const size_t offset)
{
if (!file)
@@ -39,3 +53,40 @@ bool FileSeek(FILE *file, const size_t offset)
return fseek(file, offset, SEEK_SET) == 0;
}
+
+size_t FileSize(const char *path)
+{
+ if (!path)
+ {
+ return 0;
+ }
+
+ struct stat st;
+ if (stat(path, &st) == -1)
+ {
+ return 0;
+ }
+
+ return st.st_size;
+}
+
+const char *PathRelativeToBase(const char *full, const char *base)
+{
+ if (!full || !base)
+ {
+ return NULL;
+ }
+
+ if (strstr(full, base) != &full[0])
+ {
+ return NULL;
+ }
+
+ full += strlen(base);
+ if (full[0] == '/')
+ {
+ ++full;
+ }
+
+ return full;
+}