diff -r 9b9420041d8e -r 378b5ab86f77 dav/system.c --- 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 #include #include -#include #include #include #include @@ -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