Sun, 10 Nov 2024 15:30:46 +0100
update toolkit
6
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2024 Olaf Wintermann. All rights reserved. |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
09ac07345656
add config related code from dav / load config and fill repo list
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 |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include <libidav/utils.h> |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include <stdio.h> |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | #include <stdlib.h> |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include <string.h> |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include <sys/stat.h> |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include <sys/types.h> |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include <errno.h> |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | #include <cx/string.h> |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #ifndef _WIN32 |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #include <unistd.h> |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #endif |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | #include "system.h" |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | void sys_freedirent(SysDirEnt *ent) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | free(ent->name); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | free(ent); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | #ifndef _WIN32 |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | /* ---------- POSIX implementation ---------- */ |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | void sys_init(void) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | void sys_uninit(void) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | SYS_DIR sys_opendir(const char *path) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | DIR *dir = opendir(path); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | if(!dir) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | return NULL; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | SysDir *d = malloc(sizeof(SysDir)); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | d->dir = dir; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | d->ent = NULL; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | return d; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | SysDirEnt* sys_readdir(SYS_DIR dir) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | if(dir->ent) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | free(dir->ent->name); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | free(dir->ent); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | dir->ent = NULL; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | struct dirent *ent = readdir(dir->dir); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | if(ent) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | SysDirEnt *e = malloc(sizeof(SysDirEnt)); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | e->name = strdup(ent->d_name); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | dir->ent = e; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | return e; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | return NULL; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | void sys_closedir(SYS_DIR dir) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | closedir(dir->dir); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | if(dir->ent) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | free(dir->ent->name); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | free(dir->ent); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | free(dir); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | FILE* sys_fopen(const char *path, const char *mode) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | return fopen(path, mode); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | int sys_stat(const char *path, SYS_STAT *s) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | return stat(path, s); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | int sys_lstat(const char *path, SYS_STAT *s) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | return lstat(path, s); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | int sys_islink(const char *path) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | struct stat s; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | if(!lstat(path, &s)) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | return S_ISLNK(s.st_mode); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | return 0; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | int sys_rename(const char *oldpath, const char *newpath) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | return rename(oldpath, newpath); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | int sys_unlink(const char *path) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | return unlink(path); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | int sys_mkdir(const char *path) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | return mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | char* sys_readlink(const char *path, SYS_STAT *s) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | char *ret = NULL; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | off_t l_sz = s->st_size + 16; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | size_t lnksize = l_sz > 256 ? l_sz : 256; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | char *lnkbuf = malloc(lnksize); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | ssize_t len = 0; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | for(int i=0;i<4;i++) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | // we try to read the link at most 4 times |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | // only repeat if the buffer is too small |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | len = readlink(path, lnkbuf, lnksize); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | if(len < lnksize) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | ret = lnkbuf; // success |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | lnkbuf[len] = 0; // terminate buffer |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | break; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | lnksize *= 2; // retry with bigger buffer |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | lnkbuf = realloc(lnkbuf, lnksize); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | if(!ret) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | free(lnkbuf); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | return ret; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | int sys_symlink(const char *target, const char *linkpath) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | int err = symlink(target, linkpath); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | if(err && errno == EEXIST) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | if(unlink(linkpath)) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | return 1; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | return sys_symlink(target, linkpath); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | return err; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | int sys_truncate(const char* path, off_t length) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | return truncate(path, length); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | #else |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | /* ---------- Windows implementation ---------- */ |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | #include <windows.h> |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | #include <winnls.h> |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | #include <shobjidl.h> |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | #include <objbase.h> |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | #include <objidl.h> |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | #include <direct.h> |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | #include <wchar.h> |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | void sys_init(void) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | HRESULT res = CoInitialize(NULL); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | if(res != S_OK) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | fprintf(stderr, "Error: CoInitialize failed\n"); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | void sys_uninit(void) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | CoUninitialize(); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | static wchar_t* path2winpath(const char *path, int dir, int *newlen) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | size_t len = strlen(path); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | size_t lenadd = dir ? 2 : 0; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | wchar_t *wpath = calloc(len+lenadd+1, sizeof(wchar_t)); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | int wlen = MultiByteToWideChar( |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | CP_UTF8, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | 0, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | path, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | len, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | wpath, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | len+1 |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | ); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | if(newlen) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | *newlen = wlen; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | for(int i=0;i<wlen;i++) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | if(wpath[i] == L'/') { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | wpath[i] = L'\\'; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | if(dir) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | if(wpath[wlen-1] != L'\\') { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | wpath[wlen++] = L'\\'; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | wpath[wlen++] = L'*'; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | wpath[wlen] = 0; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | return wpath; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | static char* winpath2multibyte(const wchar_t *wpath, size_t wlen) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | size_t maxlen = wlen * 4; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | char *ret = malloc(maxlen + 1); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | int ret_len = WideCharToMultiByte( |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | CP_UTF8, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | 0, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | wpath, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | wlen, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | ret, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | maxlen, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | NULL, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | NULL); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | ret[ret_len] = 0; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | return ret; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | SYS_DIR sys_opendir(const char *path) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | struct WinDir *dir = malloc(sizeof(struct WinDir)); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | wchar_t *dirpath = path2winpath(path, TRUE, NULL); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | if(!dirpath) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | fprintf(stderr, "Cannot convert path \"%s\" to UTF16\n", path); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | free(dir); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | return NULL; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | dir->first = 1; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255 | dir->handle = FindFirstFileW(dirpath, &dir->finddata); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | free(dirpath); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | if(dir->handle == INVALID_HANDLE_VALUE) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258 | free(dir); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | return NULL; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | dir->ent = NULL; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | return dir; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | SysDirEnt* sys_readdir(SYS_DIR dir) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
266 | if(dir->ent) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
267 | free(dir->ent->name); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268 | free(dir->ent); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269 | dir->ent = NULL; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | if(dir->first) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272 | dir->first = 0; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | } else { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | if(FindNextFileW(dir->handle, &dir->finddata) == 0) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | return NULL; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
277 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | size_t namelen = wcslen(dir->finddata.cFileName); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281 | char *name = malloc((namelen+1)*4); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | int nlen = WideCharToMultiByte( |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | CP_UTF8, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
284 | 0, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
285 | dir->finddata.cFileName, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
286 | -1, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
287 | name, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
288 | 256, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | NULL, |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | NULL); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | if(nlen > 0) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
292 | name[nlen] = 0; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293 | SysDirEnt *ent = malloc(sizeof(SysDirEnt)); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
294 | ent->name = name; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295 | dir->ent = ent; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
296 | return ent; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
297 | } else { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
298 | return NULL; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
299 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
300 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
301 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
302 | void sys_closedir(SYS_DIR dir) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303 | if(dir->ent) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
304 | free(dir->ent->name); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
305 | free(dir->ent); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
306 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
307 | FindClose(dir->handle); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
308 | free(dir); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
310 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
311 | FILE* sys_fopen(const char *path, const char *mode) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
312 | wchar_t *fpath = path2winpath(path, FALSE, NULL); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
313 | wchar_t *fmode = path2winpath(mode, FALSE, NULL); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
314 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
315 | FILE *file = (fpath && fmode) ? _wfopen(fpath, fmode) : NULL; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
316 | free(fpath); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
317 | free(fmode); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
318 | return file; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
319 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
320 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
321 | int sys_stat(const char *path, SYS_STAT *s) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
322 | wchar_t *fpath = path2winpath(path, FALSE, NULL); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
323 | if(!fpath) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
324 | fprintf(stderr, "Cannot convert path \"%s\" to UTF16\n", path); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
325 | return -1; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
326 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
327 | int ret = _wstat64(fpath, s); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
328 | free(fpath); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
329 | return ret; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
330 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
331 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
332 | int sys_lstat(const char *path, SYS_STAT *s) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
333 | return sys_stat(path, s); // unsupported on windows |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
334 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
335 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
336 | int sys_islink(const char *path) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
337 | // don't use symlinks on windows, because it is not really useful |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
338 | // however, we interpret .lnk files as symlinks |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
339 | int ret = 0; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
340 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
341 | cxstring path_s = cx_str(path); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
342 | if(cx_strsuffix(path_s, CX_STR(".lnk"))) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
343 | // looks like a .lnk file |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
344 | // check content |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
345 | IShellLink *sl; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
346 | HRESULT hres; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
347 | hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLinkW, (LPVOID*)&sl); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
348 | if(SUCCEEDED(hres)) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
349 | IPersistFile *file; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
350 | hres = sl->lpVtbl->QueryInterface(sl, &IID_IPersistFile, (void**)&file); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
351 | if(!SUCCEEDED(hres)) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
352 | sl->lpVtbl->Release(sl); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
353 | return ret; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
354 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
355 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
356 | int newlen = 0; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
357 | wchar_t *wpath = path2winpath(path, 0, &newlen); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
358 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
359 | hres = file->lpVtbl->Load(file, wpath, STGM_READ); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
360 | if(SUCCEEDED(hres)) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
361 | ret = 1; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
362 | file->lpVtbl->Release(file); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
363 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
364 | free(wpath); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
365 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
366 | sl->lpVtbl->Release(sl); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
367 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
368 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
369 | return ret; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
370 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
371 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
372 | int sys_rename(const char *oldpath, const char *newpath) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
373 | wchar_t *o = path2winpath(oldpath, FALSE, NULL); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
374 | wchar_t *n = path2winpath(newpath, FALSE, NULL); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
375 | if(!o || !n) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
376 | return -1; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
377 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
378 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
379 | struct __stat64 s; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
380 | if(!_wstat64(n, &s)) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
381 | if(_wunlink(n)) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
382 | fprintf(stderr, "sys_rename: cannot delete existing file: %ls\n", n); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
383 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
384 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
385 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
386 | int ret = _wrename(o, n); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
387 | free(o); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
388 | free(n); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
389 | return ret; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
390 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
391 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
392 | int sys_unlink(const char *path) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
393 | wchar_t *wpath = path2winpath(path, FALSE, NULL); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
394 | if(!wpath) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
395 | fprintf(stderr, "sys_unlink: cannot convert path\n"); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
396 | return -1; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
397 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
398 | int ret = _wunlink(wpath); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
399 | free(wpath); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
400 | return ret; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
401 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
402 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
403 | int sys_mkdir(const char *path) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
404 | wchar_t *wpath = path2winpath(path, FALSE, NULL); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
405 | if(!wpath) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
406 | fprintf(stderr, "sys_mkdir: cannot convert path\n"); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
407 | return -1; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
408 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
409 | int ret = _wmkdir(wpath); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
410 | free(wpath); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
411 | return ret; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
412 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
413 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
414 | char* sys_readlink(const char *path, SYS_STAT *s) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
415 | char *ret_link = NULL; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
416 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
417 | // create COM object for using the ShellLink interface |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
418 | IShellLinkW *sl; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
419 | HRESULT hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLinkW, (LPVOID*)&sl); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
420 | if(!SUCCEEDED(hres)) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
421 | return NULL; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
422 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
423 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
424 | IPersistFile *file; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
425 | hres = sl->lpVtbl->QueryInterface(sl, &IID_IPersistFile, (void**)&file); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
426 | if(!SUCCEEDED(hres)) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
427 | sl->lpVtbl->Release(sl); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
428 | return NULL; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
429 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
430 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
431 | // load .lnk file |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
432 | int newlen = 0; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
433 | wchar_t *wpath = path2winpath(path, 0, &newlen); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
434 | hres = file->lpVtbl->Load(file, wpath, STGM_READ); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
435 | if(SUCCEEDED(hres)) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
436 | WCHAR link_path[MAX_PATH]; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
437 | memset(link_path, 0, MAX_PATH); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
438 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
439 | hres = sl->lpVtbl->Resolve(sl, 0, SLR_NO_UI); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
440 | if(SUCCEEDED(hres)) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
441 | hres = sl->lpVtbl->GetPath(sl, link_path, MAX_PATH, NULL, SLGP_SHORTPATH); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
442 | if(SUCCEEDED(hres)) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
443 | ret_link = winpath2multibyte(link_path, wcslen(link_path)); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
444 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
445 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
446 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
447 | // cleanup |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
448 | free(wpath); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
449 | file->lpVtbl->Release(file); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
450 | sl->lpVtbl->Release(sl); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
451 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
452 | return ret_link; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
453 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
454 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
455 | int sys_symlink(const char *target, const char *linkpath) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
456 | // convert relative target to absolut path |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
457 | char *link_parent = util_parent_path(linkpath); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
458 | char *target_unnormalized = util_concat_path(link_parent, target); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
459 | char *target_normalized = util_path_normalize(target_unnormalized); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
460 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
461 | free(link_parent); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
462 | free(target_unnormalized); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
463 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
464 | // convert to wchar_t* |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
465 | int wtargetlen = 0; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
466 | wchar_t *wtarget = path2winpath(target_normalized, FALSE, &wtargetlen); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
467 | free(target_normalized); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
468 | if(!wtarget) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
469 | return 1; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
470 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
471 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
472 | int wlinkpathlen = 0; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
473 | wchar_t *wlinkpath = path2winpath(linkpath, FALSE, &wlinkpathlen); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
474 | if(!wlinkpath) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
475 | free(wtarget); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
476 | return 1; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
477 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
478 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
479 | int ret = 1; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
480 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
481 | // create COM object for using the ShellLink interface |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
482 | IShellLinkW *sl; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
483 | HRESULT hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLinkW, (LPVOID*)&sl); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
484 | if(SUCCEEDED(hres)) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
485 | IPersistFile *file; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
486 | hres = sl->lpVtbl->QueryInterface(sl, &IID_IPersistFile, (void**)&file); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
487 | if(SUCCEEDED(hres)) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
488 | // try to load the shortcut |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
489 | file->lpVtbl->Load(file, wlinkpath, STGM_READ); // ignore error |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
490 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
491 | // set path |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
492 | hres = sl->lpVtbl->SetPath(sl, wtarget); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
493 | if(SUCCEEDED(hres)) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
494 | hres = file->lpVtbl->Save(file, wlinkpath, TRUE); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
495 | if(SUCCEEDED(hres)) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
496 | // successfully created/modified shortcut |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
497 | ret = 0; // ok |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
498 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
499 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
500 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
501 | file->lpVtbl->Release(file); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
502 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
503 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
504 | sl->lpVtbl->Release(sl); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
505 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
506 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
507 | free(wtarget); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
508 | free(wlinkpath); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
509 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
510 | return ret; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
511 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
512 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
513 | int sys_truncate(const char* path, off_t length) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
514 | wchar_t* wpath = path2winpath(path, FALSE, NULL); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
515 | if (!wpath) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
516 | fprintf(stderr, "sys_truncate: cannot convert path\n"); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
517 | return -1; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
518 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
519 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
520 | FILE* file = _wfopen(wpath, L"wb"); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
521 | int ret = 1; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
522 | if (file) { |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
523 | ret = _chsize(fileno(file), length); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
524 | fclose(file); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
525 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
526 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
527 | free(wpath); |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
528 | return ret; |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
529 | } |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
530 | |
09ac07345656
add config related code from dav / load config and fill repo list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
531 | #endif |