110 if(p) { |
110 if(p) { |
111 free(p); |
111 free(p); |
112 } |
112 } |
113 } |
113 } |
114 |
114 |
|
115 int dav_sync_main(int argc, char **argv); |
|
116 |
|
117 #ifdef _WIN32 |
|
118 static char* wchar2utf8(const wchar_t *wstr, size_t wlen) { |
|
119 size_t maxlen = wlen * 4; |
|
120 char *ret = malloc(maxlen + 1); |
|
121 int ret_len = WideCharToMultiByte( |
|
122 CP_UTF8, |
|
123 0, |
|
124 wstr, |
|
125 wlen, |
|
126 ret, |
|
127 maxlen, |
|
128 NULL, |
|
129 NULL); |
|
130 ret[ret_len] = 0; |
|
131 return ret; |
|
132 } |
|
133 |
|
134 int wmain(int argc, wchar_t **argv) { |
|
135 char **argv_utf8 = calloc(argc, sizeof(char*)); |
|
136 for(int i=0;i<argc;i++) { |
|
137 argv_utf8[i] = wchar2utf8(argv[i], wcslen(argv[i])); |
|
138 } |
|
139 |
|
140 int ret = dav_sync_main(argc, argv_utf8); |
|
141 |
|
142 for(int i=0;i<argc;i++) { |
|
143 free(argv_utf8[i]); |
|
144 } |
|
145 free(argv_utf8); |
|
146 |
|
147 return ret; |
|
148 } |
|
149 #else |
115 int main(int argc, char **argv) { |
150 int main(int argc, char **argv) { |
|
151 return dav_sync_main(argc, argv); |
|
152 } |
|
153 #endif |
|
154 |
|
155 int dav_sync_main(int argc, char **argv) { |
116 if(argc < 2) { |
156 if(argc < 2) { |
117 fprintf(stderr, "Missing command\n"); |
157 fprintf(stderr, "Missing command\n"); |
118 print_usage(argv[0]); |
158 print_usage(argv[0]); |
119 return -1; |
159 return -1; |
120 } |
160 } |
140 ctx = dav_context_new(); |
180 ctx = dav_context_new(); |
141 int cfgret = load_config(ctx) || load_sync_config(); |
181 int cfgret = load_config(ctx) || load_sync_config(); |
142 |
182 |
143 // ignore sigpipe to make sure the program doesn't exit |
183 // ignore sigpipe to make sure the program doesn't exit |
144 // if stdout will be closed (for example by using dav-sync ... | head) |
184 // if stdout will be closed (for example by using dav-sync ... | head) |
|
185 #ifndef _WIN32 |
145 struct sigaction act; |
186 struct sigaction act; |
146 memset(&act, 0, sizeof(struct sigaction)); |
187 memset(&act, 0, sizeof(struct sigaction)); |
147 act.sa_handler = SIG_IGN; |
188 act.sa_handler = SIG_IGN; |
148 sigaction(SIGPIPE, &act, NULL); |
189 sigaction(SIGPIPE, &act, NULL); |
|
190 #endif |
149 |
191 |
150 // prepare signal handler thread |
192 // prepare signal handler thread |
151 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
193 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
152 pthread_mutex_lock(&mutex); |
194 pthread_mutex_lock(&mutex); |
153 pthread_t tid; |
195 pthread_t tid; |