dav/system.c

changeset 789
378b5ab86f77
parent 747
efbd59642577
--- a/dav/system.c	Tue Sep 12 21:07:54 2023 +0200
+++ b/dav/system.c	Thu Sep 14 18:11:50 2023 +0200
@@ -31,7 +31,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <dirent.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <errno.h>
@@ -165,6 +164,10 @@
     return err;
 }
 
+int sys_truncate(const char* path, off_t length) {
+    return truncate(path, length);
+}
+
 #else
 /* ---------- Windows implementation ---------- */
 
@@ -507,4 +510,22 @@
     return ret;
 }
 
+int sys_truncate(const char* path, off_t length) {
+    wchar_t* wpath = path2winpath(path, FALSE, NULL);
+    if (!wpath) {
+        fprintf(stderr, "sys_truncate: cannot convert path\n");
+        return -1;
+    }
+
+    FILE* file = _wfopen(wpath, L"wb");
+    int ret = 1;
+    if (file) {
+        ret = _chsize(fileno(file), length);
+        fclose(file);
+    }
+
+    free(wpath);
+    return ret;
+}
+
 #endif

mercurial