dav/system.h

Tue, 30 Dec 2025 21:27:14 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 30 Dec 2025 21:27:14 +0100
branch
dav-2
changeset 892
02ad5db5ad4d
parent 866
4a9227846234
permissions
-rw-r--r--

replace a bunch of cxBufferWrite calls with cxBufferPutString

410
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
576
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
4 * Copyright 2019 Olaf Wintermann. All rights reserved.
410
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #ifndef DAV_SYSTEM_H
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #define DAV_SYSTEM_H
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <stdio.h>
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <time.h>
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include <sys/types.h>
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include <sys/stat.h>
789
378b5ab86f77 add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 611
diff changeset
36
410
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #ifdef _WIN32
865
0b61e0164b44 implement system.h abstraction for utime()
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
39
410
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #include <Windows.h>
866
4a9227846234 fix some inconsistencies related to #297
Mike Becker <universe@uap-core.de>
parents: 865
diff changeset
41 #ifndef mode_t
789
378b5ab86f77 add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 611
diff changeset
42 #define mode_t unsigned int
866
4a9227846234 fix some inconsistencies related to #297
Mike Becker <universe@uap-core.de>
parents: 865
diff changeset
43 #endif
865
0b61e0164b44 implement system.h abstraction for utime()
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
44
0b61e0164b44 implement system.h abstraction for utime()
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
45 #include <sys/utime.h>
866
4a9227846234 fix some inconsistencies related to #297
Mike Becker <universe@uap-core.de>
parents: 865
diff changeset
46 #define SYS_UTIMBUF struct _utimbuf
4a9227846234 fix some inconsistencies related to #297
Mike Becker <universe@uap-core.de>
parents: 865
diff changeset
47 int sys_utime(const char *filename, SYS_UTIMBUF *times);
865
0b61e0164b44 implement system.h abstraction for utime()
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
48
0b61e0164b44 implement system.h abstraction for utime()
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
49 #else // not _WIN32
0b61e0164b44 implement system.h abstraction for utime()
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
50
789
378b5ab86f77 add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 611
diff changeset
51 #include <dirent.h>
865
0b61e0164b44 implement system.h abstraction for utime()
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
52
0b61e0164b44 implement system.h abstraction for utime()
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
53 #include <utime.h>
866
4a9227846234 fix some inconsistencies related to #297
Mike Becker <universe@uap-core.de>
parents: 865
diff changeset
54 #define SYS_UTIMBUF struct utimbuf
865
0b61e0164b44 implement system.h abstraction for utime()
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
55 #define sys_utime utime
0b61e0164b44 implement system.h abstraction for utime()
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
56
0b61e0164b44 implement system.h abstraction for utime()
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
57 #endif // _WIN32
410
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 #ifdef __cplusplus
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 extern "C" {
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 #endif
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 typedef struct SysDirEnt {
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 char *name;
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 } SysDirEnt;
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
66
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
67 #ifdef _WIN32
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
68 struct WinDir {
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
69 int first;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
70 HANDLE handle;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
71 WIN32_FIND_DATAW finddata;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
72 SysDirEnt *ent;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
73 };
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
74 #define SYS_DIR struct WinDir*
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
75 #define SYS_STAT struct __stat64
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
76
608
3e4c0285a868 fix build on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 582
diff changeset
77 typedef int uid_t;
3e4c0285a868 fix build on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 582
diff changeset
78 typedef int gid_t;
3e4c0285a868 fix build on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 582
diff changeset
79
611
a7c48e0dca88 implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 608
diff changeset
80 #define SYS_ISLINK(path, mode) sys_islink(path)
a7c48e0dca88 implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 608
diff changeset
81 #define SYS_LINK_EXT ".lnk"
a7c48e0dca88 implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 608
diff changeset
82
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
83 #else
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
84
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
85 typedef struct SysDir {
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
86 DIR *dir;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
87 SysDirEnt *ent;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
88 } SysDir;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
89
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
90 #define SYS_DIR SysDir*
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
91 #define SYS_STAT struct stat
611
a7c48e0dca88 implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 608
diff changeset
92
a7c48e0dca88 implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 608
diff changeset
93 #define SYS_ISLINK(p, s) S_ISLNK(s.st_mode)
a7c48e0dca88 implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 608
diff changeset
94
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
95 #endif
410
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96
582
7aec3e6cab1f fix stat_func typedef
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 581
diff changeset
97 typedef int(*stat_func)(const char*, SYS_STAT *);
581
3f9a9c80a2d2 fix that symlink config was not used in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
98
611
a7c48e0dca88 implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 608
diff changeset
99 void sys_init(void);
a7c48e0dca88 implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 608
diff changeset
100 void sys_uninit(void);
a7c48e0dca88 implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 608
diff changeset
101
410
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 void sys_freedirent(SysDirEnt *ent);
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 SYS_DIR sys_opendir(const char *path);
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 SysDirEnt* sys_readdir(SYS_DIR dir);
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 void sys_closedir(SYS_DIR dir);
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 FILE* sys_fopen(const char *path, const char *mode);
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 int sys_stat(const char *path, SYS_STAT *s);
574
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
110 int sys_lstat(const char *path, SYS_STAT *s);
410
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111
611
a7c48e0dca88 implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 608
diff changeset
112 int sys_islink(const char *path);
a7c48e0dca88 implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 608
diff changeset
113
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
114 int sys_rename(const char *oldpath, const char *newpath);
412
dc74f736aea1 adds more fs abstraction
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
115 int sys_unlink(const char *path);
dc74f736aea1 adds more fs abstraction
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
116 int sys_mkdir(const char *path);
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 410
diff changeset
117
611
a7c48e0dca88 implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 608
diff changeset
118 char* sys_readlink(const char *path, SYS_STAT *s);
574
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
119
578
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
120 int sys_symlink(const char *target, const char *linkpath);
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
121
789
378b5ab86f77 add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 611
diff changeset
122 int sys_truncate(const char* path, off_t length);
378b5ab86f77 add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 611
diff changeset
123
410
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 #ifdef __cplusplus
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 }
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 #endif
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 #endif /* DAV_SYSTEM_H */
0b9bea2d7283 adds file io abstraction functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129

mercurial