aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-09 19:17:18 +0000
committerng0 <ng0@n0.is>2019-09-09 19:17:18 +0000
commit483b0139a218a5f8a8311bda3eb23bcd88f57688 (patch)
treed9e7a0f5053cdaa1a720485b93e9927f08466958 /src
parentec472b1aae122481f4f7e760e5242753eba9bf87 (diff)
downloadgnunet-483b0139a218a5f8a8311bda3eb23bcd88f57688.tar.gz
gnunet-483b0139a218a5f8a8311bda3eb23bcd88f57688.zip
Remove win32 and cygwin support
Diffstat (limited to 'src')
-rw-r--r--src/arm/gnunet-service-arm.c15
-rw-r--r--src/conversation/gnunet-conversation.c82
-rw-r--r--src/conversation/gnunet-helper-audio-playback-gst.c4
-rw-r--r--src/conversation/gnunet-helper-audio-record-gst.c4
-rw-r--r--src/datacache/plugin_datacache_sqlite.c5
-rw-r--r--src/fs/fs_file_information.c19
-rw-r--r--src/fs/gnunet-download.c15
-rw-r--r--src/fs/gnunet-helper-fs-publish.c29
-rw-r--r--src/gns/gnunet-gns-import.c8
-rw-r--r--src/include/gauger.h30
-rw-r--r--src/include/gnunet_disk_lib.h37
-rw-r--r--src/include/gnunet_network_lib.h34
-rw-r--r--src/include/platform.h58
-rw-r--r--src/mysql/mysql.c12
-rw-r--r--src/testbed/gnunet-helper-testbed.c12
-rw-r--r--src/testbed/gnunet-service-testbed_cpustatus.c3
-rw-r--r--src/testing/testing.c4
-rw-r--r--src/transport/tcp_service_legacy.c11
-rw-r--r--src/transport/transport-testing-filenames.c19
-rw-r--r--src/util/common_allocation.c3
-rw-r--r--src/util/common_logging.c75
-rw-r--r--src/util/disk.c842
-rw-r--r--src/util/dnsparser.c23
-rw-r--r--src/util/getopt.c6
-rw-r--r--src/util/gnunet-helper-w32-console.c319
-rw-r--r--src/util/gnunet-helper-w32-console.h70
-rw-r--r--src/util/network.c166
-rw-r--r--src/util/os_installation.c135
-rw-r--r--src/util/os_priority.c215
-rw-r--r--src/util/service.c3
-rw-r--r--src/util/signal.c27
-rw-r--r--src/util/strings.c95
-rw-r--r--src/util/test_common_logging_runtime_loglevels.c10
-rw-r--r--src/util/test_disk.c2
-rw-r--r--src/util/test_os_start_process.c4
-rw-r--r--src/util/test_strings.c12
36 files changed, 44 insertions, 2364 deletions
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c
index e8c740235..e02314b91 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -763,11 +763,8 @@ start_process(struct ServiceList *sl,
763 sli->accept_task = NULL; 763 sli->accept_task = NULL;
764 } 764 }
765 } 765 }
766#if WINDOWS 766
767 GNUNET_array_append(lsocks, ls, INVALID_SOCKET);
768#else
769 GNUNET_array_append(lsocks, ls, -1); 767 GNUNET_array_append(lsocks, ls, -1);
770#endif
771 768
772 /* obtain configuration */ 769 /* obtain configuration */
773 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, 770 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg,
@@ -1002,10 +999,8 @@ create_listen_socket(struct sockaddr *sa,
1002 struct GNUNET_NETWORK_Handle *sock; 999 struct GNUNET_NETWORK_Handle *sock;
1003 struct ServiceListeningInfo *sli; 1000 struct ServiceListeningInfo *sli;
1004 1001
1005#ifndef WINDOWS
1006 int match_uid; 1002 int match_uid;
1007 int match_gid; 1003 int match_gid;
1008#endif
1009 1004
1010 switch (sa->sa_family) 1005 switch (sa->sa_family)
1011 { 1006 {
@@ -1056,10 +1051,8 @@ create_listen_socket(struct sockaddr *sa,
1056 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 1051 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1057 "setsockopt"); 1052 "setsockopt");
1058#endif 1053#endif
1059#ifndef WINDOWS
1060 if (AF_UNIX == sa->sa_family) 1054 if (AF_UNIX == sa->sa_family)
1061 GNUNET_NETWORK_unix_precheck((struct sockaddr_un *)sa); 1055 GNUNET_NETWORK_unix_precheck((struct sockaddr_un *)sa);
1062#endif
1063 if (GNUNET_OK != 1056 if (GNUNET_OK !=
1064 GNUNET_NETWORK_socket_bind(sock, (const struct sockaddr *)sa, addr_len)) 1057 GNUNET_NETWORK_socket_bind(sock, (const struct sockaddr *)sa, addr_len))
1065 { 1058 {
@@ -1074,7 +1067,6 @@ create_listen_socket(struct sockaddr *sa,
1074 GNUNET_free(sa); 1067 GNUNET_free(sa);
1075 return; 1068 return;
1076 } 1069 }
1077#ifndef WINDOWS
1078 if ((AF_UNIX == sa->sa_family) 1070 if ((AF_UNIX == sa->sa_family)
1079#ifdef LINUX 1071#ifdef LINUX
1080 /* Permission settings are not required when abstract sockets are used */ 1072 /* Permission settings are not required when abstract sockets are used */
@@ -1090,7 +1082,6 @@ create_listen_socket(struct sockaddr *sa,
1090 match_uid, 1082 match_uid,
1091 match_gid); 1083 match_gid);
1092 } 1084 }
1093#endif
1094 if (GNUNET_OK != GNUNET_NETWORK_socket_listen(sock, 5)) 1085 if (GNUNET_OK != GNUNET_NETWORK_socket_listen(sock, 5))
1095 { 1086 {
1096 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "listen"); 1087 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "listen");
@@ -1884,13 +1875,9 @@ setup_service(void *cls, const char *section)
1884 sl->config = config; 1875 sl->config = config;
1885 sl->backoff = GNUNET_TIME_UNIT_MILLISECONDS; 1876 sl->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
1886 sl->restart_at = GNUNET_TIME_UNIT_FOREVER_ABS; 1877 sl->restart_at = GNUNET_TIME_UNIT_FOREVER_ABS;
1887#if WINDOWS
1888 sl->pipe_control = GNUNET_YES;
1889#else
1890 if (GNUNET_CONFIGURATION_have_value(cfg, section, "PIPECONTROL")) 1878 if (GNUNET_CONFIGURATION_have_value(cfg, section, "PIPECONTROL"))
1891 sl->pipe_control = 1879 sl->pipe_control =
1892 GNUNET_CONFIGURATION_get_value_yesno(cfg, section, "PIPECONTROL"); 1880 GNUNET_CONFIGURATION_get_value_yesno(cfg, section, "PIPECONTROL");
1893#endif
1894 GNUNET_CONTAINER_DLL_insert(running_head, running_tail, sl); 1881 GNUNET_CONTAINER_DLL_insert(running_head, running_tail, sl);
1895 if (GNUNET_YES == 1882 if (GNUNET_YES ==
1896 GNUNET_CONFIGURATION_get_value_yesno(cfg, section, "IMMEDIATE_START")) 1883 GNUNET_CONFIGURATION_get_value_yesno(cfg, section, "IMMEDIATE_START"))
diff --git a/src/conversation/gnunet-conversation.c b/src/conversation/gnunet-conversation.c
index 20765bbf6..bf044a4f8 100644
--- a/src/conversation/gnunet-conversation.c
+++ b/src/conversation/gnunet-conversation.c
@@ -29,9 +29,6 @@
29#include "gnunet_gnsrecord_lib.h" 29#include "gnunet_gnsrecord_lib.h"
30#include "gnunet_conversation_service.h" 30#include "gnunet_conversation_service.h"
31#include "gnunet_namestore_service.h" 31#include "gnunet_namestore_service.h"
32#ifdef WINDOWS
33#include "../util/gnunet-helper-w32-console.h"
34#endif
35 32
36/** 33/**
37 * Maximum length allowed for the command line input. 34 * Maximum length allowed for the command line input.
@@ -42,13 +39,6 @@
42 39
43#define STRINGIFY(x) (#x) 40#define STRINGIFY(x) (#x)
44 41
45#ifdef WINDOWS
46/**
47 * Helper that reads the console for us.
48 */
49struct GNUNET_HELPER_Handle *stdin_hlp;
50#endif
51
52/** 42/**
53 * Possible states of the phone. 43 * Possible states of the phone.
54 */ 44 */
@@ -1016,13 +1006,6 @@ static void
1016do_stop_task(void *cls) 1006do_stop_task(void *cls)
1017{ 1007{
1018 (void)cls; 1008 (void)cls;
1019#ifdef WINDOWS
1020 if (NULL != stdin_hlp)
1021 {
1022 GNUNET_HELPER_stop(stdin_hlp, GNUNET_NO);
1023 stdin_hlp = NULL;
1024 }
1025#endif
1026 if (NULL != call) 1009 if (NULL != call)
1027 { 1010 {
1028 GNUNET_CONVERSATION_call_stop(call); 1011 GNUNET_CONVERSATION_call_stop(call);
@@ -1090,38 +1073,6 @@ handle_command_string(char *message, size_t str_len)
1090} 1073}
1091 1074
1092 1075
1093#ifdef WINDOWS
1094static int
1095console_reader_chars(void *cls,
1096 void *client,
1097 const struct GNUNET_MessageHeader *message)
1098{
1099 char *chars;
1100 size_t str_size;
1101
1102 (void)cls;
1103 switch (ntohs(message->type))
1104 {
1105 case GNUNET_MESSAGE_TYPE_W32_CONSOLE_HELPER_CHARS:
1106 chars = (char *)&message[1];
1107 str_size = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader);
1108 if (chars[str_size - 1] != '\0')
1109 return GNUNET_SYSERR;
1110 /* FIXME: is it ok that we pass part of a const struct to
1111 * this function that may mangle the contents?
1112 */
1113 handle_command_string(chars, str_size - 1);
1114 break;
1115
1116 default:
1117 GNUNET_break(0);
1118 break;
1119 }
1120 return GNUNET_OK;
1121}
1122#endif
1123
1124
1125/** 1076/**
1126 * Task to handle commands from the terminal. 1077 * Task to handle commands from the terminal.
1127 * 1078 *
@@ -1213,30 +1164,6 @@ run(void *cls,
1213 return; 1164 return;
1214 } 1165 }
1215 id = GNUNET_IDENTITY_connect(cfg, &identity_cb, NULL); 1166 id = GNUNET_IDENTITY_connect(cfg, &identity_cb, NULL);
1216#ifdef WINDOWS
1217 if (stdin_fh == NULL)
1218 {
1219 static char cpid[64];
1220 static char *args[] = { "gnunet-helper-w32-console.exe",
1221 "chars",
1222 XSTRINGIFY(MAX_MESSAGE_LENGTH),
1223 cpid,
1224 NULL };
1225 snprintf(cpid, 64, "%d", GetCurrentProcessId());
1226 stdin_hlp = GNUNET_HELPER_start(GNUNET_NO,
1227 "gnunet-helper-w32-console",
1228 args,
1229 console_reader_chars,
1230 NULL,
1231 NULL);
1232 if (NULL == stdin_hlp)
1233 {
1234 fprintf(stderr, "%s", _("Failed to start gnunet-helper-w32-console\n"));
1235 return;
1236 }
1237 }
1238 else
1239#endif
1240 handle_cmd_task = 1167 handle_cmd_task =
1241 GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_UI, 1168 GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_UI,
1242 &handle_command, 1169 &handle_command,
@@ -1271,21 +1198,12 @@ main(int argc, char *const *argv)
1271 GNUNET_GETOPT_OPTION_END }; 1198 GNUNET_GETOPT_OPTION_END };
1272 int ret; 1199 int ret;
1273 1200
1274#ifndef WINDOWS
1275 int flags; 1201 int flags;
1276 flags = fcntl(0, F_GETFL, 0); 1202 flags = fcntl(0, F_GETFL, 0);
1277 flags |= O_NONBLOCK; 1203 flags |= O_NONBLOCK;
1278 if (0 != fcntl(0, F_SETFL, flags)) 1204 if (0 != fcntl(0, F_SETFL, flags))
1279 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "fcntl"); 1205 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "fcntl");
1280 stdin_fh = GNUNET_DISK_get_handle_from_int_fd(0); 1206 stdin_fh = GNUNET_DISK_get_handle_from_int_fd(0);
1281#else
1282 if (FILE_TYPE_CHAR == GetFileType((HANDLE)_get_osfhandle(0)))
1283 {
1284 stdin_fh = NULL;
1285 }
1286 else
1287 stdin_fh = GNUNET_DISK_get_handle_from_int_fd(0);
1288#endif
1289 1207
1290 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 1208 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
1291 return 2; 1209 return 2;
diff --git a/src/conversation/gnunet-helper-audio-playback-gst.c b/src/conversation/gnunet-helper-audio-playback-gst.c
index b268fa215..6e16b9791 100644
--- a/src/conversation/gnunet-helper-audio-playback-gst.c
+++ b/src/conversation/gnunet-helper-audio-playback-gst.c
@@ -273,10 +273,6 @@ main(int argc, char **argv)
273 termhandler = signal(SIGTERM, 273 termhandler = signal(SIGTERM,
274 &signalhandler); 274 &signalhandler);
275 275
276#ifdef WINDOWS
277 setmode(0, _O_BINARY);
278#endif
279
280 /* Initialisation */ 276 /* Initialisation */
281 gst_init(&argc, &argv); 277 gst_init(&argc, &argv);
282 278
diff --git a/src/conversation/gnunet-helper-audio-record-gst.c b/src/conversation/gnunet-helper-audio-record-gst.c
index 98ee97d15..f41f529ea 100644
--- a/src/conversation/gnunet-helper-audio-record-gst.c
+++ b/src/conversation/gnunet-helper-audio-record-gst.c
@@ -175,10 +175,6 @@ main(int argc, char **argv)
175 dump_pure_ogg = getenv("GNUNET_RECORD_PURE_OGG") ? 1 : 0; 175 dump_pure_ogg = getenv("GNUNET_RECORD_PURE_OGG") ? 1 : 0;
176#endif 176#endif
177 177
178#ifdef WINDOWS
179 setmode(1, _O_BINARY);
180#endif
181
182 /* Initialisation */ 178 /* Initialisation */
183 gst_init(&argc, &argv); 179 gst_init(&argc, &argv);
184 180
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c
index 3b901725e..b173af2f3 100644
--- a/src/datacache/plugin_datacache_sqlite.c
+++ b/src/datacache/plugin_datacache_sqlite.c
@@ -795,11 +795,6 @@ libgnunet_plugin_datacache_sqlite_done(void *cls)
795 if (SQLITE_OK != result) 795 if (SQLITE_OK != result)
796 LOG_SQLITE(plugin->dbh, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close"); 796 LOG_SQLITE(plugin->dbh, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close");
797 797
798#if WINDOWS && !defined(__CYGWIN__)
799 if ((NULL != plugin->fn) && (0 != unlink(plugin->fn)))
800 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "unlink", plugin->fn);
801 GNUNET_free_non_null(plugin->fn);
802#endif
803 GNUNET_free(plugin); 798 GNUNET_free(plugin);
804 GNUNET_free(api); 799 GNUNET_free(api);
805 return NULL; 800 return NULL;
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c
index ccba1a8b4..dbcfd81c4 100644
--- a/src/fs/fs_file_information.c
+++ b/src/fs/fs_file_information.c
@@ -112,10 +112,6 @@ GNUNET_FS_file_information_create_from_file(
112 const char *fn; 112 const char *fn;
113 const char *ss; 113 const char *ss;
114 114
115#if WINDOWS
116 char fn_conv[MAX_PATH];
117#endif
118
119 /* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */ 115 /* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */
120 if (GNUNET_OK != 116 if (GNUNET_OK !=
121 GNUNET_DISK_file_size(filename, &fsize, GNUNET_NO, GNUNET_YES)) 117 GNUNET_DISK_file_size(filename, &fsize, GNUNET_NO, GNUNET_YES))
@@ -143,18 +139,12 @@ GNUNET_FS_file_information_create_from_file(
143 return NULL; 139 return NULL;
144 ret->h = h; 140 ret->h = h;
145 ret->filename = GNUNET_strdup(filename); 141 ret->filename = GNUNET_strdup(filename);
146#if !WINDOWS
147 fn = filename; 142 fn = filename;
148#else
149 plibc_conv_to_win_path(filename, fn_conv);
150 fn = fn_conv;
151#endif
152 while (NULL != (ss = strstr(fn, DIR_SEPARATOR_STR))) 143 while (NULL != (ss = strstr(fn, DIR_SEPARATOR_STR)))
153 fn = ss + 1; 144 fn = ss + 1;
154/* FIXME: If we assume that on other platforms CRT is UTF-8-aware, then 145/* FIXME: If we assume that on other platforms CRT is UTF-8-aware, then
155 * this should be changed to EXTRACTOR_METAFORMAT_UTF8 146 * this should be changed to EXTRACTOR_METAFORMAT_UTF8
156 */ 147 */
157#if !WINDOWS
158 GNUNET_CONTAINER_meta_data_insert(ret->meta, 148 GNUNET_CONTAINER_meta_data_insert(ret->meta,
159 "<gnunet>", 149 "<gnunet>",
160 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, 150 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
@@ -162,15 +152,6 @@ GNUNET_FS_file_information_create_from_file(
162 "text/plain", 152 "text/plain",
163 fn, 153 fn,
164 strlen(fn) + 1); 154 strlen(fn) + 1);
165#else
166 GNUNET_CONTAINER_meta_data_insert(ret->meta,
167 "<gnunet>",
168 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
169 EXTRACTOR_METAFORMAT_UTF8,
170 "text/plain",
171 fn,
172 strlen(fn) + 1);
173#endif
174 return ret; 155 return ret;
175} 156}
176 157
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c
index eda6765ab..14a43e6ec 100644
--- a/src/fs/gnunet-download.c
+++ b/src/fs/gnunet-download.c
@@ -87,13 +87,8 @@ display_bar(unsigned long long x, unsigned long long n, unsigned int w)
87 unsigned int endeq; 87 unsigned int endeq;
88 float ratio_complete; 88 float ratio_complete;
89 89
90#if !WINDOWS
91 if (0 == isatty(1)) 90 if (0 == isatty(1))
92 return; 91 return;
93#else
94 if (FILE_TYPE_CHAR != GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)))
95 return;
96#endif
97 ratio_complete = x / (float)n; 92 ratio_complete = x / (float)n;
98 endeq = ratio_complete * w; 93 endeq = ratio_complete * w;
99 GNUNET_snprintf(buf, sizeof(buf), "%3d%% [", (int)(ratio_complete * 100)); 94 GNUNET_snprintf(buf, sizeof(buf), "%3d%% [", (int)(ratio_complete * 100));
@@ -175,13 +170,8 @@ progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info)
175 break; 170 break;
176 171
177 case GNUNET_FS_STATUS_DOWNLOAD_ERROR: 172 case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
178#if !WINDOWS
179 if (0 != isatty(1)) 173 if (0 != isatty(1))
180 fprintf(stdout, "\n"); 174 fprintf(stdout, "\n");
181#else
182 if (FILE_TYPE_CHAR == GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)))
183 fprintf(stdout, "\n");
184#endif
185 fprintf(stderr, 175 fprintf(stderr,
186 _("Error downloading: %s.\n"), 176 _("Error downloading: %s.\n"),
187 info->value.download.specifics.error.message); 177 info->value.download.specifics.error.message);
@@ -192,13 +182,8 @@ progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info)
192 s = GNUNET_STRINGS_byte_size_fancy( 182 s = GNUNET_STRINGS_byte_size_fancy(
193 info->value.download.completed * 1000 / 183 info->value.download.completed * 1000 /
194 (info->value.download.duration.rel_value_us + 1)); 184 (info->value.download.duration.rel_value_us + 1));
195#if !WINDOWS
196 if (0 != isatty(1)) 185 if (0 != isatty(1))
197 fprintf(stdout, "\n"); 186 fprintf(stdout, "\n");
198#else
199 if (FILE_TYPE_CHAR == GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)))
200 fprintf(stdout, "\n");
201#endif
202 fprintf(stdout, 187 fprintf(stdout,
203 _("Downloading `%s' done (%s/s).\n"), 188 _("Downloading `%s' done (%s/s).\n"),
204 info->value.download.filename, 189 info->value.download.filename,
diff --git a/src/fs/gnunet-helper-fs-publish.c b/src/fs/gnunet-helper-fs-publish.c
index db74e65aa..a6776d84f 100644
--- a/src/fs/gnunet-helper-fs-publish.c
+++ b/src/fs/gnunet-helper-fs-publish.c
@@ -434,7 +434,6 @@ extract_files(struct ScanTreeNode *item)
434} 434}
435 435
436 436
437#ifndef WINDOWS
438/** 437/**
439 * Install a signal handler to ignore SIGPIPE. 438 * Install a signal handler to ignore SIGPIPE.
440 */ 439 */
@@ -479,8 +478,6 @@ make_dev_zero(int fd, int flags)
479 GNUNET_assert(0 == close(z)); 478 GNUNET_assert(0 == close(z));
480} 479}
481 480
482#endif
483
484 481
485/** 482/**
486 * Main function of the helper process to extract meta data. 483 * Main function of the helper process to extract meta data.
@@ -499,23 +496,12 @@ main(int argc, char *const *argv)
499 const char *ex; 496 const char *ex;
500 struct ScanTreeNode *root; 497 struct ScanTreeNode *root;
501 498
502#if WINDOWS
503 /* We're using stdout to communicate binary data back to the parent; use
504 * binary mode.
505 */
506 _setmode(1, _O_BINARY);
507 /* Get utf-8-encoded arguments */
508 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
509 return 5;
510 output_stream = 1; /* stdout */
511#else
512 ignore_sigpipe(); 499 ignore_sigpipe();
513 /* move stdout to some other FD for IPC, bind 500 /* move stdout to some other FD for IPC, bind
514 stdout/stderr to /dev/null */ 501 stdout/stderr to /dev/null */
515 output_stream = dup(1); 502 output_stream = dup(1);
516 make_dev_zero(1, O_WRONLY); 503 make_dev_zero(1, O_WRONLY);
517 make_dev_zero(2, O_WRONLY); 504 make_dev_zero(2, O_WRONLY);
518#endif
519 505
520 /* parse command line */ 506 /* parse command line */
521 if ((3 != argc) && (2 != argc)) 507 if ((3 != argc) && (2 != argc))
@@ -523,9 +509,6 @@ main(int argc, char *const *argv)
523 fprintf(stderr, 509 fprintf(stderr,
524 "%s", 510 "%s",
525 "gnunet-helper-fs-publish needs exactly one or two arguments\n"); 511 "gnunet-helper-fs-publish needs exactly one or two arguments\n");
526#if WINDOWS
527 GNUNET_free((void *)argv);
528#endif
529 return 1; 512 return 1;
530 } 513 }
531 filename_expanded = argv[1]; 514 filename_expanded = argv[1];
@@ -548,9 +531,6 @@ main(int argc, char *const *argv)
548#if HAVE_LIBEXTRACTOR 531#if HAVE_LIBEXTRACTOR
549 EXTRACTOR_plugin_remove_all(plugins); 532 EXTRACTOR_plugin_remove_all(plugins);
550#endif 533#endif
551#if WINDOWS
552 GNUNET_free((void *)argv);
553#endif
554 return 2; 534 return 2;
555 } 535 }
556 /* signal that we're done counting files, so that a percentage of 536 /* signal that we're done counting files, so that a percentage of
@@ -563,9 +543,6 @@ main(int argc, char *const *argv)
563#if HAVE_LIBEXTRACTOR 543#if HAVE_LIBEXTRACTOR
564 EXTRACTOR_plugin_remove_all(plugins); 544 EXTRACTOR_plugin_remove_all(plugins);
565#endif 545#endif
566#if WINDOWS
567 GNUNET_free((void *)argv);
568#endif
569 return 3; 546 return 3;
570 } 547 }
571 if (NULL != root) 548 if (NULL != root)
@@ -579,9 +556,6 @@ main(int argc, char *const *argv)
579#if HAVE_LIBEXTRACTOR 556#if HAVE_LIBEXTRACTOR
580 EXTRACTOR_plugin_remove_all(plugins); 557 EXTRACTOR_plugin_remove_all(plugins);
581#endif 558#endif
582#if WINDOWS
583 GNUNET_free((void *)argv);
584#endif
585 return 4; 559 return 4;
586 } 560 }
587 free_tree(root); 561 free_tree(root);
@@ -593,9 +567,6 @@ main(int argc, char *const *argv)
593#if HAVE_LIBEXTRACTOR 567#if HAVE_LIBEXTRACTOR
594 EXTRACTOR_plugin_remove_all(plugins); 568 EXTRACTOR_plugin_remove_all(plugins);
595#endif 569#endif
596#if WINDOWS
597 GNUNET_free((void *)argv);
598#endif
599 return 0; 570 return 0;
600} 571}
601 572
diff --git a/src/gns/gnunet-gns-import.c b/src/gns/gnunet-gns-import.c
index 82710b803..cd354eee4 100644
--- a/src/gns/gnunet-gns-import.c
+++ b/src/gns/gnunet-gns-import.c
@@ -159,14 +159,6 @@ run_process_and_wait(int pipe_control,
159 GNUNET_free(args); 159 GNUNET_free(args);
160 return 1; 160 return 1;
161 } 161 }
162#ifdef WINDOWS
163 if (GNUNET_OS_PROCESS_EXITED != *st || 0 != *code)
164 {
165 ret = 7;
166 fprintf(stderr, "`%s' did not end correctly (%d, %d)\n", args, *st, *code);
167 return 1;
168 }
169#endif
170 return 0; 162 return 0;
171} 163}
172 164
diff --git a/src/include/gauger.h b/src/include/gauger.h
index d23883742..562208e1f 100644
--- a/src/include/gauger.h
+++ b/src/include/gauger.h
@@ -11,8 +11,6 @@
11#ifndef __GAUGER_H__ 11#ifndef __GAUGER_H__
12#define __GAUGER_H__ 12#define __GAUGER_H__
13 13
14#ifndef WINDOWS
15
16#include <unistd.h> 14#include <unistd.h>
17#include <stdio.h> 15#include <stdio.h>
18#include <sys/wait.h> 16#include <sys/wait.h>
@@ -79,32 +77,4 @@
79 } \ 77 } \
80 } 78 }
81 79
82#else /* WINDOWS */
83
84#include <stdlib.h>
85#include <stdio.h>
86#include <windef.h>
87
88#define GAUGER(category, counter, value, unit) \
89 { \
90 char __gauger_commandline[MAX_PATH]; \
91 \
92 snprintf(__gauger_commandline, MAX_PATH, "gauger.py -n \"%s\" -d \"%Lf\" -u \"%s\" -c \"%s\"", \
93 (counter), (long double)(value), (unit), (category)); \
94 __gauger_commandline[MAX_PATH - 1] = '\0'; \
95 system(__gauger_commandline); \
96 }
97
98#define GAUGER_ID(category, counter, value, unit, id) \
99 { \
100 char __gauger_commandline[MAX_PATH]; \
101 \
102 snprintf(__gauger_commandline, MAX_PATH, "gauger.py -n \"%s\" -d \"%Lf\" -u \"%s\" -i \"%s\" -c \"%s\"", \
103 (counter), (long double)(value), (unit), (id), (category)); \
104 __gauger_commandline[MAX_PATH - 1] = '\0'; \
105 system(__gauger_commandline); \
106 }
107
108#endif // WINDOWS
109
110#endif 80#endif
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h
index f693615f1..d1e1e0333 100644
--- a/src/include/gnunet_disk_lib.h
+++ b/src/include/gnunet_disk_lib.h
@@ -59,32 +59,10 @@ enum GNUNET_FILE_Type {
59 * Handle used to access files (and pipes). 59 * Handle used to access files (and pipes).
60 */ 60 */
61struct GNUNET_DISK_FileHandle { 61struct GNUNET_DISK_FileHandle {
62#if WINDOWS
63 /** 62 /**
64 * File handle under W32. 63 * File handle on Unix-like systems.
65 */
66 HANDLE h;
67
68 /**
69 * Type
70 */
71 enum GNUNET_FILE_Type type;
72
73 /**
74 * Structure for overlapped reading (for pipes)
75 */
76 OVERLAPPED *oOverlapRead;
77
78 /**
79 * Structure for overlapped writing (for pipes)
80 */
81 OVERLAPPED *oOverlapWrite;
82#else
83 /**
84 * File handle on other OSes.
85 */ 64 */
86 int fd; 65 int fd;
87#endif
88}; 66};
89 67
90 68
@@ -495,19 +473,6 @@ const struct GNUNET_DISK_FileHandle *
495GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, 473GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p,
496 enum GNUNET_DISK_PipeEnd n); 474 enum GNUNET_DISK_PipeEnd n);
497 475
498
499#if WINDOWS
500/**
501 * Get a GNUnet file handle from a W32 handle (W32-only).
502 * Do not call on non-W32 platforms (returns NULL).
503 *
504 * @param handle native handle
505 * @return GNUnet file handle corresponding to the W32 handle
506 */
507struct GNUNET_DISK_FileHandle *
508GNUNET_DISK_get_handle_from_w32_handle(HANDLE osfh);
509#endif
510
511/** 476/**
512 * Update POSIX permissions mask of a file on disk. If both argumets 477 * Update POSIX permissions mask of a file on disk. If both argumets
513 * are #GNUNET_NO, the file is made world-read-write-executable (777). 478 * are #GNUNET_NO, the file is made world-read-write-executable (777).
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h
index 2a91621a3..bdf568385 100644
--- a/src/include/gnunet_network_lib.h
+++ b/src/include/gnunet_network_lib.h
@@ -60,25 +60,6 @@ struct GNUNET_NETWORK_FDSet {
60 */ 60 */
61 fd_set sds; 61 fd_set sds;
62 62
63#ifdef WINDOWS
64 /**
65 * Array of file handles (from pipes) that are also in
66 * the FDSet. Needed as those cannot go into @e sds
67 * on W32.
68 */
69 const struct GNUNET_DISK_FileHandle **handles;
70
71 /**
72 * Size of the @e handles array
73 */
74 unsigned int handles_size;
75
76 /**
77 * Number of @e handles slots in use. Always
78 * smaller than @e handles_size.
79 */
80 unsigned int handles_pos;
81#endif
82}; 63};
83 64
84#include "gnunet_disk_lib.h" 65#include "gnunet_disk_lib.h"
@@ -107,7 +88,6 @@ char *
107GNUNET_NETWORK_shorten_unixpath(char *unixpath); 88GNUNET_NETWORK_shorten_unixpath(char *unixpath);
108 89
109 90
110#ifndef WINDOWS
111/** 91/**
112 * If services crash, they can leave a unix domain socket file on the 92 * If services crash, they can leave a unix domain socket file on the
113 * disk. This needs to be manually removed, because otherwise both 93 * disk. This needs to be manually removed, because otherwise both
@@ -119,7 +99,6 @@ GNUNET_NETWORK_shorten_unixpath(char *unixpath);
119 */ 99 */
120void 100void
121GNUNET_NETWORK_unix_precheck(const struct sockaddr_un *un); 101GNUNET_NETWORK_unix_precheck(const struct sockaddr_un *un);
122#endif
123 102
124 103
125/** 104/**
@@ -406,19 +385,6 @@ GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds,
406 const struct GNUNET_NETWORK_Handle *desc); 385 const struct GNUNET_NETWORK_Handle *desc);
407 386
408 387
409#if WINDOWS
410/**
411 * Add a W32 file handle to the fd set
412 *
413 * @param fds fd set
414 * @param h the file handle to add
415 */
416void
417GNUNET_NETWORK_fdset_handle_set_native_w32_handle(struct GNUNET_NETWORK_FDSet *fds,
418 HANDLE h);
419#endif
420
421
422/** 388/**
423 * Check whether a socket is part of the fd set 389 * Check whether a socket is part of the fd set
424 * 390 *
diff --git a/src/include/platform.h b/src/include/platform.h
index e12d08e44..bdfbb4a4b 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -38,13 +38,8 @@
38#endif 38#endif
39#endif 39#endif
40 40
41#ifdef WINDOWS
42#define BREAKPOINT asm ("int $3;");
43#define GNUNET_SIGCHLD 17
44#else
45#define BREAKPOINT 41#define BREAKPOINT
46#define GNUNET_SIGCHLD SIGCHLD 42#define GNUNET_SIGCHLD SIGCHLD
47#endif
48 43
49#ifdef HAVE_SYS_TYPES_H 44#ifdef HAVE_SYS_TYPES_H
50#include <sys/types.h> 45#include <sys/types.h>
@@ -70,18 +65,6 @@
70 65
71#define VERBOSE_STATS 0 66#define VERBOSE_STATS 0
72 67
73#ifdef CYGWIN
74#include <sys/reent.h>
75#endif
76
77#ifdef _MSC_VER
78#ifndef FD_SETSIZE
79#define FD_SETSIZE 1024
80#endif
81#include <Winsock2.h>
82#include <ws2tcpip.h>
83#else
84#ifndef MINGW
85#include <netdb.h> 68#include <netdb.h>
86#include <sys/socket.h> 69#include <sys/socket.h>
87#include <sys/un.h> 70#include <sys/un.h>
@@ -100,10 +83,6 @@
100#include <sys/ioctl.h> 83#include <sys/ioctl.h>
101#include <sys/wait.h> 84#include <sys/wait.h>
102#include <grp.h> 85#include <grp.h>
103#else
104#include "winproc.h"
105#endif
106#endif
107 86
108#include <string.h> 87#include <string.h>
109#include <stdio.h> 88#include <stdio.h>
@@ -114,20 +93,13 @@
114#include <errno.h> 93#include <errno.h>
115#include <signal.h> 94#include <signal.h>
116#include <libgen.h> 95#include <libgen.h>
117#ifdef WINDOWS
118#include <malloc.h> /* for alloca(), on other OSes it's in stdlib.h */
119#endif
120#ifdef HAVE_MALLOC_H 96#ifdef HAVE_MALLOC_H
121#include <malloc.h> /* for mallinfo on GNU */ 97#include <malloc.h> /* for mallinfo on GNU */
122#endif 98#endif
123#ifndef _MSC_VER
124#include <unistd.h> /* KLB_FIX */ 99#include <unistd.h> /* KLB_FIX */
125#endif
126#include <sys/stat.h> 100#include <sys/stat.h>
127#include <sys/types.h> 101#include <sys/types.h>
128#ifndef _MSC_VER
129#include <dirent.h> /* KLB_FIX */ 102#include <dirent.h> /* KLB_FIX */
130#endif
131#include <fcntl.h> 103#include <fcntl.h>
132#include <math.h> 104#include <math.h>
133#if HAVE_SYS_PARAM_H 105#if HAVE_SYS_PARAM_H
@@ -170,10 +142,6 @@
170#if HAVE_SYS_UCRED_H 142#if HAVE_SYS_UCRED_H
171#include <sys/ucred.h> 143#include <sys/ucred.h>
172#endif 144#endif
173#ifdef CYGWIN
174#include <windows.h>
175#include <cygwin/if.h>
176#endif
177#if HAVE_IFADDRS_H 145#if HAVE_IFADDRS_H
178#include <ifaddrs.h> 146#include <ifaddrs.h>
179#endif 147#endif
@@ -196,24 +164,11 @@
196#include <sys/endian.h> 164#include <sys/endian.h>
197#endif 165#endif
198 166
199/* From plibc. */
200#ifdef Q_OS_WIN32
201#define WINDOWS 1
202#endif
203
204#ifndef WINDOWS
205#define DIR_SEPARATOR '/' 167#define DIR_SEPARATOR '/'
206#define DIR_SEPARATOR_STR "/" 168#define DIR_SEPARATOR_STR "/"
207#define PATH_SEPARATOR ':' 169#define PATH_SEPARATOR ':'
208#define PATH_SEPARATOR_STR ":" 170#define PATH_SEPARATOR_STR ":"
209#define NEWLINE "\n" 171#define NEWLINE "\n"
210#else
211#define DIR_SEPARATOR '\\'
212#define DIR_SEPARATOR_STR "\\"
213#define PATH_SEPARATOR ';'
214#define PATH_SEPARATOR_STR ";"
215#define NEWLINE "\r\n"
216#endif
217 172
218#include "compat.h" 173#include "compat.h"
219 174
@@ -231,15 +186,7 @@
231#define LIBEXTRACTOR_GETTEXT_DOMAIN "org.gnunet.libextractor" 186#define LIBEXTRACTOR_GETTEXT_DOMAIN "org.gnunet.libextractor"
232#endif 187#endif
233 188
234#ifdef CYGWIN
235#define SIOCGIFCONF _IOW('s', 100, struct ifconf) /* get if list */
236#define SIOCGIFFLAGS _IOW('s', 101, struct ifreq) /* Get if flags */
237#define SIOCGIFADDR _IOW('s', 102, struct ifreq) /* Get if addr */
238#endif
239
240#ifndef MINGW
241#include <sys/mman.h> 189#include <sys/mman.h>
242#endif
243 190
244#ifdef FREEBSD 191#ifdef FREEBSD
245#define __BYTE_ORDER BYTE_ORDER 192#define __BYTE_ORDER BYTE_ORDER
@@ -286,13 +233,8 @@ atoll(const char *nptr);
286#define MAKE_UNALIGNED(val) val 233#define MAKE_UNALIGNED(val) val
287#endif 234#endif
288 235
289#if WINDOWS
290#define FDTYPE HANDLE
291#define SOCKTYPE SOCKET
292#else
293#define FDTYPE int 236#define FDTYPE int
294#define SOCKTYPE int 237#define SOCKTYPE int
295#endif
296 238
297/** 239/**
298 * The termination signal 240 * The termination signal
diff --git a/src/mysql/mysql.c b/src/mysql/mysql.c
index 68a75d083..918d24cf2 100644
--- a/src/mysql/mysql.c
+++ b/src/mysql/mysql.c
@@ -157,12 +157,10 @@ get_my_cnf_path(const struct GNUNET_CONFIGURATION_Handle *cfg,
157 char *home_dir; 157 char *home_dir;
158 struct stat st; 158 struct stat st;
159 159
160#ifndef WINDOWS
161 struct passwd *pw; 160 struct passwd *pw;
162#endif 161
163 int configured; 162 int configured;
164 163
165#ifndef WINDOWS
166 pw = getpwuid(getuid()); 164 pw = getpwuid(getuid());
167 if (!pw) 165 if (!pw)
168 { 166 {
@@ -185,13 +183,7 @@ get_my_cnf_path(const struct GNUNET_CONFIGURATION_Handle *cfg,
185 GNUNET_free(home_dir); 183 GNUNET_free(home_dir);
186 configured = GNUNET_NO; 184 configured = GNUNET_NO;
187 } 185 }
188#else 186
189 home_dir = (char *)GNUNET_malloc(_MAX_PATH + 1);
190 plibc_conv_to_win_path("~/", home_dir);
191 GNUNET_asprintf(&cnffile, "%s/.my.cnf", home_dir);
192 GNUNET_free(home_dir);
193 configured = GNUNET_NO;
194#endif
195 GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, 187 GNUNET_log_from(GNUNET_ERROR_TYPE_INFO,
196 "mysql", 188 "mysql",
197 _("Trying to use file `%s' for MySQL configuration.\n"), 189 _("Trying to use file `%s' for MySQL configuration.\n"),
diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c
index 979d6c38f..0650e7dbd 100644
--- a/src/testbed/gnunet-helper-testbed.c
+++ b/src/testbed/gnunet-helper-testbed.c
@@ -60,11 +60,7 @@
60/** 60/**
61 * We need pipe control only on WINDOWS 61 * We need pipe control only on WINDOWS
62 */ 62 */
63#if WINDOWS
64#define PIPE_CONTROL GNUNET_YES
65#else
66#define PIPE_CONTROL GNUNET_NO 63#define PIPE_CONTROL GNUNET_NO
67#endif
68 64
69 65
70/** 66/**
@@ -394,25 +390,17 @@ tokenizer_cb(void *cls, const struct GNUNET_MessageHeader *message)
394 { 390 {
395 /* unsetting the variable will invalidate the pointer! */ 391 /* unsetting the variable will invalidate the pointer! */
396 evstr = GNUNET_strdup(evstr); 392 evstr = GNUNET_strdup(evstr);
397#ifdef WINDOWS
398 GNUNET_break(0 != SetEnvironmentVariable(GNUNET_TESTING_PREFIX, NULL));
399#else
400 GNUNET_break(0 == unsetenv(GNUNET_TESTING_PREFIX)); 393 GNUNET_break(0 == unsetenv(GNUNET_TESTING_PREFIX));
401#endif
402 } 394 }
403 test_system = 395 test_system =
404 GNUNET_TESTING_system_create("testbed-helper", trusted_ip, hostname, NULL); 396 GNUNET_TESTING_system_create("testbed-helper", trusted_ip, hostname, NULL);
405 if (NULL != evstr) 397 if (NULL != evstr)
406 { 398 {
407#ifdef WINDOWS
408 GNUNET_assert(0 != SetEnvironmentVariable(GNUNET_TESTING_PREFIX, evstr));
409#else
410 char *evar; 399 char *evar;
411 400
412 GNUNET_asprintf(&evar, GNUNET_TESTING_PREFIX "=%s", evstr); 401 GNUNET_asprintf(&evar, GNUNET_TESTING_PREFIX "=%s", evstr);
413 GNUNET_assert(0 == putenv(evar)); /* consumes 'evar', 402 GNUNET_assert(0 == putenv(evar)); /* consumes 'evar',
414 see putenv(): becomes part of envrionment! */ 403 see putenv(): becomes part of envrionment! */
415#endif
416 GNUNET_free(evstr); 404 GNUNET_free(evstr);
417 evstr = NULL; 405 evstr = NULL;
418 } 406 }
diff --git a/src/testbed/gnunet-service-testbed_cpustatus.c b/src/testbed/gnunet-service-testbed_cpustatus.c
index a8796ea11..b659b5dc3 100644
--- a/src/testbed/gnunet-service-testbed_cpustatus.c
+++ b/src/testbed/gnunet-service-testbed_cpustatus.c
@@ -54,9 +54,6 @@
54 54
55static processor_cpu_load_info_t prev_cpu_load; 55static processor_cpu_load_info_t prev_cpu_load;
56#endif 56#endif
57#ifdef WINDOWS
58#include <winternl.h>
59#endif
60 57
61#define DEBUG_STATUSCALLS GNUNET_NO 58#define DEBUG_STATUSCALLS GNUNET_NO
62 59
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 9c5c32012..26e866225 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -40,11 +40,7 @@
40/** 40/**
41 * We need pipe control only on WINDOWS 41 * We need pipe control only on WINDOWS
42 */ 42 */
43#if WINDOWS
44#define PIPE_CONTROL GNUNET_YES
45#else
46#define PIPE_CONTROL GNUNET_NO 43#define PIPE_CONTROL GNUNET_NO
47#endif
48 44
49 45
50/** 46/**
diff --git a/src/transport/tcp_service_legacy.c b/src/transport/tcp_service_legacy.c
index f1821a17b..8f3f43718 100644
--- a/src/transport/tcp_service_legacy.c
+++ b/src/transport/tcp_service_legacy.c
@@ -335,11 +335,10 @@ check_access(void *cls,
335 (!check_ipv6_listed(sctx->v6_denied, &i6->sin6_addr))); 335 (!check_ipv6_listed(sctx->v6_denied, &i6->sin6_addr)));
336 break; 336 break;
337 337
338#ifndef WINDOWS
339 case AF_UNIX: 338 case AF_UNIX:
340 ret = GNUNET_OK; /* controlled using file-system ACL now */ 339 ret = GNUNET_OK; /* controlled using file-system ACL now */
341 break; 340 break;
342#endif 341
343 default: 342 default:
344 LOG(GNUNET_ERROR_TYPE_WARNING, 343 LOG(GNUNET_ERROR_TYPE_WARNING,
345 _("Unknown address family %d\n"), 344 _("Unknown address family %d\n"),
@@ -1203,7 +1202,7 @@ service_task(void *cls)
1203 sctx->ret = GNUNET_SYSERR; 1202 sctx->ret = GNUNET_SYSERR;
1204 return; 1203 return;
1205 } 1204 }
1206#ifndef WINDOWS 1205
1207 if (NULL != sctx->addrs) 1206 if (NULL != sctx->addrs)
1208 for (i = 0; NULL != sctx->addrs[i]; i++) 1207 for (i = 0; NULL != sctx->addrs[i]; i++)
1209 if ((AF_UNIX == sctx->addrs[i]->sa_family) && 1208 if ((AF_UNIX == sctx->addrs[i]->sa_family) &&
@@ -1213,8 +1212,6 @@ service_task(void *cls)
1213 ->sun_path, 1212 ->sun_path,
1214 sctx->match_uid, 1213 sctx->match_uid,
1215 sctx->match_gid); 1214 sctx->match_gid);
1216#endif
1217
1218 1215
1219 if (0 == (sctx->options & LEGACY_SERVICE_OPTION_MANUAL_SHUTDOWN)) 1216 if (0 == (sctx->options & LEGACY_SERVICE_OPTION_MANUAL_SHUTDOWN))
1220 { 1217 {
@@ -1647,7 +1644,7 @@ LEGACY_SERVICE_start(const char *service_name,
1647 LEGACY_SERVICE_stop(sctx); 1644 LEGACY_SERVICE_stop(sctx);
1648 return NULL; 1645 return NULL;
1649 } 1646 }
1650#ifndef WINDOWS 1647
1651 if (NULL != sctx->addrs) 1648 if (NULL != sctx->addrs)
1652 for (i = 0; NULL != sctx->addrs[i]; i++) 1649 for (i = 0; NULL != sctx->addrs[i]; i++)
1653 if ((AF_UNIX == sctx->addrs[i]->sa_family) && 1650 if ((AF_UNIX == sctx->addrs[i]->sa_family) &&
@@ -1657,7 +1654,7 @@ LEGACY_SERVICE_start(const char *service_name,
1657 ->sun_path, 1654 ->sun_path,
1658 sctx->match_uid, 1655 sctx->match_uid,
1659 sctx->match_gid); 1656 sctx->match_gid);
1660#endif 1657
1661 sctx->my_handlers = GNUNET_malloc(sizeof(defhandlers)); 1658 sctx->my_handlers = GNUNET_malloc(sizeof(defhandlers));
1662 GNUNET_memcpy(sctx->my_handlers, defhandlers, sizeof(defhandlers)); 1659 GNUNET_memcpy(sctx->my_handlers, defhandlers, sizeof(defhandlers));
1663 i = 0; 1660 i = 0;
diff --git a/src/transport/transport-testing-filenames.c b/src/transport/transport-testing-filenames.c
index 865907007..8d493864e 100644
--- a/src/transport/transport-testing-filenames.c
+++ b/src/transport/transport-testing-filenames.c
@@ -40,25 +40,6 @@ extract_filename(const char *file)
40 char *filename = NULL; 40 char *filename = NULL;
41 char *res; 41 char *res;
42 42
43#if WINDOWS
44 if ((strlen(pch) >= 3) && pch[1] == ':')
45 {
46 if (NULL != strstr(pch, "\\"))
47 {
48 pch = strtok(pch, "\\");
49 while (pch != NULL)
50 {
51 pch = strtok(NULL, "\\");
52 if (pch != NULL)
53 filename = pch;
54 }
55 }
56 }
57 if (filename != NULL)
58 pch = filename; /* If we miss the next condition, filename = pch will
59 * not harm us.
60 */
61#endif
62 if (NULL != strstr(pch, "/")) 43 if (NULL != strstr(pch, "/"))
63 { 44 {
64 pch = strtok(pch, "/"); 45 pch = strtok(pch, "/");
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index fd5af7a91..d8d6d639f 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -285,9 +285,6 @@ GNUNET_xrealloc_(void *ptr, size_t n, const char *filename, int linenumber)
285#define BAADFOOD_STR "\xBA\xAD\xF0\x0D" 285#define BAADFOOD_STR "\xBA\xAD\xF0\x0D"
286#endif 286#endif
287 287
288#if WINDOWS
289#define M_SIZE(p) _msize(p)
290#endif
291#if HAVE_MALLOC_NP_H 288#if HAVE_MALLOC_NP_H
292#include <malloc_np.h> 289#include <malloc_np.h>
293#endif 290#endif
diff --git a/src/util/common_logging.c b/src/util/common_logging.c
index 4c7a5291f..7a2d5a0b5 100644
--- a/src/util/common_logging.c
+++ b/src/util/common_logging.c
@@ -241,13 +241,6 @@ static int gnunet_force_log_parsed;
241static int gnunet_force_log_present; 241static int gnunet_force_log_present;
242#endif 242#endif
243 243
244#ifdef WINDOWS
245/**
246 * Contains the number of performance counts per second.
247 */
248static LARGE_INTEGER performance_frequency;
249#endif
250
251 244
252/** 245/**
253 * Convert a textual description of a loglevel 246 * Convert a textual description of a loglevel
@@ -283,9 +276,6 @@ get_type(const char *log)
283void 276void
284GNUNET_abort_() 277GNUNET_abort_()
285{ 278{
286#if WINDOWS
287 DebugBreak();
288#endif
289 abort(); 279 abort();
290} 280}
291 281
@@ -377,14 +367,10 @@ setup_log_file(const struct tm *tm)
377 strerror(errno)); 367 strerror(errno));
378 return GNUNET_SYSERR; 368 return GNUNET_SYSERR;
379 } 369 }
380#if WINDOWS
381 altlog_fd =
382 open(fn, O_APPEND | O_BINARY | O_WRONLY | O_CREAT, _S_IREAD | _S_IWRITE);
383#else
384 altlog_fd = open(fn, 370 altlog_fd = open(fn,
385 O_APPEND | O_WRONLY | O_CREAT, 371 O_APPEND | O_WRONLY | O_CREAT,
386 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); 372 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
387#endif 373
388 if (-1 != altlog_fd) 374 if (-1 != altlog_fd)
389 { 375 {
390 if (NULL != GNUNET_stderr) 376 if (NULL != GNUNET_stderr)
@@ -725,9 +711,6 @@ GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
725#if !defined(GNUNET_CULL_LOGGING) 711#if !defined(GNUNET_CULL_LOGGING)
726 parse_all_definitions(); 712 parse_all_definitions();
727#endif 713#endif
728#ifdef WINDOWS
729 QueryPerformanceFrequency(&performance_frequency);
730#endif
731 GNUNET_free_non_null(component); 714 GNUNET_free_non_null(component);
732 GNUNET_asprintf(&component, "%s-%d", comp, getpid()); 715 GNUNET_asprintf(&component, "%s-%d", comp, getpid());
733 GNUNET_free_non_null(component_nopid); 716 GNUNET_free_non_null(component_nopid);
@@ -809,10 +792,6 @@ GNUNET_logger_remove(GNUNET_Logger logger, void *logger_cls)
809 GNUNET_free(pos); 792 GNUNET_free(pos);
810} 793}
811 794
812#if WINDOWS
813CRITICAL_SECTION output_message_cs;
814#endif
815
816 795
817/** 796/**
818 * Actually output the log message. 797 * Actually output the log message.
@@ -830,9 +809,6 @@ output_message(enum GNUNET_ErrorType kind,
830{ 809{
831 struct CustomLogger *pos; 810 struct CustomLogger *pos;
832 811
833#if WINDOWS
834 EnterCriticalSection(&output_message_cs);
835#endif
836 /* only use the standard logger if no custom loggers are present */ 812 /* only use the standard logger if no custom loggers are present */
837 if ((NULL != GNUNET_stderr) && (NULL == loggers)) 813 if ((NULL != GNUNET_stderr) && (NULL == loggers))
838 { 814 {
@@ -887,9 +863,6 @@ output_message(enum GNUNET_ErrorType kind,
887 pos->logger(pos->logger_cls, kind, comp, datestr, msg); 863 pos->logger(pos->logger_cls, kind, comp, datestr, msg);
888 pos = pos->next; 864 pos = pos->next;
889 } 865 }
890#if WINDOWS
891 LeaveCriticalSection(&output_message_cs);
892#endif
893} 866}
894 867
895 868
@@ -1003,33 +976,7 @@ mylog(enum GNUNET_ErrorType kind,
1003 { 976 {
1004 char buf[size]; 977 char buf[size];
1005 long long offset; 978 long long offset;
1006#ifdef WINDOWS
1007 LARGE_INTEGER pc;
1008 time_t timetmp;
1009 979
1010 offset = GNUNET_TIME_get_offset();
1011 time(&timetmp);
1012 timetmp += offset / 1000;
1013 tmptr = localtime(&timetmp);
1014 pc.QuadPart = 0;
1015 QueryPerformanceCounter(&pc);
1016 if (NULL == tmptr)
1017 {
1018 strcpy(date, "localtime error");
1019 }
1020 else
1021 {
1022 if (0 ==
1023 strftime(date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%020llu", tmptr))
1024 abort();
1025 if (0 > snprintf(date,
1026 sizeof(date),
1027 date2,
1028 (long long)(pc.QuadPart /
1029 (performance_frequency.QuadPart / 1000))))
1030 abort();
1031 }
1032#else
1033 struct timeval timeofday; 980 struct timeval timeofday;
1034 981
1035 gettimeofday(&timeofday, NULL); 982 gettimeofday(&timeofday, NULL);
@@ -1069,7 +1016,7 @@ mylog(enum GNUNET_ErrorType kind,
1069 if (0 > snprintf(date, sizeof(date), date2, timeofday.tv_usec)) 1016 if (0 > snprintf(date, sizeof(date), date2, timeofday.tv_usec))
1070 abort(); 1017 abort();
1071 } 1018 }
1072#endif 1019
1073 vsnprintf(buf, size, message, va); 1020 vsnprintf(buf, size, message, va);
1074#if !(defined(GNUNET_CULL_LOGGING) || TALER_WALLET_ONLY) 1021#if !(defined(GNUNET_CULL_LOGGING) || TALER_WALLET_ONLY)
1075 if (NULL != tmptr) 1022 if (NULL != tmptr)
@@ -1433,13 +1380,9 @@ GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
1433const char * 1380const char *
1434GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen) 1381GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
1435{ 1382{
1436#ifndef WINDOWS
1437#define LEN \ 1383#define LEN \
1438 GNUNET_MAX((INET6_ADDRSTRLEN + 8), \ 1384 GNUNET_MAX((INET6_ADDRSTRLEN + 8), \
1439 (1 + sizeof(struct sockaddr_un) - sizeof(sa_family_t))) 1385 (1 + sizeof(struct sockaddr_un) - sizeof(sa_family_t)))
1440#else
1441#define LEN (INET6_ADDRSTRLEN + 8)
1442#endif
1443 static char buf[LEN]; 1386 static char buf[LEN];
1444#undef LEN 1387#undef LEN
1445 static char b2[6]; 1388 static char b2[6];
@@ -1603,13 +1546,6 @@ GNUNET_async_scope_get(struct GNUNET_AsyncScopeSave *scope_ret)
1603void __attribute__ ((constructor)) GNUNET_util_cl_init() 1546void __attribute__ ((constructor)) GNUNET_util_cl_init()
1604{ 1547{
1605 GNUNET_stderr = stderr; 1548 GNUNET_stderr = stderr;
1606#ifdef MINGW
1607 GNInitWinEnv(NULL);
1608#endif
1609#if WINDOWS
1610 if (!InitializeCriticalSectionAndSpinCount(&output_message_cs, 0x00000400))
1611 GNUNET_abort_();
1612#endif
1613} 1549}
1614 1550
1615 1551
@@ -1618,12 +1554,7 @@ void __attribute__ ((constructor)) GNUNET_util_cl_init()
1618 */ 1554 */
1619void __attribute__ ((destructor)) GNUNET_util_cl_fini() 1555void __attribute__ ((destructor)) GNUNET_util_cl_fini()
1620{ 1556{
1621#if WINDOWS 1557
1622 DeleteCriticalSection(&output_message_cs);
1623#endif
1624#ifdef MINGW
1625 GNShutdownWinEnv();
1626#endif
1627} 1558}
1628 1559
1629/* end of common_logging.c */ 1560/* end of common_logging.c */
diff --git a/src/util/disk.c b/src/util/disk.c
index c5ea42ee6..01d5efbe2 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -208,23 +208,11 @@ GNUNET_DISK_handle_invalid(const struct GNUNET_DISK_FileHandle *h)
208int 208int
209GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size) 209GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
210{ 210{
211#if WINDOWS
212 BOOL b;
213 LARGE_INTEGER li;
214 b = GetFileSizeEx(fh->h, &li);
215 if (!b)
216 {
217 SetErrnoFromWinError(GetLastError());
218 return GNUNET_SYSERR;
219 }
220 *size = (off_t)li.QuadPart;
221#else
222 struct stat sbuf; 211 struct stat sbuf;
223 212
224 if (0 != fstat(fh->fd, &sbuf)) 213 if (0 != fstat(fh->fd, &sbuf))
225 return GNUNET_SYSERR; 214 return GNUNET_SYSERR;
226 *size = sbuf.st_size; 215 *size = sbuf.st_size;
227#endif
228 return GNUNET_OK; 216 return GNUNET_OK;
229} 217}
230 218
@@ -324,29 +312,6 @@ GNUNET_DISK_file_get_identifiers(const char *filename,
324 uint64_t *dev, 312 uint64_t *dev,
325 uint64_t *ino) 313 uint64_t *ino)
326{ 314{
327#if WINDOWS
328 {
329 // FIXME NILS: test this
330 struct GNUNET_DISK_FileHandle *fh;
331 BY_HANDLE_FILE_INFORMATION info;
332 int succ;
333
334 fh = GNUNET_DISK_file_open(filename,
335 GNUNET_DISK_OPEN_READ,
336 GNUNET_DISK_PERM_NONE);
337 if (NULL == fh)
338 return GNUNET_SYSERR;
339 succ = GetFileInformationByHandle(fh->h, &info);
340 GNUNET_DISK_file_close(fh);
341 if (!succ)
342 {
343 return GNUNET_SYSERR;
344 }
345 *dev = info.dwVolumeSerialNumber;
346 *ino = ((((uint64_t)info.nFileIndexHigh) << (sizeof(DWORD) * 8)) |
347 info.nFileIndexLow);
348 }
349#else /* !WINDOWS */
350#if HAVE_STAT 315#if HAVE_STAT
351 { 316 {
352 struct stat sbuf; 317 struct stat sbuf;
@@ -384,7 +349,6 @@ GNUNET_DISK_file_get_identifiers(const char *filename,
384#else 349#else
385 *dev = 0; 350 *dev = 0;
386#endif 351#endif
387#endif /* !WINDOWS */
388 return GNUNET_OK; 352 return GNUNET_OK;
389} 353}
390 354
@@ -402,11 +366,7 @@ mktemp_name(const char *t)
402 char *tmpl; 366 char *tmpl;
403 char *fn; 367 char *fn;
404 368
405 if ((t[0] != '/') && (t[0] != '\\') 369 if ((t[0] != '/') && (t[0] != '\\'))
406#if WINDOWS
407 && !(isalpha((int)t[0]) && (t[0] != '\0') && (t[1] == ':'))
408#endif
409 )
410 { 370 {
411 /* FIXME: This uses system codepage on W32, not UTF-8 */ 371 /* FIXME: This uses system codepage on W32, not UTF-8 */
412 tmpdir = getenv("TMPDIR"); 372 tmpdir = getenv("TMPDIR");
@@ -422,71 +382,10 @@ mktemp_name(const char *t)
422 { 382 {
423 GNUNET_asprintf(&tmpl, "%s%s", t, "XXXXXX"); 383 GNUNET_asprintf(&tmpl, "%s%s", t, "XXXXXX");
424 } 384 }
425#ifdef MINGW
426 fn = (char *)GNUNET_malloc(MAX_PATH + 1);
427 if (ERROR_SUCCESS != plibc_conv_to_win_path(tmpl, fn))
428 {
429 GNUNET_free(fn);
430 GNUNET_free(tmpl);
431 return NULL;
432 }
433 GNUNET_free(tmpl);
434#else
435 fn = tmpl; 385 fn = tmpl;
436#endif
437 return fn;
438}
439
440
441#if WINDOWS
442static char *
443mkdtemp(char *fn)
444{
445 char *random_fn;
446 char *tfn;
447
448 while (1)
449 {
450 tfn = GNUNET_strdup(fn);
451 random_fn = _mktemp(tfn);
452 if (NULL == random_fn)
453 {
454 GNUNET_free(tfn);
455 return NULL;
456 }
457 /* FIXME: assume fn to be UTF-8-encoded and do the right thing */
458 if (0 == CreateDirectoryA(tfn, NULL))
459 {
460 DWORD error = GetLastError();
461 GNUNET_free(tfn);
462 if (ERROR_ALREADY_EXISTS == error)
463 continue;
464 return NULL;
465 }
466 break;
467 }
468 strcpy(fn, tfn);
469 return fn; 386 return fn;
470} 387}
471 388
472/**
473 * Update POSIX permissions mask of a file on disk. If both argumets
474 * are #GNUNET_NO, the file is made world-read-write-executable (777).
475 * Does nothing on W32.
476 *
477 * @param fn name of the file to update
478 * @param require_uid_match #GNUNET_YES means 700
479 * @param require_gid_match #GNUNET_YES means 770 unless @a require_uid_match is set
480 */
481void
482GNUNET_DISK_fix_permissions(const char *fn,
483 int require_uid_match,
484 int require_gid_match)
485{
486 /* nothing on W32 */
487}
488
489#else
490 389
491/** 390/**
492 * Update POSIX permissions mask of a file on disk. If both argumets 391 * Update POSIX permissions mask of a file on disk. If both argumets
@@ -514,7 +413,6 @@ GNUNET_DISK_fix_permissions(const char *fn,
514 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "chmod", fn); 413 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "chmod", fn);
515} 414}
516 415
517#endif
518 416
519/** 417/**
520 * Create an (empty) temporary directory on disk. If the given name is not 418 * Create an (empty) temporary directory on disk. If the given name is not
@@ -724,28 +622,9 @@ GNUNET_DISK_directory_create(const char *dir)
724 } 622 }
725 623
726 len = strlen(rdir); 624 len = strlen(rdir);
727#ifndef MINGW 625
728 pos = 1; /* skip heading '/' */ 626 pos = 1; /* skip heading '/' */
729#else 627
730 /* Local or Network path? */
731 if (strncmp(rdir, "\\\\", 2) == 0)
732 {
733 pos = 2;
734 while (rdir[pos])
735 {
736 if (rdir[pos] == '\\')
737 {
738 pos++;
739 break;
740 }
741 pos++;
742 }
743 }
744 else
745 {
746 pos = 3; /* strlen("C:\\") */
747 }
748#endif
749 /* Check which low level directories already exist */ 628 /* Check which low level directories already exist */
750 pos2 = len; 629 pos2 = len;
751 rdir[len] = DIR_SEPARATOR; 630 rdir[len] = DIR_SEPARATOR;
@@ -792,17 +671,10 @@ GNUNET_DISK_directory_create(const char *dir)
792 } 671 }
793 if (GNUNET_SYSERR == ret) 672 if (GNUNET_SYSERR == ret)
794 { 673 {
795#ifndef MINGW
796 ret = mkdir(rdir, 674 ret = mkdir(rdir,
797 S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | 675 S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH |
798 S_IXOTH); /* 755 */ 676 S_IXOTH); /* 755 */
799#else 677
800 wchar_t wrdir[MAX_PATH + 1];
801 if (ERROR_SUCCESS == plibc_conv_to_win_pathwconv(rdir, wrdir))
802 ret = !CreateDirectoryW(wrdir, NULL);
803 else
804 ret = 1;
805#endif
806 if ((ret != 0) && (errno != EEXIST)) 678 if ((ret != 0) && (errno != EEXIST))
807 { 679 {
808 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_ERROR, "mkdir", rdir); 680 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_ERROR, "mkdir", rdir);
@@ -887,42 +759,7 @@ GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h,
887 return GNUNET_SYSERR; 759 return GNUNET_SYSERR;
888 } 760 }
889 761
890#ifdef MINGW
891 DWORD bytes_read;
892
893 if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE)
894 {
895 if (!ReadFile(h->h, result, len, &bytes_read, NULL))
896 {
897 SetErrnoFromWinError(GetLastError());
898 return GNUNET_SYSERR;
899 }
900 }
901 else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE)
902 {
903 if (!ReadFile(h->h, result, len, &bytes_read, h->oOverlapRead))
904 {
905 if (GetLastError() != ERROR_IO_PENDING)
906 {
907 LOG(GNUNET_ERROR_TYPE_DEBUG,
908 "Error reading from pipe: %u\n",
909 GetLastError());
910 SetErrnoFromWinError(GetLastError());
911 return GNUNET_SYSERR;
912 }
913 LOG(GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n");
914 GetOverlappedResult(h->h, h->oOverlapRead, &bytes_read, TRUE);
915 }
916 LOG(GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes from pipe\n", bytes_read);
917 }
918 else
919 {
920 bytes_read = 0;
921 }
922 return bytes_read;
923#else
924 return read(h->fd, result, len); 762 return read(h->fd, result, len);
925#endif
926} 763}
927 764
928 765
@@ -947,45 +784,6 @@ GNUNET_DISK_file_read_non_blocking(const struct GNUNET_DISK_FileHandle *h,
947 return GNUNET_SYSERR; 784 return GNUNET_SYSERR;
948 } 785 }
949 786
950#ifdef MINGW
951 DWORD bytes_read;
952
953 if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE)
954 {
955 if (!ReadFile(h->h, result, len, &bytes_read, NULL))
956 {
957 SetErrnoFromWinError(GetLastError());
958 return GNUNET_SYSERR;
959 }
960 }
961 else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE)
962 {
963 if (!ReadFile(h->h, result, len, &bytes_read, h->oOverlapRead))
964 {
965 if (GetLastError() != ERROR_IO_PENDING)
966 {
967 LOG(GNUNET_ERROR_TYPE_DEBUG,
968 "Error reading from pipe: %u\n",
969 GetLastError());
970 SetErrnoFromWinError(GetLastError());
971 return GNUNET_SYSERR;
972 }
973 else
974 {
975 LOG(GNUNET_ERROR_TYPE_DEBUG, "ReadFile() queued a read, cancelling\n");
976 CancelIo(h->h);
977 errno = EAGAIN;
978 return GNUNET_SYSERR;
979 }
980 }
981 LOG(GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes\n", bytes_read);
982 }
983 else
984 {
985 bytes_read = 0;
986 }
987 return bytes_read;
988#else
989 int flags; 787 int flags;
990 ssize_t ret; 788 ssize_t ret;
991 789
@@ -1001,7 +799,6 @@ GNUNET_DISK_file_read_non_blocking(const struct GNUNET_DISK_FileHandle *h,
1001 errno = eno; 799 errno = eno;
1002 } 800 }
1003 return ret; 801 return ret;
1004#endif
1005} 802}
1006 803
1007 804
@@ -1050,78 +847,8 @@ GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h,
1050 return GNUNET_SYSERR; 847 return GNUNET_SYSERR;
1051 } 848 }
1052 849
1053#ifdef MINGW
1054 DWORD bytes_written;
1055 850
1056 if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE)
1057 {
1058 if (!WriteFile(h->h, buffer, n, &bytes_written, NULL))
1059 {
1060 SetErrnoFromWinError(GetLastError());
1061 return GNUNET_SYSERR;
1062 }
1063 }
1064 else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE)
1065 {
1066 LOG(GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write %u bytes\n", n);
1067 if (!WriteFile(h->h, buffer, n, &bytes_written, h->oOverlapWrite))
1068 {
1069 if (GetLastError() != ERROR_IO_PENDING)
1070 {
1071 SetErrnoFromWinError(GetLastError());
1072 LOG(GNUNET_ERROR_TYPE_DEBUG,
1073 "Error writing to pipe: %u\n",
1074 GetLastError());
1075 return GNUNET_SYSERR;
1076 }
1077 LOG(GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n");
1078 if (!GetOverlappedResult(h->h, h->oOverlapWrite, &bytes_written, TRUE))
1079 {
1080 SetErrnoFromWinError(GetLastError());
1081 LOG(GNUNET_ERROR_TYPE_DEBUG,
1082 "Error getting overlapped result while writing to pipe: %u\n",
1083 GetLastError());
1084 return GNUNET_SYSERR;
1085 }
1086 }
1087 else
1088 {
1089 DWORD ovr;
1090 if (!GetOverlappedResult(h->h, h->oOverlapWrite, &ovr, TRUE))
1091 {
1092 LOG(GNUNET_ERROR_TYPE_DEBUG,
1093 "Error getting control overlapped result while writing to pipe: %u\n",
1094 GetLastError());
1095 }
1096 else
1097 {
1098 LOG(GNUNET_ERROR_TYPE_DEBUG,
1099 "Wrote %u bytes (ovr says %u), picking the greatest\n",
1100 bytes_written,
1101 ovr);
1102 }
1103 }
1104 if (bytes_written == 0)
1105 {
1106 if (n > 0)
1107 {
1108 LOG(GNUNET_ERROR_TYPE_DEBUG,
1109 "Wrote %u bytes, returning -1 with EAGAIN\n",
1110 bytes_written);
1111 errno = EAGAIN;
1112 return GNUNET_SYSERR;
1113 }
1114 }
1115 LOG(GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytes_written);
1116 }
1117 else
1118 {
1119 bytes_written = 0;
1120 }
1121 return bytes_written;
1122#else
1123 return write(h->fd, buffer, n); 851 return write(h->fd, buffer, n);
1124#endif
1125} 852}
1126 853
1127 854
@@ -1144,34 +871,7 @@ GNUNET_DISK_file_write_blocking(const struct GNUNET_DISK_FileHandle *h,
1144 return GNUNET_SYSERR; 871 return GNUNET_SYSERR;
1145 } 872 }
1146 873
1147#ifdef MINGW 874
1148 DWORD bytes_written;
1149 /* We do a non-overlapped write, which is as blocking as it gets */
1150 LOG(GNUNET_ERROR_TYPE_DEBUG, "Writing %u bytes\n", n);
1151 if (!WriteFile(h->h, buffer, n, &bytes_written, NULL))
1152 {
1153 SetErrnoFromWinError(GetLastError());
1154 LOG(GNUNET_ERROR_TYPE_DEBUG,
1155 "Error writing to pipe: %u\n",
1156 GetLastError());
1157 return GNUNET_SYSERR;
1158 }
1159 if (bytes_written == 0 && n > 0)
1160 {
1161 LOG(GNUNET_ERROR_TYPE_DEBUG, "Waiting for pipe to clean\n");
1162 WaitForSingleObject(h->h, INFINITE);
1163 if (!WriteFile(h->h, buffer, n, &bytes_written, NULL))
1164 {
1165 SetErrnoFromWinError(GetLastError());
1166 LOG(GNUNET_ERROR_TYPE_DEBUG,
1167 "Error writing to pipe: %u\n",
1168 GetLastError());
1169 return GNUNET_SYSERR;
1170 }
1171 }
1172 LOG(GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytes_written);
1173 return bytes_written;
1174#else
1175 int flags; 875 int flags;
1176 ssize_t ret; 876 ssize_t ret;
1177 877
@@ -1183,7 +883,6 @@ GNUNET_DISK_file_write_blocking(const struct GNUNET_DISK_FileHandle *h,
1183 if (0 == (flags & O_NONBLOCK)) 883 if (0 == (flags & O_NONBLOCK))
1184 (void)fcntl(h->fd, F_SETFL, flags); 884 (void)fcntl(h->fd, F_SETFL, flags);
1185 return ret; 885 return ret;
1186#endif
1187} 886}
1188 887
1189 888
@@ -1486,7 +1185,6 @@ GNUNET_DISK_filename_canonicalize(char *fn)
1486int 1185int
1487GNUNET_DISK_file_change_owner(const char *filename, const char *user) 1186GNUNET_DISK_file_change_owner(const char *filename, const char *user)
1488{ 1187{
1489#ifndef MINGW
1490 struct passwd *pws; 1188 struct passwd *pws;
1491 1189
1492 pws = getpwnam(user); 1190 pws = getpwnam(user);
@@ -1503,7 +1201,6 @@ GNUNET_DISK_file_change_owner(const char *filename, const char *user)
1503 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "chown", filename); 1201 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "chown", filename);
1504 return GNUNET_SYSERR; 1202 return GNUNET_SYSERR;
1505 } 1203 }
1506#endif
1507 return GNUNET_OK; 1204 return GNUNET_OK;
1508} 1205}
1509 1206
@@ -1529,7 +1226,6 @@ GNUNET_DISK_file_lock(struct GNUNET_DISK_FileHandle *fh,
1529 return GNUNET_SYSERR; 1226 return GNUNET_SYSERR;
1530 } 1227 }
1531 1228
1532#ifndef MINGW
1533 struct flock fl; 1229 struct flock fl;
1534 1230
1535 memset(&fl, 0, sizeof(struct flock)); 1231 memset(&fl, 0, sizeof(struct flock));
@@ -1539,33 +1235,6 @@ GNUNET_DISK_file_lock(struct GNUNET_DISK_FileHandle *fh,
1539 fl.l_len = lock_end; 1235 fl.l_len = lock_end;
1540 1236
1541 return fcntl(fh->fd, F_SETLK, &fl) != 0 ? GNUNET_SYSERR : GNUNET_OK; 1237 return fcntl(fh->fd, F_SETLK, &fl) != 0 ? GNUNET_SYSERR : GNUNET_OK;
1542#else
1543 OVERLAPPED o;
1544 off_t diff = lock_end - lock_start;
1545 DWORD diff_low, diff_high;
1546 diff_low = (DWORD)(diff & 0xFFFFFFFF);
1547 diff_high = (DWORD)((diff >> (sizeof(DWORD) * 8)) & 0xFFFFFFFF);
1548
1549 memset(&o, 0, sizeof(OVERLAPPED));
1550 o.Offset = (DWORD)(lock_start & 0xFFFFFFFF);
1551 ;
1552 o.OffsetHigh =
1553 (DWORD)(((lock_start & ~0xFFFFFFFF) >> (sizeof(DWORD) * 8)) & 0xFFFFFFFF);
1554
1555 if (!LockFileEx(fh->h,
1556 (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) |
1557 LOCKFILE_FAIL_IMMEDIATELY,
1558 0,
1559 diff_low,
1560 diff_high,
1561 &o))
1562 {
1563 SetErrnoFromWinError(GetLastError());
1564 return GNUNET_SYSERR;
1565 }
1566
1567 return GNUNET_OK;
1568#endif
1569} 1238}
1570 1239
1571 1240
@@ -1588,7 +1257,6 @@ GNUNET_DISK_file_unlock(struct GNUNET_DISK_FileHandle *fh,
1588 return GNUNET_SYSERR; 1257 return GNUNET_SYSERR;
1589 } 1258 }
1590 1259
1591#ifndef MINGW
1592 struct flock fl; 1260 struct flock fl;
1593 1261
1594 memset(&fl, 0, sizeof(struct flock)); 1262 memset(&fl, 0, sizeof(struct flock));
@@ -1598,27 +1266,6 @@ GNUNET_DISK_file_unlock(struct GNUNET_DISK_FileHandle *fh,
1598 fl.l_len = unlock_end; 1266 fl.l_len = unlock_end;
1599 1267
1600 return fcntl(fh->fd, F_SETLK, &fl) != 0 ? GNUNET_SYSERR : GNUNET_OK; 1268 return fcntl(fh->fd, F_SETLK, &fl) != 0 ? GNUNET_SYSERR : GNUNET_OK;
1601#else
1602 OVERLAPPED o;
1603 off_t diff = unlock_end - unlock_start;
1604 DWORD diff_low, diff_high;
1605 diff_low = (DWORD)(diff & 0xFFFFFFFF);
1606 diff_high = (DWORD)((diff >> (sizeof(DWORD) * 8)) & 0xFFFFFFFF);
1607
1608 memset(&o, 0, sizeof(OVERLAPPED));
1609 o.Offset = (DWORD)(unlock_start & 0xFFFFFFFF);
1610 ;
1611 o.OffsetHigh = (DWORD)(
1612 ((unlock_start & ~0xFFFFFFFF) >> (sizeof(DWORD) * 8)) & 0xFFFFFFFF);
1613
1614 if (!UnlockFileEx(fh->h, 0, diff_low, diff_high, &o))
1615 {
1616 SetErrnoFromWinError(GetLastError());
1617 return GNUNET_SYSERR;
1618 }
1619
1620 return GNUNET_OK;
1621#endif
1622} 1269}
1623 1270
1624 1271
@@ -1642,16 +1289,9 @@ GNUNET_DISK_file_open(const char *fn,
1642 char *expfn; 1289 char *expfn;
1643 struct GNUNET_DISK_FileHandle *ret; 1290 struct GNUNET_DISK_FileHandle *ret;
1644 1291
1645#ifdef MINGW
1646 DWORD access;
1647 DWORD disp;
1648 HANDLE h;
1649 wchar_t wexpfn[MAX_PATH + 1];
1650#else
1651 int oflags; 1292 int oflags;
1652 int mode; 1293 int mode;
1653 int fd; 1294 int fd;
1654#endif
1655 1295
1656 expfn = GNUNET_STRINGS_filename_expand(fn); 1296 expfn = GNUNET_STRINGS_filename_expand(fn);
1657 if (NULL == expfn) 1297 if (NULL == expfn)
@@ -1767,12 +1407,9 @@ GNUNET_DISK_file_open(const char *fn,
1767#endif 1407#endif
1768 1408
1769 ret = GNUNET_new(struct GNUNET_DISK_FileHandle); 1409 ret = GNUNET_new(struct GNUNET_DISK_FileHandle);
1770#ifdef MINGW 1410
1771 ret->h = h;
1772 ret->type = GNUNET_DISK_HANLDE_TYPE_FILE;
1773#else
1774 ret->fd = fd; 1411 ret->fd = fd;
1775#endif 1412
1776 GNUNET_free(expfn); 1413 GNUNET_free(expfn);
1777 return ret; 1414 return ret;
1778} 1415}
@@ -1797,111 +1434,17 @@ GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
1797 1434
1798 ret = GNUNET_OK; 1435 ret = GNUNET_OK;
1799 1436
1800#if MINGW
1801 if (!CloseHandle(h->h))
1802 {
1803 SetErrnoFromWinError(GetLastError());
1804 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "close");
1805 ret = GNUNET_SYSERR;
1806 }
1807 if (h->oOverlapRead)
1808 {
1809 if (!CloseHandle(h->oOverlapRead->hEvent))
1810 {
1811 SetErrnoFromWinError(GetLastError());
1812 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "close");
1813 ret = GNUNET_SYSERR;
1814 }
1815 GNUNET_free(h->oOverlapRead);
1816 }
1817 if (h->oOverlapWrite)
1818 {
1819 if (!CloseHandle(h->oOverlapWrite->hEvent))
1820 {
1821 SetErrnoFromWinError(GetLastError());
1822 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "close");
1823 ret = GNUNET_SYSERR;
1824 }
1825 GNUNET_free(h->oOverlapWrite);
1826 }
1827#else
1828 if (close(h->fd) != 0) 1437 if (close(h->fd) != 0)
1829 { 1438 {
1830 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "close"); 1439 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "close");
1831 ret = GNUNET_SYSERR; 1440 ret = GNUNET_SYSERR;
1832 } 1441 }
1833#endif 1442
1834 GNUNET_free(h); 1443 GNUNET_free(h);
1835 return ret; 1444 return ret;
1836} 1445}
1837 1446
1838 1447
1839#ifdef WINDOWS
1840/**
1841 * Get a GNUnet file handle from a W32 handle.
1842 *
1843 * @param handle native handle
1844 * @return GNUnet file handle corresponding to the W32 handle
1845 */
1846struct GNUNET_DISK_FileHandle *
1847GNUNET_DISK_get_handle_from_w32_handle(HANDLE osfh)
1848{
1849 struct GNUNET_DISK_FileHandle *fh;
1850 DWORD dwret;
1851 enum GNUNET_FILE_Type ftype;
1852
1853 dwret = GetFileType(osfh);
1854 switch (dwret)
1855 {
1856 case FILE_TYPE_DISK:
1857 ftype = GNUNET_DISK_HANLDE_TYPE_FILE;
1858 break;
1859
1860 case FILE_TYPE_PIPE:
1861 ftype = GNUNET_DISK_HANLDE_TYPE_PIPE;
1862 break;
1863
1864 case FILE_TYPE_UNKNOWN:
1865 if ((GetLastError() == NO_ERROR) ||
1866 (GetLastError() == ERROR_INVALID_HANDLE))
1867 {
1868 if (0 != ResetEvent(osfh))
1869 ftype = GNUNET_DISK_HANLDE_TYPE_EVENT;
1870 else
1871 return NULL;
1872 }
1873 else
1874 return NULL;
1875 break;
1876
1877 default:
1878 return NULL;
1879 }
1880
1881 fh = GNUNET_new(struct GNUNET_DISK_FileHandle);
1882
1883 fh->h = osfh;
1884 fh->type = ftype;
1885 if (ftype == GNUNET_DISK_HANLDE_TYPE_PIPE)
1886 {
1887 /**
1888 * Note that we can't make it overlapped if it isn't already.
1889 * (ReOpenFile() is only available in 2003/Vista).
1890 * The process that opened this file in the first place (usually a parent
1891 * process, if this is stdin/stdout/stderr) must make it overlapped,
1892 * otherwise we're screwed, as selecting on non-overlapped handle
1893 * will block.
1894 */
1895 fh->oOverlapRead = GNUNET_new(OVERLAPPED);
1896 fh->oOverlapWrite = GNUNET_new(OVERLAPPED);
1897 fh->oOverlapRead->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
1898 fh->oOverlapWrite->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
1899 }
1900
1901 return fh;
1902}
1903#endif
1904
1905/** 1448/**
1906 * Get a handle from a native integer FD. 1449 * Get a handle from a native integer FD.
1907 * 1450 *
@@ -1916,19 +1459,9 @@ GNUNET_DISK_get_handle_from_int_fd(int fno)
1916 if ((((off_t)-1) == lseek(fno, 0, SEEK_CUR)) && (EBADF == errno)) 1459 if ((((off_t)-1) == lseek(fno, 0, SEEK_CUR)) && (EBADF == errno))
1917 return NULL; /* invalid FD */ 1460 return NULL; /* invalid FD */
1918 1461
1919#ifndef WINDOWS
1920 fh = GNUNET_new(struct GNUNET_DISK_FileHandle); 1462 fh = GNUNET_new(struct GNUNET_DISK_FileHandle);
1921 1463
1922 fh->fd = fno; 1464 fh->fd = fno;
1923#else
1924 intptr_t osfh;
1925
1926 osfh = _get_osfhandle(fno);
1927 if (INVALID_HANDLE_VALUE == (HANDLE)osfh)
1928 return NULL;
1929
1930 fh = GNUNET_DISK_get_handle_from_w32_handle((HANDLE)osfh);
1931#endif
1932 1465
1933 return fh; 1466 return fh;
1934} 1467}
@@ -1962,17 +1495,10 @@ struct GNUNET_DISK_MapHandle {
1962 */ 1495 */
1963 void *addr; 1496 void *addr;
1964 1497
1965#ifdef MINGW
1966 /**
1967 * Underlying OS handle.
1968 */
1969 HANDLE h;
1970#else
1971 /** 1498 /**
1972 * Number of bytes mapped. 1499 * Number of bytes mapped.
1973 */ 1500 */
1974 size_t len; 1501 size_t len;
1975#endif
1976}; 1502};
1977 1503
1978 1504
@@ -2001,50 +1527,6 @@ GNUNET_DISK_file_map(const struct GNUNET_DISK_FileHandle *h,
2001 return NULL; 1527 return NULL;
2002 } 1528 }
2003 1529
2004#ifdef MINGW
2005 DWORD mapAccess, protect;
2006
2007 if ((access & GNUNET_DISK_MAP_TYPE_READ) &&
2008 (access & GNUNET_DISK_MAP_TYPE_WRITE))
2009 {
2010 protect = PAGE_READWRITE;
2011 mapAccess = FILE_MAP_ALL_ACCESS;
2012 }
2013 else if (access & GNUNET_DISK_MAP_TYPE_READ)
2014 {
2015 protect = PAGE_READONLY;
2016 mapAccess = FILE_MAP_READ;
2017 }
2018 else if (access & GNUNET_DISK_MAP_TYPE_WRITE)
2019 {
2020 protect = PAGE_READWRITE;
2021 mapAccess = FILE_MAP_WRITE;
2022 }
2023 else
2024 {
2025 GNUNET_break(0);
2026 return NULL;
2027 }
2028
2029 *m = GNUNET_new(struct GNUNET_DISK_MapHandle);
2030 (*m)->h = CreateFileMapping(h->h, NULL, protect, 0, 0, NULL);
2031 if ((*m)->h == INVALID_HANDLE_VALUE)
2032 {
2033 SetErrnoFromWinError(GetLastError());
2034 GNUNET_free(*m);
2035 return NULL;
2036 }
2037
2038 (*m)->addr = MapViewOfFile((*m)->h, mapAccess, 0, 0, len);
2039 if (!(*m)->addr)
2040 {
2041 SetErrnoFromWinError(GetLastError());
2042 CloseHandle((*m)->h);
2043 GNUNET_free(*m);
2044 }
2045
2046 return (*m)->addr;
2047#else
2048 int prot; 1530 int prot;
2049 1531
2050 prot = 0; 1532 prot = 0;
@@ -2062,7 +1544,6 @@ GNUNET_DISK_file_map(const struct GNUNET_DISK_FileHandle *h,
2062 } 1544 }
2063 (*m)->len = len; 1545 (*m)->len = len;
2064 return (*m)->addr; 1546 return (*m)->addr;
2065#endif
2066} 1547}
2067 1548
2068/** 1549/**
@@ -2081,18 +1562,8 @@ GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
2081 return GNUNET_SYSERR; 1562 return GNUNET_SYSERR;
2082 } 1563 }
2083 1564
2084#ifdef MINGW
2085 ret = UnmapViewOfFile(h->addr) ? GNUNET_OK : GNUNET_SYSERR;
2086 if (ret != GNUNET_OK)
2087 SetErrnoFromWinError(GetLastError());
2088 if (!CloseHandle(h->h) && (ret == GNUNET_OK))
2089 {
2090 ret = GNUNET_SYSERR;
2091 SetErrnoFromWinError(GetLastError());
2092 }
2093#else
2094 ret = munmap(h->addr, h->len) != -1 ? GNUNET_OK : GNUNET_SYSERR; 1565 ret = munmap(h->addr, h->len) != -1 ? GNUNET_OK : GNUNET_SYSERR;
2095#endif 1566
2096 GNUNET_free(h); 1567 GNUNET_free(h);
2097 return ret; 1568 return ret;
2098} 1569}
@@ -2112,14 +1583,7 @@ GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h)
2112 return GNUNET_SYSERR; 1583 return GNUNET_SYSERR;
2113 } 1584 }
2114 1585
2115#ifdef MINGW 1586#if defined(FREEBSD) || defined(OPENBSD) || defined(DARWIN)
2116 int ret;
2117
2118 ret = FlushFileBuffers(h->h) ? GNUNET_OK : GNUNET_SYSERR;
2119 if (ret != GNUNET_OK)
2120 SetErrnoFromWinError(GetLastError());
2121 return ret;
2122#elif defined(FREEBSD) || defined(OPENBSD) || defined(DARWIN)
2123 return fsync(h->fd) == -1 ? GNUNET_SYSERR : GNUNET_OK; 1587 return fsync(h->fd) == -1 ? GNUNET_SYSERR : GNUNET_OK;
2124#else 1588#else
2125 return fdatasync(h->fd) == -1 ? GNUNET_SYSERR : GNUNET_OK; 1589 return fdatasync(h->fd) == -1 ? GNUNET_SYSERR : GNUNET_OK;
@@ -2127,151 +1591,6 @@ GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h)
2127} 1591}
2128 1592
2129 1593
2130#if WINDOWS
2131#ifndef PIPE_BUF
2132#define PIPE_BUF 512
2133#endif
2134/* Copyright Bob Byrnes <byrnes <at> curl.com>
2135 http://permalink.gmane.org/gmane.os.cygwin.patches/2121
2136 */
2137/* Create a pipe, and return handles to the read and write ends,
2138 just like CreatePipe, but ensure that the write end permits
2139 FILE_READ_ATTRIBUTES access, on later versions of win32 where
2140 this is supported. This access is needed by NtQueryInformationFile,
2141 which is used to implement select and nonblocking writes.
2142 Note that the return value is either NO_ERROR or GetLastError,
2143 unlike CreatePipe, which returns a bool for success or failure. */
2144static int
2145create_selectable_pipe(PHANDLE read_pipe_ptr,
2146 PHANDLE write_pipe_ptr,
2147 LPSECURITY_ATTRIBUTES sa_ptr,
2148 DWORD psize,
2149 DWORD dwReadMode,
2150 DWORD dwWriteMode)
2151{
2152 /* Default to error. */
2153 *read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE;
2154
2155 HANDLE read_pipe;
2156 HANDLE write_pipe;
2157
2158 /* Ensure that there is enough pipe buffer space for atomic writes. */
2159 if (psize < PIPE_BUF)
2160 psize = PIPE_BUF;
2161
2162 char pipename[MAX_PATH];
2163
2164 /* Retry CreateNamedPipe as long as the pipe name is in use.
2165 * Retrying will probably never be necessary, but we want
2166 * to be as robust as possible. */
2167 while (1)
2168 {
2169 static volatile LONG pipe_unique_id;
2170
2171 snprintf(pipename,
2172 sizeof pipename,
2173 "\\\\.\\pipe\\gnunet-%d-%ld",
2174 getpid(),
2175 InterlockedIncrement((LONG *)&pipe_unique_id));
2176 LOG(GNUNET_ERROR_TYPE_DEBUG,
2177 "CreateNamedPipe: name = %s, size = %lu\n",
2178 pipename,
2179 psize);
2180 /* Use CreateNamedPipe instead of CreatePipe, because the latter
2181 * returns a write handle that does not permit FILE_READ_ATTRIBUTES
2182 * access, on versions of win32 earlier than WinXP SP2.
2183 * CreatePipe also stupidly creates a full duplex pipe, which is
2184 * a waste, since only a single direction is actually used.
2185 * It's important to only allow a single instance, to ensure that
2186 * the pipe was not created earlier by some other process, even if
2187 * the pid has been reused. */
2188 read_pipe = CreateNamedPipeA(pipename,
2189 PIPE_ACCESS_INBOUND |
2190 FILE_FLAG_FIRST_PIPE_INSTANCE | dwReadMode,
2191 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE,
2192 1, /* max instances */
2193 psize, /* output buffer size */
2194 psize, /* input buffer size */
2195 NMPWAIT_USE_DEFAULT_WAIT,
2196 sa_ptr);
2197
2198 if (read_pipe != INVALID_HANDLE_VALUE)
2199 {
2200 LOG(GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", read_pipe);
2201 break;
2202 }
2203
2204 DWORD err = GetLastError();
2205
2206 switch (err)
2207 {
2208 case ERROR_PIPE_BUSY:
2209 /* The pipe is already open with compatible parameters.
2210 * Pick a new name and retry. */
2211 LOG(GNUNET_ERROR_TYPE_DEBUG, "pipe busy, retrying\n");
2212 continue;
2213
2214 case ERROR_ACCESS_DENIED:
2215 /* The pipe is already open with incompatible parameters.
2216 * Pick a new name and retry. */
2217 LOG(GNUNET_ERROR_TYPE_DEBUG, "pipe access denied, retrying\n");
2218 continue;
2219
2220 case ERROR_CALL_NOT_IMPLEMENTED:
2221 /* We are on an older Win9x platform without named pipes.
2222 * Return an anonymous pipe as the best approximation. */
2223 LOG(GNUNET_ERROR_TYPE_DEBUG,
2224 "CreateNamedPipe not implemented, resorting to "
2225 "CreatePipe: size = %lu\n",
2226 psize);
2227 if (CreatePipe(read_pipe_ptr, write_pipe_ptr, sa_ptr, psize))
2228 {
2229 LOG(GNUNET_ERROR_TYPE_DEBUG,
2230 "pipe read handle = %p, write handle = %p\n",
2231 *read_pipe_ptr,
2232 *write_pipe_ptr);
2233 return GNUNET_OK;
2234 }
2235 err = GetLastError();
2236 LOG(GNUNET_ERROR_TYPE_ERROR, "CreatePipe failed: %d\n", err);
2237 return err;
2238
2239 default:
2240 LOG(GNUNET_ERROR_TYPE_ERROR, "CreateNamedPipe failed: %d\n", err);
2241 return err;
2242 }
2243 /* NOTREACHED */
2244 }
2245 LOG(GNUNET_ERROR_TYPE_DEBUG, "CreateFile: name = %s\n", pipename);
2246
2247 /* Open the named pipe for writing.
2248 * Be sure to permit FILE_READ_ATTRIBUTES access. */
2249 write_pipe = CreateFileA(pipename,
2250 GENERIC_WRITE | FILE_READ_ATTRIBUTES,
2251 0, /* share mode */
2252 sa_ptr,
2253 OPEN_EXISTING,
2254 dwWriteMode, /* flags and attributes */
2255 0); /* handle to template file */
2256
2257 if (write_pipe == INVALID_HANDLE_VALUE)
2258 {
2259 /* Failure. */
2260 DWORD err = GetLastError();
2261
2262 LOG(GNUNET_ERROR_TYPE_DEBUG, "CreateFile failed: %d\n", err);
2263 CloseHandle(read_pipe);
2264 return err;
2265 }
2266 LOG(GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n", write_pipe);
2267 /* Success. */
2268 *read_pipe_ptr = read_pipe;
2269 *write_pipe_ptr = write_pipe;
2270 return GNUNET_OK;
2271}
2272#endif
2273
2274
2275/** 1594/**
2276 * Creates an interprocess channel 1595 * Creates an interprocess channel
2277 * 1596 *
@@ -2287,7 +1606,6 @@ GNUNET_DISK_pipe(int blocking_read,
2287 int inherit_read, 1606 int inherit_read,
2288 int inherit_write) 1607 int inherit_write)
2289{ 1608{
2290#ifndef MINGW
2291 int fd[2]; 1609 int fd[2];
2292 int ret; 1610 int ret;
2293 int eno; 1611 int eno;
@@ -2303,99 +1621,6 @@ GNUNET_DISK_pipe(int blocking_read,
2303 return NULL; 1621 return NULL;
2304 } 1622 }
2305 return GNUNET_DISK_pipe_from_fd(blocking_read, blocking_write, fd); 1623 return GNUNET_DISK_pipe_from_fd(blocking_read, blocking_write, fd);
2306#else
2307 struct GNUNET_DISK_PipeHandle *p;
2308 BOOL ret;
2309 HANDLE tmp_handle;
2310 int save_errno;
2311
2312 p = GNUNET_new(struct GNUNET_DISK_PipeHandle);
2313 p->fd[0] = GNUNET_new(struct GNUNET_DISK_FileHandle);
2314 p->fd[1] = GNUNET_new(struct GNUNET_DISK_FileHandle);
2315
2316 /* All pipes are overlapped. If you want them to block - just
2317 * call WriteFile() and ReadFile() with NULL overlapped pointer.
2318 * NOTE: calling with NULL overlapped pointer works only
2319 * for pipes, and doesn't seem to be a documented feature.
2320 * It will NOT work for files, because overlapped files need
2321 * to read offsets from the overlapped structure, regardless.
2322 * Pipes are not seekable, and need no offsets, which is
2323 * probably why it works for them.
2324 */
2325 ret = create_selectable_pipe(&p->fd[0]->h,
2326 &p->fd[1]->h,
2327 NULL,
2328 0,
2329 FILE_FLAG_OVERLAPPED,
2330 FILE_FLAG_OVERLAPPED);
2331 if (!ret)
2332 {
2333 SetErrnoFromWinError(GetLastError());
2334 save_errno = errno;
2335 GNUNET_free(p->fd[0]);
2336 GNUNET_free(p->fd[1]);
2337 GNUNET_free(p);
2338 errno = save_errno;
2339 return NULL;
2340 }
2341 if (!DuplicateHandle(GetCurrentProcess(),
2342 p->fd[0]->h,
2343 GetCurrentProcess(),
2344 &tmp_handle,
2345 0,
2346 inherit_read == GNUNET_YES ? TRUE : FALSE,
2347 DUPLICATE_SAME_ACCESS))
2348 {
2349 SetErrnoFromWinError(GetLastError());
2350 save_errno = errno;
2351 CloseHandle(p->fd[0]->h);
2352 CloseHandle(p->fd[1]->h);
2353 GNUNET_free(p->fd[0]);
2354 GNUNET_free(p->fd[1]);
2355 GNUNET_free(p);
2356 errno = save_errno;
2357 return NULL;
2358 }
2359 CloseHandle(p->fd[0]->h);
2360 p->fd[0]->h = tmp_handle;
2361
2362 if (!DuplicateHandle(GetCurrentProcess(),
2363 p->fd[1]->h,
2364 GetCurrentProcess(),
2365 &tmp_handle,
2366 0,
2367 inherit_write == GNUNET_YES ? TRUE : FALSE,
2368 DUPLICATE_SAME_ACCESS))
2369 {
2370 SetErrnoFromWinError(GetLastError());
2371 save_errno = errno;
2372 CloseHandle(p->fd[0]->h);
2373 CloseHandle(p->fd[1]->h);
2374 GNUNET_free(p->fd[0]);
2375 GNUNET_free(p->fd[1]);
2376 GNUNET_free(p);
2377 errno = save_errno;
2378 return NULL;
2379 }
2380 CloseHandle(p->fd[1]->h);
2381 p->fd[1]->h = tmp_handle;
2382
2383 p->fd[0]->type = GNUNET_DISK_HANLDE_TYPE_PIPE;
2384 p->fd[1]->type = GNUNET_DISK_HANLDE_TYPE_PIPE;
2385
2386 p->fd[0]->oOverlapRead = GNUNET_new(OVERLAPPED);
2387 p->fd[0]->oOverlapWrite = GNUNET_new(OVERLAPPED);
2388 p->fd[1]->oOverlapRead = GNUNET_new(OVERLAPPED);
2389 p->fd[1]->oOverlapWrite = GNUNET_new(OVERLAPPED);
2390
2391 p->fd[0]->oOverlapRead->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
2392 p->fd[0]->oOverlapWrite->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
2393
2394 p->fd[1]->oOverlapRead->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
2395 p->fd[1]->oOverlapWrite->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
2396
2397 return p;
2398#endif
2399} 1624}
2400 1625
2401 1626
@@ -2416,7 +1641,6 @@ GNUNET_DISK_pipe_from_fd(int blocking_read, int blocking_write, int fd[2])
2416 1641
2417 p = GNUNET_new(struct GNUNET_DISK_PipeHandle); 1642 p = GNUNET_new(struct GNUNET_DISK_PipeHandle);
2418 1643
2419#ifndef MINGW
2420 int ret; 1644 int ret;
2421 int flags; 1645 int flags;
2422 int eno = 0; /* make gcc happy */ 1646 int eno = 0; /* make gcc happy */
@@ -2481,44 +1705,7 @@ GNUNET_DISK_pipe_from_fd(int blocking_read, int blocking_write, int fd[2])
2481 errno = eno; 1705 errno = eno;
2482 return NULL; 1706 return NULL;
2483 } 1707 }
2484#else 1708
2485 if (fd[0] >= 0)
2486 {
2487 p->fd[0] = GNUNET_new(struct GNUNET_DISK_FileHandle);
2488 p->fd[0]->h = (HANDLE)_get_osfhandle(fd[0]);
2489 if (p->fd[0]->h != INVALID_HANDLE_VALUE)
2490 {
2491 p->fd[0]->type = GNUNET_DISK_HANLDE_TYPE_PIPE;
2492 p->fd[0]->oOverlapRead = GNUNET_new(OVERLAPPED);
2493 p->fd[0]->oOverlapWrite = GNUNET_new(OVERLAPPED);
2494 p->fd[0]->oOverlapRead->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
2495 p->fd[0]->oOverlapWrite->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
2496 }
2497 else
2498 {
2499 GNUNET_free(p->fd[0]);
2500 p->fd[0] = NULL;
2501 }
2502 }
2503 if (fd[1] >= 0)
2504 {
2505 p->fd[1] = GNUNET_new(struct GNUNET_DISK_FileHandle);
2506 p->fd[1]->h = (HANDLE)_get_osfhandle(fd[1]);
2507 if (p->fd[1]->h != INVALID_HANDLE_VALUE)
2508 {
2509 p->fd[1]->type = GNUNET_DISK_HANLDE_TYPE_PIPE;
2510 p->fd[1]->oOverlapRead = GNUNET_new(OVERLAPPED);
2511 p->fd[1]->oOverlapWrite = GNUNET_new(OVERLAPPED);
2512 p->fd[1]->oOverlapRead->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
2513 p->fd[1]->oOverlapWrite->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
2514 }
2515 else
2516 {
2517 GNUNET_free(p->fd[1]);
2518 p->fd[1] = NULL;
2519 }
2520 }
2521#endif
2522 return p; 1709 return p;
2523} 1710}
2524 1711
@@ -2671,15 +1858,10 @@ GNUNET_DISK_internal_file_handle_(const struct GNUNET_DISK_FileHandle *fh,
2671{ 1858{
2672 if (NULL == fh) 1859 if (NULL == fh)
2673 return GNUNET_SYSERR; 1860 return GNUNET_SYSERR;
2674#ifdef MINGW 1861
2675 if (dst_len < sizeof(HANDLE))
2676 return GNUNET_SYSERR;
2677 *((HANDLE *)dst) = fh->h;
2678#else
2679 if (dst_len < sizeof(int)) 1862 if (dst_len < sizeof(int))
2680 return GNUNET_SYSERR; 1863 return GNUNET_SYSERR;
2681 *((int *)dst) = fh->fd; 1864 *((int *)dst) = fh->fd;
2682#endif
2683 1865
2684 return GNUNET_OK; 1866 return GNUNET_OK;
2685} 1867}
diff --git a/src/util/dnsparser.c b/src/util/dnsparser.c
index fcec0d4f1..f187803bc 100644
--- a/src/util/dnsparser.c
+++ b/src/util/dnsparser.c
@@ -38,9 +38,6 @@
38#include <idn/idna.h> 38#include <idn/idna.h>
39#endif 39#endif
40#endif 40#endif
41#if WINDOWS
42#include <idn-free.h>
43#endif
44#include "gnunet_util_lib.h" 41#include "gnunet_util_lib.h"
45 42
46 43
@@ -65,11 +62,7 @@ GNUNET_DNSPARSER_check_label(const char *label)
65 if (IDNA_SUCCESS != idna_to_ascii_8z(label, &output, IDNA_ALLOW_UNASSIGNED)) 62 if (IDNA_SUCCESS != idna_to_ascii_8z(label, &output, IDNA_ALLOW_UNASSIGNED))
66 return GNUNET_SYSERR; 63 return GNUNET_SYSERR;
67 slen = strlen(output); 64 slen = strlen(output);
68#if WINDOWS
69 idn_free(output);
70#else
71 free(output); 65 free(output);
72#endif
73 return (slen > 63) ? GNUNET_SYSERR : GNUNET_OK; 66 return (slen > 63) ? GNUNET_SYSERR : GNUNET_OK;
74} 67}
75 68
@@ -101,11 +94,7 @@ GNUNET_DNSPARSER_check_name(const char *name)
101 if (IDNA_SUCCESS != idna_to_ascii_8z(name, &output, IDNA_ALLOW_UNASSIGNED)) 94 if (IDNA_SUCCESS != idna_to_ascii_8z(name, &output, IDNA_ALLOW_UNASSIGNED))
102 return GNUNET_SYSERR; 95 return GNUNET_SYSERR;
103 slen = strlen(output); 96 slen = strlen(output);
104#if WINDOWS
105 idn_free(output);
106#else
107 free(output); 97 free(output);
108#endif
109 return (slen > 253) ? GNUNET_SYSERR : GNUNET_OK; 98 return (slen > 253) ? GNUNET_SYSERR : GNUNET_OK;
110} 99}
111 100
@@ -276,11 +265,7 @@ parse_name(const char *udp_payload,
276 { 265 {
277 GNUNET_free(tmp); 266 GNUNET_free(tmp);
278 GNUNET_asprintf(&tmp, "%s%s.", ret, utf8); 267 GNUNET_asprintf(&tmp, "%s%s.", ret, utf8);
279#if WINDOWS
280 idn_free(utf8);
281#else
282 free(utf8); 268 free(utf8);
283#endif
284 } 269 }
285 GNUNET_free(ret); 270 GNUNET_free(ret);
286 ret = tmp; 271 ret = tmp;
@@ -954,18 +939,10 @@ GNUNET_DNSPARSER_builder_add_name(char *dst,
954 while (NULL != dot); 939 while (NULL != dot);
955 dst[pos++] = '\0'; /* terminator */ 940 dst[pos++] = '\0'; /* terminator */
956 *off = pos; 941 *off = pos;
957#if WINDOWS
958 idn_free(idna_start);
959#else
960 free(idna_start); 942 free(idna_start);
961#endif
962 return GNUNET_OK; 943 return GNUNET_OK;
963fail: 944fail:
964#if WINDOWS
965 idn_free(idna_start);
966#else
967 free(idna_start); 945 free(idna_start);
968#endif
969 return GNUNET_NO; 946 return GNUNET_NO;
970} 947}
971 948
diff --git a/src/util/getopt.c b/src/util/getopt.c
index 19b160cc9..3b144457a 100644
--- a/src/util/getopt.c
+++ b/src/util/getopt.c
@@ -52,12 +52,6 @@
52#define LOG_STRERROR(kind, syscall) \ 52#define LOG_STRERROR(kind, syscall) \
53 GNUNET_log_from_strerror(kind, "util-getopt", syscall) 53 GNUNET_log_from_strerror(kind, "util-getopt", syscall)
54 54
55#if defined(WIN32) && !defined(__CYGWIN32__)
56/* It's not Unix, really. See? Capital letters. */
57#include <windows.h>
58#define getpid() GetCurrentProcessId()
59#endif
60
61#ifndef _ 55#ifndef _
62/* This is for other GNU distributions with internationalized messages. 56/* This is for other GNU distributions with internationalized messages.
63 When compiling libc, the _ macro is predefined. */ 57 When compiling libc, the _ macro is predefined. */
diff --git a/src/util/gnunet-helper-w32-console.c b/src/util/gnunet-helper-w32-console.c
deleted file mode 100644
index b773e27d7..000000000
--- a/src/util/gnunet-helper-w32-console.c
+++ /dev/null
@@ -1,319 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2014 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file src/util/gnunet-helper-w32-console.c
23 * @brief Does blocking reads from the console, writes the results
24 * into stdout, turning blocking console I/O into non-blocking
25 * pipe I/O. For W32 only.
26 * @author LRN
27 */
28#include "platform.h"
29#include "gnunet_crypto_lib.h"
30#include "gnunet_common.h"
31#include "gnunet-helper-w32-console.h"
32
33static unsigned long buffer_size;
34
35static int chars;
36
37static HANDLE parent_handle;
38
39/**
40 * Write @a size bytes from @a buf into @a output.
41 *
42 * @param output the descriptor to write into
43 * @param buf buffer with data to write
44 * @param size number of bytes to write
45 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
46 */
47static int
48write_all(int output,
49 const void *buf,
50 size_t size)
51{
52 const char *cbuf = buf;
53 size_t total;
54 ssize_t wr;
55
56 total = 0;
57 do
58 {
59 wr = write(output,
60 &cbuf[total],
61 size - total);
62 if (wr > 0)
63 total += wr;
64 }
65 while ((wr > 0) && (total < size));
66 if (wr <= 0)
67 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
68 "Failed to write to stdout: %s\n",
69 strerror(errno));
70 return (total == size) ? GNUNET_OK : GNUNET_SYSERR;
71}
72
73
74/**
75 * Write message to the master process.
76 *
77 * @param output the descriptor to write into
78 * @param message_type message type to use
79 * @param data data to append, NULL for none
80 * @param data_length number of bytes in @a data
81 * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow)
82 */
83static int
84write_message(int output,
85 uint16_t message_type,
86 const char *data,
87 size_t data_length)
88{
89 struct GNUNET_MessageHeader hdr;
90
91#if 0
92 fprintf(stderr,
93 "Helper sends %u-byte message of type %u\n",
94 (unsigned int)(sizeof(struct GNUNET_MessageHeader) + data_length),
95 (unsigned int)message_type);
96#endif
97 hdr.type = htons(message_type);
98 hdr.size = htons(sizeof(struct GNUNET_MessageHeader) + data_length);
99 if (GNUNET_OK != write_all(output, &hdr, sizeof(hdr)))
100 return GNUNET_SYSERR;
101 if (GNUNET_OK != write_all(output, data, data_length))
102 return GNUNET_SYSERR;
103 return GNUNET_OK;
104}
105
106
107/**
108 * Main function of the helper process. Reads input events from console,
109 * writes messages, into stdout.
110 *
111 * @param console a handle to a console to read from
112 * @param output_stream a stream to write messages to
113 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
114 */
115static int
116read_events(HANDLE console, int output_stream)
117{
118 DWORD rr;
119 BOOL b;
120 INPUT_RECORD *buf;
121 DWORD i;
122 int result;
123
124 result = GNUNET_SYSERR;
125 buf = malloc(sizeof(INPUT_RECORD) * buffer_size);
126 if (NULL == buf)
127 return result;
128 b = TRUE;
129 rr = 1;
130 while (TRUE == b && 0 < rr)
131 {
132 rr = 0;
133 b = ReadConsoleInput(console, buf, buffer_size, &rr);
134 if (FALSE == b && ERROR_SUCCESS != GetLastError())
135 break;
136 for (i = 0; i < rr; i++)
137 {
138 int r;
139 r = write_message(output_stream,
140 GNUNET_MESSAGE_TYPE_W32_CONSOLE_HELPER_INPUT,
141 (const char *)&buf[i],
142 sizeof(INPUT_RECORD));
143 if (GNUNET_OK != r)
144 break;
145 }
146 if (rr + 1 != i)
147 break;
148 }
149 return result;
150}
151
152
153/**
154 * Main function of the helper process. Reads chars from console,
155 * writes messages, into stdout.
156 *
157 * @param console a handle to a console to read from
158 * @param output_stream a stream to write messages to
159 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
160 */
161static int
162read_chars(HANDLE console, int output_stream)
163{
164 DWORD rr;
165 BOOL b;
166 wchar_t *buf;
167 char *small_ubuf;
168 char *large_ubuf;
169 char *ubuf;
170 int conv;
171 int r;
172 int result;
173
174 result = GNUNET_SYSERR;
175 buf = malloc(sizeof(wchar_t) * buffer_size);
176 if (NULL == buf)
177 return result;
178 small_ubuf = malloc(sizeof(char) * buffer_size * 2);
179 if (NULL == small_ubuf)
180 {
181 free(buf);
182 return result;
183 }
184 b = TRUE;
185 rr = 1;
186 while (TRUE == b)
187 {
188 large_ubuf = NULL;
189 rr = 0;
190 b = ReadConsoleW(console, buf, buffer_size, &rr, NULL);
191 if (FALSE == b && ERROR_SUCCESS != GetLastError())
192 break;
193 if (0 == rr)
194 continue;
195 /* Caveat: if the UTF-16-encoded string is longer than BUFFER_SIZE,
196 * there's a possibility that we will read up to a word that constitutes
197 * a part of a multi-byte UTF-16 codepoint. Converting that to UTF-8
198 * will either drop invalid word (flags == 0) or bail out because of it
199 * (flags == WC_ERR_INVALID_CHARS).
200 */
201 conv = WideCharToMultiByte(CP_UTF8, 0, buf, rr, small_ubuf, 0, NULL, FALSE);
202 if (0 == conv || 0xFFFD == conv)
203 continue;
204 if (conv <= buffer_size * 2 - 1)
205 {
206 memset(small_ubuf, 0, buffer_size * 2);
207 conv = WideCharToMultiByte(CP_UTF8, 0, buf, rr, small_ubuf, buffer_size * 2 - 1, NULL, FALSE);
208 if (0 == conv || 0xFFFD == conv)
209 continue;
210 ubuf = small_ubuf;
211 }
212 else
213 {
214 large_ubuf = malloc(conv + 1);
215 if (NULL == large_ubuf)
216 continue;
217 memset(large_ubuf, 0, conv + 1);
218 conv = WideCharToMultiByte(CP_UTF8, 0, buf, rr, large_ubuf, conv, NULL, FALSE);
219 if (0 == conv || 0xFFFD == conv)
220 {
221 free(large_ubuf);
222 large_ubuf = NULL;
223 continue;
224 }
225 ubuf = large_ubuf;
226 }
227 r = write_message(output_stream,
228 GNUNET_MESSAGE_TYPE_W32_CONSOLE_HELPER_CHARS,
229 ubuf,
230 conv + 1);
231 if (large_ubuf)
232 free(large_ubuf);
233 if (GNUNET_OK != r)
234 break;
235 }
236 free(small_ubuf);
237 free(buf);
238 return result;
239}
240
241
242DWORD WINAPI
243watch_parent(LPVOID param)
244{
245 WaitForSingleObject(parent_handle, INFINITE);
246 ExitProcess(1);
247 return 0;
248}
249
250/**
251 * Main function of the helper process to extract meta data.
252 *
253 * @param argc should be 3
254 * @param argv [0] our binary name
255 * [1] name of the file or directory to process
256 * [2] "-" to disable extraction, NULL for defaults,
257 * otherwise custom plugins to load from LE
258 * @return 0 on success
259 */
260int
261main(int argc,
262 char *const *argv)
263{
264 HANDLE os_stdin;
265 DWORD parent_pid;
266
267 /* We're using stdout to communicate binary data back to the parent; use
268 * binary mode.
269 */
270 _setmode(1, _O_BINARY);
271
272 if (argc != 4)
273 {
274 fprintf(stderr,
275 "Usage: gnunet-helper-w32-console <chars|events> <buffer size> <parent pid>\n");
276 return 2;
277 }
278
279 if (0 == strcmp(argv[1], "chars"))
280 chars = GNUNET_YES;
281 else if (0 == strcmp(argv[1], "events"))
282 chars = GNUNET_NO;
283 else
284 return 3;
285
286 buffer_size = strtoul(argv[2], NULL, 10);
287 if (buffer_size <= 0)
288 return 4;
289
290 parent_pid = (DWORD)strtoul(argv[3], NULL, 10);
291 if (parent_pid == 0)
292 return 5;
293 parent_handle = OpenProcess(SYNCHRONIZE, FALSE, parent_pid);
294 if (NULL == parent_handle)
295 return 6;
296
297 CreateThread(NULL, 0, watch_parent, NULL, 0, NULL);
298
299 if (0 == AttachConsole(ATTACH_PARENT_PROCESS))
300 {
301 if (ERROR_ACCESS_DENIED != GetLastError())
302 return 5;
303 }
304
305 /* Helper API overrides stdin, so we just attach to the console that we
306 * inherited. If we did.
307 */
308 os_stdin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
309 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
310 if (INVALID_HANDLE_VALUE == os_stdin)
311 return 1;
312
313 if (GNUNET_NO == chars)
314 return read_events(os_stdin, 1);
315 else
316 return read_chars(os_stdin, 1);
317}
318
319/* end of gnunet-helper-w32-console.c */
diff --git a/src/util/gnunet-helper-w32-console.h b/src/util/gnunet-helper-w32-console.h
deleted file mode 100644
index 6af357cb7..000000000
--- a/src/util/gnunet-helper-w32-console.h
+++ /dev/null
@@ -1,70 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2014 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author LRN
23 * @file src/util/gnunet-helper-w32-console.h
24 */
25#ifndef GNUNET_HELPER_W32_CONSOLE_H
26#define GNUNET_HELPER_W32_CONSOLE_H
27
28#include "platform.h"
29#include "gnunet_crypto_lib.h"
30#include "gnunet_common.h"
31
32/**
33 * Input event from the console
34 */
35#define GNUNET_MESSAGE_TYPE_W32_CONSOLE_HELPER_INPUT 60000
36
37/**
38 * Chars from the console
39 */
40#define GNUNET_MESSAGE_TYPE_W32_CONSOLE_HELPER_CHARS 60001
41
42GNUNET_NETWORK_STRUCT_BEGIN
43
44/**
45 * This is just a dump of the INPUT_RECORD structure.
46 */
47struct GNUNET_W32_CONSOLE_input {
48 /**
49 * Type: GNUNET_MESSAGE_TYPE_W32_CONSOLE_HELPER_INPUT
50 */
51 struct GNUNET_MessageHeader header;
52
53 INPUT_RECORD input_record GNUNET_PACKED;
54};
55
56/**
57 * A header, followed by UTF8-encoded, 0-terminated string
58 */
59struct GNUNET_W32_CONSOLE_chars {
60 /**
61 * Type: GNUNET_MESSAGE_TYPE_W32_CONSOLE_HELPER_CHARS
62 */
63 struct GNUNET_MessageHeader header;
64
65 /* followed by a string */
66};
67
68GNUNET_NETWORK_STRUCT_END
69
70#endif
diff --git a/src/util/network.c b/src/util/network.c
index 7a1d27f0e..ec76424eb 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -44,11 +44,7 @@
44 * @brief handle to a socket 44 * @brief handle to a socket
45 */ 45 */
46struct GNUNET_NETWORK_Handle { 46struct GNUNET_NETWORK_Handle {
47#ifndef MINGW
48 int fd; 47 int fd;
49#else
50 _win_socket fd;
51#endif
52 48
53 /** 49 /**
54 * Address family / domain. 50 * Address family / domain.
@@ -119,11 +115,7 @@ GNUNET_NETWORK_test_pf(int pf)
119 } 115 }
120 else 116 else
121 { 117 {
122#if WINDOWS
123 closesocket(s);
124#else
125 close(s); 118 close(s);
126#endif
127 ret = GNUNET_OK; 119 ret = GNUNET_OK;
128 } 120 }
129 switch (pf) 121 switch (pf)
@@ -189,7 +181,6 @@ GNUNET_NETWORK_shorten_unixpath(char *unixpath)
189} 181}
190 182
191 183
192#ifndef WINDOWS
193/** 184/**
194 * If services crash, they can leave a unix domain socket file on the 185 * If services crash, they can leave a unix domain socket file on the
195 * disk. This needs to be manually removed, because otherwise both 186 * disk. This needs to be manually removed, because otherwise both
@@ -238,8 +229,6 @@ GNUNET_NETWORK_unix_precheck(const struct sockaddr_un *un)
238 "unlink", 229 "unlink",
239 un->sun_path); 230 un->sun_path);
240} 231}
241#endif
242
243 232
244 233
245#ifndef FD_COPY 234#ifndef FD_COPY
@@ -258,24 +247,6 @@ int
258GNUNET_NETWORK_socket_set_blocking(struct GNUNET_NETWORK_Handle *fd, 247GNUNET_NETWORK_socket_set_blocking(struct GNUNET_NETWORK_Handle *fd,
259 int doBlock) 248 int doBlock)
260{ 249{
261#if MINGW
262 u_long mode;
263
264 mode = !doBlock;
265 if (SOCKET_ERROR ==
266 ioctlsocket(fd->fd,
267 FIONBIO,
268 &mode))
269
270 {
271 SetErrnoFromWinsockError(WSAGetLastError());
272 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING,
273 "ioctlsocket");
274 return GNUNET_SYSERR;
275 }
276 return GNUNET_OK;
277#else
278 /* not MINGW */
279 int flags = fcntl(fd->fd, F_GETFL); 250 int flags = fcntl(fd->fd, F_GETFL);
280 251
281 if (flags == -1) 252 if (flags == -1)
@@ -299,7 +270,6 @@ GNUNET_NETWORK_socket_set_blocking(struct GNUNET_NETWORK_Handle *fd,
299 return GNUNET_SYSERR; 270 return GNUNET_SYSERR;
300 } 271 }
301 return GNUNET_OK; 272 return GNUNET_OK;
302#endif
303} 273}
304 274
305 275
@@ -313,7 +283,6 @@ GNUNET_NETWORK_socket_set_blocking(struct GNUNET_NETWORK_Handle *fd,
313static int 283static int
314socket_set_inheritable(const struct GNUNET_NETWORK_Handle *h) 284socket_set_inheritable(const struct GNUNET_NETWORK_Handle *h)
315{ 285{
316#ifndef MINGW
317 int i; 286 int i;
318 i = fcntl(h->fd, F_GETFD); 287 i = fcntl(h->fd, F_GETFD);
319 if (i < 0) 288 if (i < 0)
@@ -323,16 +292,7 @@ socket_set_inheritable(const struct GNUNET_NETWORK_Handle *h)
323 i |= FD_CLOEXEC; 292 i |= FD_CLOEXEC;
324 if (fcntl(h->fd, F_SETFD, i) < 0) 293 if (fcntl(h->fd, F_SETFD, i) < 0)
325 return GNUNET_SYSERR; 294 return GNUNET_SYSERR;
326#else 295
327 BOOL b;
328 SetLastError(0);
329 b = SetHandleInformation((HANDLE)h->fd, HANDLE_FLAG_INHERIT, 0);
330 if (!b)
331 {
332 SetErrnoFromWinsockError(WSAGetLastError());
333 return GNUNET_SYSERR;
334 }
335#endif
336 return GNUNET_OK; 296 return GNUNET_OK;
337} 297}
338 298
@@ -368,7 +328,6 @@ socket_set_nosigpipe(const struct GNUNET_NETWORK_Handle *h)
368static void 328static void
369socket_set_nodelay(const struct GNUNET_NETWORK_Handle *h) 329socket_set_nodelay(const struct GNUNET_NETWORK_Handle *h)
370{ 330{
371#ifndef WINDOWS
372 int value = 1; 331 int value = 1;
373 332
374 if (0 != 333 if (0 !=
@@ -378,18 +337,6 @@ socket_set_nodelay(const struct GNUNET_NETWORK_Handle *h)
378 &value, sizeof(value))) 337 &value, sizeof(value)))
379 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, 338 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING,
380 "setsockopt"); 339 "setsockopt");
381#else
382 const char *abs_value = "1";
383
384 if (0 !=
385 setsockopt(h->fd,
386 IPPROTO_TCP,
387 TCP_NODELAY,
388 (const void *)abs_value,
389 sizeof(abs_value)))
390 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING,
391 "setsockopt");
392#endif
393} 340}
394 341
395 342
@@ -416,22 +363,19 @@ initialize_network_handle(struct GNUNET_NETWORK_Handle *h,
416 h->type = type; 363 h->type = type;
417 if (h->fd == INVALID_SOCKET) 364 if (h->fd == INVALID_SOCKET)
418 { 365 {
419#ifdef MINGW
420 SetErrnoFromWinsockError(WSAGetLastError());
421#endif
422 eno = errno; 366 eno = errno;
423 GNUNET_free(h); 367 GNUNET_free(h);
424 errno = eno; 368 errno = eno;
425 return GNUNET_SYSERR; 369 return GNUNET_SYSERR;
426 } 370 }
427#ifndef MINGW 371
428 if (h->fd >= FD_SETSIZE) 372 if (h->fd >= FD_SETSIZE)
429 { 373 {
430 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(h)); 374 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(h));
431 errno = EMFILE; 375 errno = EMFILE;
432 return GNUNET_SYSERR; 376 return GNUNET_SYSERR;
433 } 377 }
434#endif 378
435 if (GNUNET_OK != socket_set_inheritable(h)) 379 if (GNUNET_OK != socket_set_inheritable(h))
436 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 380 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
437 "socket_set_inheritable"); 381 "socket_set_inheritable");
@@ -549,7 +493,6 @@ GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc,
549 } 493 }
550#endif 494#endif
551#endif 495#endif
552#ifndef WINDOWS
553 if (AF_UNIX == address->sa_family) 496 if (AF_UNIX == address->sa_family)
554 GNUNET_NETWORK_unix_precheck((const struct sockaddr_un *)address); 497 GNUNET_NETWORK_unix_precheck((const struct sockaddr_un *)address);
555 { 498 {
@@ -576,28 +519,21 @@ GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc,
576 not_abstract = 1; 519 not_abstract = 1;
577 if (not_abstract) 520 if (not_abstract)
578 old_mask = umask(S_IWGRP | S_IRGRP | S_IXGRP | S_IWOTH | S_IROTH | S_IXOTH); 521 old_mask = umask(S_IWGRP | S_IRGRP | S_IXGRP | S_IWOTH | S_IROTH | S_IXOTH);
579#endif
580 522
581 ret = bind(desc->fd, 523 ret = bind(desc->fd,
582 address, 524 address,
583 address_len); 525 address_len);
584 526
585#ifndef WINDOWS
586 if (not_abstract) 527 if (not_abstract)
587 (void)umask(old_mask); 528 (void)umask(old_mask);
588} 529}
589#endif
590#ifdef MINGW
591 if (SOCKET_ERROR == ret)
592 SetErrnoFromWinsockError(WSAGetLastError());
593#endif
594 if (0 != ret) 530 if (0 != ret)
595 return GNUNET_SYSERR; 531 return GNUNET_SYSERR;
596#ifndef MINGW 532
597 desc->addr = GNUNET_malloc(address_len); 533 desc->addr = GNUNET_malloc(address_len);
598 GNUNET_memcpy(desc->addr, address, address_len); 534 GNUNET_memcpy(desc->addr, address, address_len);
599 desc->addrlen = address_len; 535 desc->addrlen = address_len;
600#endif 536
601 return GNUNET_OK; 537 return GNUNET_OK;
602} 538}
603 539
@@ -613,22 +549,8 @@ GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
613{ 549{
614 int ret; 550 int ret;
615 551
616#ifdef WINDOWS
617 DWORD error = 0;
618
619 SetLastError(0);
620 ret = closesocket(desc->fd);
621 error = WSAGetLastError();
622 SetErrnoFromWinsockError(error);
623 LOG(GNUNET_ERROR_TYPE_DEBUG,
624 "Closed 0x%x, closesocket() returned %d, GLE is %u\n",
625 desc->fd,
626 ret,
627 error);
628#else
629 ret = close(desc->fd); 552 ret = close(desc->fd);
630#endif 553
631#ifndef WINDOWS
632 const struct sockaddr_un *un = (const struct sockaddr_un *)desc->addr; 554 const struct sockaddr_un *un = (const struct sockaddr_un *)desc->addr;
633 555
634 /* Cleanup the UNIX domain socket and its parent directories in case of non 556 /* Cleanup the UNIX domain socket and its parent directories in case of non
@@ -674,7 +596,6 @@ GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
674 } 596 }
675 GNUNET_free(dirname); 597 GNUNET_free(dirname);
676 } 598 }
677#endif
678 GNUNET_NETWORK_socket_free_memory_only_(desc); 599 GNUNET_NETWORK_socket_free_memory_only_(desc);
679 return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR; 600 return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR;
680} 601}
@@ -704,28 +625,12 @@ GNUNET_NETWORK_socket_box_native(SOCKTYPE fd)
704{ 625{
705 struct GNUNET_NETWORK_Handle *ret; 626 struct GNUNET_NETWORK_Handle *ret;
706 627
707#if MINGW
708 unsigned long i;
709 DWORD d;
710 /* FIXME: Find a better call to check that FD is valid */
711 if (0 !=
712 WSAIoctl(fd, FIONBIO,
713 (void *)&i, sizeof(i),
714 NULL, 0, &d,
715 NULL, NULL))
716 return NULL; /* invalid FD */
717 ret = GNUNET_new(struct GNUNET_NETWORK_Handle);
718 ret->fd = fd;
719 ret->af = AF_UNSPEC;
720 return ret;
721#else
722 if (fcntl(fd, F_GETFD) < 0) 628 if (fcntl(fd, F_GETFD) < 0)
723 return NULL; /* invalid FD */ 629 return NULL; /* invalid FD */
724 ret = GNUNET_new(struct GNUNET_NETWORK_Handle); 630 ret = GNUNET_new(struct GNUNET_NETWORK_Handle);
725 ret->fd = fd; 631 ret->fd = fd;
726 ret->af = AF_UNSPEC; 632 ret->af = AF_UNSPEC;
727 return ret; 633 return ret;
728#endif
729} 634}
730 635
731 636
@@ -747,14 +652,7 @@ GNUNET_NETWORK_socket_connect(const struct GNUNET_NETWORK_Handle *desc,
747 ret = connect(desc->fd, 652 ret = connect(desc->fd,
748 address, 653 address,
749 address_len); 654 address_len);
750#ifdef MINGW 655
751 if (SOCKET_ERROR == ret)
752 {
753 SetErrnoFromWinsockError(WSAGetLastError());
754 if (errno == EWOULDBLOCK)
755 errno = EINPROGRESS;
756 }
757#endif
758 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; 656 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
759} 657}
760 658
@@ -783,14 +681,6 @@ GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Handle *desc,
783 optname, 681 optname,
784 optval, optlen); 682 optval, optlen);
785 683
786#ifdef MINGW
787 if ((0 == ret) &&
788 (SOL_SOCKET == level) &&
789 (SO_ERROR == optname))
790 *((int *)optval) = GetErrnoFromWinsockError(*((int *)optval));
791 else if (SOCKET_ERROR == ret)
792 SetErrnoFromWinsockError(WSAGetLastError());
793#endif
794 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; 684 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
795} 685}
796 686
@@ -810,10 +700,7 @@ GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc,
810 700
811 ret = listen(desc->fd, 701 ret = listen(desc->fd,
812 backlog); 702 backlog);
813#ifdef MINGW 703
814 if (SOCKET_ERROR == ret)
815 SetErrnoFromWinsockError(WSAGetLastError());
816#endif
817 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; 704 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
818} 705}
819 706
@@ -830,7 +717,6 @@ GNUNET_NETWORK_socket_recvfrom_amount(const struct GNUNET_NETWORK_Handle *desc)
830 int error; 717 int error;
831 718
832 /* How much is there to be read? */ 719 /* How much is there to be read? */
833#ifndef WINDOWS
834 int pending; 720 int pending;
835 721
836 error = ioctl(desc->fd, 722 error = ioctl(desc->fd,
@@ -839,16 +725,6 @@ GNUNET_NETWORK_socket_recvfrom_amount(const struct GNUNET_NETWORK_Handle *desc)
839 if (0 == error) 725 if (0 == error)
840 return (ssize_t)pending; 726 return (ssize_t)pending;
841 return GNUNET_SYSERR; 727 return GNUNET_SYSERR;
842#else
843 u_long pending;
844
845 error = ioctlsocket(desc->fd,
846 FIONREAD,
847 &pending);
848 if (error != SOCKET_ERROR)
849 return (ssize_t)pending;
850 return GNUNET_SYSERR;
851#endif
852} 728}
853 729
854 730
@@ -1096,28 +972,7 @@ GNUNET_NETWORK_socket_disable_corking(struct GNUNET_NETWORK_Handle *desc)
1096{ 972{
1097 int ret = 0; 973 int ret = 0;
1098 974
1099#if WINDOWS 975#if LINUX
1100 int value = 0;
1101
1102 if (0 !=
1103 (ret =
1104 setsockopt(desc->fd,
1105 SOL_SOCKET,
1106 SO_SNDBUF,
1107 (char *)&value,
1108 sizeof(value))))
1109 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING,
1110 "setsockopt");
1111 if (0 !=
1112 (ret =
1113 setsockopt(desc->fd,
1114 SOL_SOCKET,
1115 SO_RCVBUF,
1116 (char *)&value,
1117 sizeof(value))))
1118 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING,
1119 "setsockopt");
1120#elif LINUX
1121 int value = 0; 976 int value = 0;
1122 977
1123 if (0 != 978 if (0 !=
@@ -1153,9 +1008,6 @@ GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds)
1153{ 1008{
1154 FD_ZERO(&fds->sds); 1009 FD_ZERO(&fds->sds);
1155 fds->nsds = 0; 1010 fds->nsds = 0;
1156#ifdef MINGW
1157 fds->handles_pos = 0;
1158#endif
1159} 1011}
1160 1012
1161 1013
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index 8d9c6e622..104a98da6 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -39,8 +39,6 @@
39#if DARWIN 39#if DARWIN
40#include <mach-o/ldsyms.h> 40#include <mach-o/ldsyms.h>
41#include <mach-o/dyld.h> 41#include <mach-o/dyld.h>
42#elif WINDOWS
43#include <windows.h>
44#endif 42#endif
45 43
46 44
@@ -212,124 +210,6 @@ get_path_from_proc_exe()
212#endif 210#endif
213 211
214 212
215#if WINDOWS
216static HINSTANCE dll_instance;
217
218
219/**
220 * GNUNET_util_cl_init() in common_logging.c is preferred.
221 * This function is only for thread-local storage (not used in GNUnet)
222 * and hInstance saving.
223 */
224BOOL WINAPI
225DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
226{
227 switch (fdwReason)
228 {
229 case DLL_PROCESS_ATTACH:
230 dll_instance = hinstDLL;
231 break;
232
233 case DLL_THREAD_ATTACH:
234 break;
235
236 case DLL_THREAD_DETACH:
237 break;
238
239 case DLL_PROCESS_DETACH:
240 break;
241 }
242 return TRUE;
243}
244
245
246/**
247 * Try to determine path with win32-specific function
248 *
249 * @return NULL on error
250 */
251static char *
252get_path_from_module_filename()
253{
254 size_t pathlen = 512;
255 DWORD real_pathlen;
256 wchar_t *idx;
257 wchar_t *modulepath = NULL;
258 char *upath;
259 uint8_t *u8_string;
260 size_t u8_string_length;
261
262 /* This braindead function won't tell us how much space it needs, so
263 * we start at 1024 and double the space up if it doesn't fit, until
264 * it fits, or we exceed the threshold.
265 */
266 do
267 {
268 pathlen = pathlen * 2;
269 modulepath = GNUNET_realloc(modulepath, pathlen * sizeof(wchar_t));
270 SetLastError(0);
271 real_pathlen =
272 GetModuleFileNameW(dll_instance, modulepath, pathlen * sizeof(wchar_t));
273 }
274 while (real_pathlen >= pathlen && pathlen < 16 * 1024);
275 if (real_pathlen >= pathlen)
276 GNUNET_assert(0);
277 /* To be safe */
278 modulepath[real_pathlen] = '\0';
279
280 idx = modulepath + real_pathlen;
281 while ((idx > modulepath) && (*idx != L'\\') && (*idx != L'/'))
282 idx--;
283 *idx = L'\0';
284
285 /* Now modulepath holds full path to the directory where libgnunetutil is.
286 * This directory should look like <GNUNET_PREFIX>/bin or <GNUNET_PREFIX>.
287 */
288 if (wcschr(modulepath, L'/') || wcschr(modulepath, L'\\'))
289 {
290 /* At least one directory component (i.e. we're not in a root directory) */
291 wchar_t *dirname = idx;
292 while ((dirname > modulepath) && (*dirname != L'\\') && (*dirname != L'/'))
293 dirname--;
294 *dirname = L'\0';
295 if (dirname > modulepath)
296 {
297 dirname++;
298 /* Now modulepath holds full path to the parent directory of the directory
299 * where libgnunetutil is.
300 * dirname holds the name of the directory where libgnunetutil is.
301 */
302 if (wcsicmp(dirname, L"bin") == 0)
303 {
304 /* pass */
305 }
306 else
307 {
308 /* Roll back our changes to modulepath */
309 dirname--;
310 *dirname = L'/';
311 }
312 }
313 }
314
315 /* modulepath is GNUNET_PREFIX */
316 u8_string =
317 u16_to_u8(modulepath, wcslen(modulepath), NULL, &u8_string_length);
318 if (NULL == u8_string)
319 GNUNET_assert(0);
320
321 upath = GNUNET_malloc(u8_string_length + 1);
322 GNUNET_memcpy(upath, u8_string, u8_string_length);
323 upath[u8_string_length] = '\0';
324
325 free(u8_string);
326 GNUNET_free(modulepath);
327
328 return upath;
329}
330#endif
331
332
333#if DARWIN 213#if DARWIN
334/** 214/**
335 * Signature of the '_NSGetExecutablePath" function. 215 * Signature of the '_NSGetExecutablePath" function.
@@ -433,12 +313,9 @@ get_path_from_PATH(const char *binary)
433 313
434 if (NULL == (p = getenv("PATH"))) 314 if (NULL == (p = getenv("PATH")))
435 return NULL; 315 return NULL;
436#if WINDOWS 316
437 /* On W32 look in CWD first. */
438 GNUNET_asprintf(&path, ".%c%s", PATH_SEPARATOR, p);
439#else
440 path = GNUNET_strdup(p); /* because we write on it */ 317 path = GNUNET_strdup(p); /* because we write on it */
441#endif 318
442 buf = GNUNET_malloc(strlen(path) + strlen(binary) + 1 + 1); 319 buf = GNUNET_malloc(strlen(path) + strlen(binary) + 1 + 1);
443 pos = path; 320 pos = path;
444 while (NULL != (end = strchr(pos, PATH_SEPARATOR))) 321 while (NULL != (end = strchr(pos, PATH_SEPARATOR)))
@@ -512,10 +389,6 @@ os_get_gnunet_path()
512 if (NULL != (ret = get_path_from_proc_exe())) 389 if (NULL != (ret = get_path_from_proc_exe()))
513 return ret; 390 return ret;
514#endif 391#endif
515#if WINDOWS
516 if (NULL != (ret = get_path_from_module_filename()))
517 return ret;
518#endif
519#if DARWIN 392#if DARWIN
520 if (NULL != (ret = get_path_from_dyld_image())) 393 if (NULL != (ret = get_path_from_dyld_image()))
521 return ret; 394 return ret;
@@ -548,10 +421,6 @@ os_get_exec_path()
548 if (NULL != (ret = get_path_from_proc_exe())) 421 if (NULL != (ret = get_path_from_proc_exe()))
549 return ret; 422 return ret;
550#endif 423#endif
551#if WINDOWS
552 if (NULL != (ret = get_path_from_module_filename()))
553 return ret;
554#endif
555#if DARWIN 424#if DARWIN
556 if (NULL != (ret = get_path_from_NSGetExecutablePath())) 425 if (NULL != (ret = get_path_from_NSGetExecutablePath()))
557 return ret; 426 return ret;
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index e4f2371e7..ebe469b3b 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -46,12 +46,6 @@ struct GNUNET_OS_Process {
46 */ 46 */
47 pid_t pid; 47 pid_t pid;
48 48
49#if WINDOWS
50 /**
51 * Process handle.
52 */
53 HANDLE handle;
54#endif
55 49
56 /** 50 /**
57 * Pipe we use to signal the process. 51 * Pipe we use to signal the process.
@@ -174,12 +168,7 @@ GNUNET_OS_install_parent_control_handler(void *cls)
174 putenv(GNUNET_OS_CONTROL_PIPE "="); 168 putenv(GNUNET_OS_CONTROL_PIPE "=");
175 return; 169 return;
176 } 170 }
177#if !defined(WINDOWS)
178 if (pipe_fd >= FD_SETSIZE) 171 if (pipe_fd >= FD_SETSIZE)
179#else
180 if ((FILE_TYPE_UNKNOWN == GetFileType((HANDLE)(uintptr_t)pipe_fd)) &&
181 (0 != GetLastError()))
182#endif
183 { 172 {
184 LOG(GNUNET_ERROR_TYPE_ERROR, 173 LOG(GNUNET_ERROR_TYPE_ERROR,
185 "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n", 174 "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n",
@@ -187,12 +176,9 @@ GNUNET_OS_install_parent_control_handler(void *cls)
187 putenv(GNUNET_OS_CONTROL_PIPE "="); 176 putenv(GNUNET_OS_CONTROL_PIPE "=");
188 return; 177 return;
189 } 178 }
190#if WINDOWS 179
191 control_pipe =
192 GNUNET_DISK_get_handle_from_w32_handle((HANDLE)(uintptr_t)pipe_fd);
193#else
194 control_pipe = GNUNET_DISK_get_handle_from_int_fd((int)pipe_fd); 180 control_pipe = GNUNET_DISK_get_handle_from_int_fd((int)pipe_fd);
195#endif 181
196 if (NULL == control_pipe) 182 if (NULL == control_pipe)
197 { 183 {
198 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "open", env_buf); 184 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
@@ -222,12 +208,7 @@ GNUNET_OS_install_parent_control_handler(void *cls)
222struct GNUNET_OS_Process * 208struct GNUNET_OS_Process *
223GNUNET_OS_process_current() 209GNUNET_OS_process_current()
224{ 210{
225#if WINDOWS
226 current_process.pid = GetCurrentProcessId();
227 current_process.handle = GetCurrentProcess();
228#else
229 current_process.pid = 0; 211 current_process.pid = 0;
230#endif
231 return &current_process; 212 return &current_process;
232} 213}
233 214
@@ -259,72 +240,24 @@ GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
259 /* pipe failed or non-existent, try other methods */ 240 /* pipe failed or non-existent, try other methods */
260 switch (sig) 241 switch (sig)
261 { 242 {
262#if !defined(WINDOWS)
263 case SIGHUP: 243 case SIGHUP:
264#endif
265 case SIGINT: 244 case SIGINT:
266 case SIGKILL: 245 case SIGKILL:
267 case SIGTERM: 246 case SIGTERM:
268#if (SIGTERM != GNUNET_TERM_SIG) 247#if (SIGTERM != GNUNET_TERM_SIG)
269 case GNUNET_TERM_SIG: 248 case GNUNET_TERM_SIG:
270#endif 249#endif
271#if defined(WINDOWS) && !defined(__CYGWIN__)
272 {
273 DWORD exitcode;
274 int must_kill = GNUNET_YES;
275 if (0 != GetExitCodeProcess(proc->handle, &exitcode))
276 must_kill = (exitcode == STILL_ACTIVE) ? GNUNET_YES : GNUNET_NO;
277 if (GNUNET_YES == must_kill)
278 {
279 if (0 == SafeTerminateProcess(proc->handle, 0, 0))
280 {
281 DWORD error_code = GetLastError();
282 if ((error_code != WAIT_TIMEOUT) &&
283 (error_code != ERROR_PROCESS_ABORTED))
284 {
285 LOG((error_code == ERROR_ACCESS_DENIED) ? GNUNET_ERROR_TYPE_INFO
286 : GNUNET_ERROR_TYPE_WARNING,
287 "SafeTermiateProcess failed with code %lu\n",
288 error_code);
289 /* The problem here is that a process that is already dying
290 * might cause SafeTerminateProcess to fail with
291 * ERROR_ACCESS_DENIED, but the process WILL die eventually.
292 * If we really had a permissions problem, hanging up (which
293 * is what will happen in process_wait() in that case) is
294 * a valid option.
295 */
296 if (ERROR_ACCESS_DENIED == error_code)
297 {
298 errno = 0;
299 }
300 else
301 {
302 SetErrnoFromWinError(error_code);
303 return -1;
304 }
305 }
306 }
307 }
308 }
309 return 0;
310#else
311 LOG(GNUNET_ERROR_TYPE_DEBUG, 250 LOG(GNUNET_ERROR_TYPE_DEBUG,
312 "Sending signal %d to pid: %u via system call\n", 251 "Sending signal %d to pid: %u via system call\n",
313 sig, 252 sig,
314 proc->pid); 253 proc->pid);
315 return kill(proc->pid, sig); 254 return kill(proc->pid, sig);
316#endif
317 default: 255 default:
318#if defined(WINDOWS)
319 errno = EINVAL;
320 return -1;
321#else
322 LOG(GNUNET_ERROR_TYPE_DEBUG, 256 LOG(GNUNET_ERROR_TYPE_DEBUG,
323 "Sending signal %d to pid: %u via system call\n", 257 "Sending signal %d to pid: %u via system call\n",
324 sig, 258 sig,
325 proc->pid); 259 proc->pid);
326 return kill(proc->pid, sig); 260 return kill(proc->pid, sig);
327#endif
328 } 261 }
329} 262}
330 263
@@ -354,152 +287,11 @@ GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
354{ 287{
355 if (NULL != proc->control_pipe) 288 if (NULL != proc->control_pipe)
356 GNUNET_DISK_file_close(proc->control_pipe); 289 GNUNET_DISK_file_close(proc->control_pipe);
357#if defined(WINDOWS) 290
358 if (NULL != proc->handle)
359 CloseHandle(proc->handle);
360#endif
361 GNUNET_free(proc); 291 GNUNET_free(proc);
362} 292}
363 293
364 294
365#if WINDOWS
366#include "gnunet_signal_lib.h"
367
368extern GNUNET_SIGNAL_Handler w32_sigchld_handler;
369
370/**
371 * Make seaspider happy.
372 */
373#define DWORD_WINAPI DWORD WINAPI
374
375
376/**
377 * @brief Waits for a process to terminate and invokes the SIGCHLD handler
378 * @param proc pointer to process structure
379 */
380static DWORD_WINAPI
381child_wait_thread(void *arg)
382{
383 struct GNUNET_OS_Process *proc = (struct GNUNET_OS_Process *)arg;
384
385 WaitForSingleObject(proc->handle, INFINITE);
386
387 if (w32_sigchld_handler)
388 w32_sigchld_handler();
389
390 return 0;
391}
392#endif
393
394
395#if MINGW
396static char *
397CreateCustomEnvTable(char **vars)
398{
399 char *win32_env_table;
400 char *ptr;
401 char **var_ptr;
402 char *result;
403 char *result_ptr;
404 size_t tablesize = 0;
405 size_t items_count = 0;
406 size_t n_found = 0;
407 size_t n_var;
408 char *index = NULL;
409 size_t c;
410 size_t var_len;
411 char *var;
412 char *val;
413
414 win32_env_table = GetEnvironmentStringsA();
415 if (NULL == win32_env_table)
416 return NULL;
417 for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++)
418 ;
419 n_var = c;
420 index = GNUNET_malloc(sizeof(char *) * n_var);
421 for (c = 0; c < n_var; c++)
422 index[c] = 0;
423 for (items_count = 0, ptr = win32_env_table; ptr[0] != 0; items_count++)
424 {
425 size_t len = strlen(ptr);
426 int found = 0;
427
428 for (var_ptr = vars; *var_ptr; var_ptr++)
429 {
430 var = *var_ptr++;
431 val = *var_ptr;
432 var_len = strlen(var);
433 if (strncmp(var, ptr, var_len) == 0)
434 {
435 found = 1;
436 index[c] = 1;
437 tablesize += var_len + strlen(val) + 1;
438 break;
439 }
440 }
441 if (!found)
442 tablesize += len + 1;
443 ptr += len + 1;
444 }
445 for (n_found = 0, c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
446 {
447 var = *var_ptr++;
448 val = *var_ptr;
449 if (index[c] != 1)
450 n_found += strlen(var) + strlen(val) + 1;
451 }
452 result = GNUNET_malloc(tablesize + n_found + 1);
453 for (result_ptr = result, ptr = win32_env_table; ptr[0] != 0;)
454 {
455 size_t len = strlen(ptr);
456 int found = 0;
457
458 for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
459 {
460 var = *var_ptr++;
461 val = *var_ptr;
462 var_len = strlen(var);
463 if (strncmp(var, ptr, var_len) == 0)
464 {
465 found = 1;
466 break;
467 }
468 }
469 if (!found)
470 {
471 strcpy(result_ptr, ptr);
472 result_ptr += len + 1;
473 }
474 else
475 {
476 strcpy(result_ptr, var);
477 result_ptr += var_len;
478 strcpy(result_ptr, val);
479 result_ptr += strlen(val) + 1;
480 }
481 ptr += len + 1;
482 }
483 for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
484 {
485 var = *var_ptr++;
486 val = *var_ptr;
487 var_len = strlen(var);
488 if (index[c] != 1)
489 {
490 strcpy(result_ptr, var);
491 result_ptr += var_len;
492 strcpy(result_ptr, val);
493 result_ptr += strlen(val) + 1;
494 }
495 }
496 FreeEnvironmentStrings(win32_env_table);
497 GNUNET_free(index);
498 *result_ptr = 0;
499 return result;
500}
501
502#else
503 295
504/** 296/**
505 * Open '/dev/null' and make the result the given 297 * Open '/dev/null' and make the result the given
@@ -529,7 +321,6 @@ open_dev_null(int target_fd, int flags)
529 } 321 }
530 GNUNET_break(0 == close(fd)); 322 GNUNET_break(0 == close(fd));
531} 323}
532#endif
533 324
534 325
535/** 326/**
diff --git a/src/util/service.c b/src/util/service.c
index 75094e028..880047a42 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -825,11 +825,10 @@ accept_client(void *cls)
825 (!check_ipv6_listed(sh->v6_denied, &v6->sin6_addr)))); 825 (!check_ipv6_listed(sh->v6_denied, &v6->sin6_addr))));
826 break; 826 break;
827 827
828#ifndef WINDOWS
829 case AF_UNIX: 828 case AF_UNIX:
830 ok = GNUNET_OK; /* controlled using file-system ACL now */ 829 ok = GNUNET_OK; /* controlled using file-system ACL now */
831 break; 830 break;
832#endif 831
833 default: 832 default:
834 LOG(GNUNET_ERROR_TYPE_WARNING, 833 LOG(GNUNET_ERROR_TYPE_WARNING,
835 _("Unknown address family %d\n"), 834 _("Unknown address family %d\n"),
diff --git a/src/util/signal.c b/src/util/signal.c
index 96e40ba7f..ada4db5ad 100644
--- a/src/util/signal.c
+++ b/src/util/signal.c
@@ -39,33 +39,24 @@ struct GNUNET_SIGNAL_Context {
39 39
40 GNUNET_SIGNAL_Handler method; 40 GNUNET_SIGNAL_Handler method;
41 41
42#ifndef MINGW
43 struct sigaction oldsig; 42 struct sigaction oldsig;
44#endif
45}; 43};
46 44
47static struct GNUNET_SIGNAL_Context *sc_head; 45static struct GNUNET_SIGNAL_Context *sc_head;
48 46
49static struct GNUNET_SIGNAL_Context *sc_tail; 47static struct GNUNET_SIGNAL_Context *sc_tail;
50 48
51
52#ifdef WINDOWS
53GNUNET_SIGNAL_Handler w32_sigchld_handler = NULL;
54#endif
55
56struct GNUNET_SIGNAL_Context * 49struct GNUNET_SIGNAL_Context *
57GNUNET_SIGNAL_handler_install(int signum, GNUNET_SIGNAL_Handler handler) 50GNUNET_SIGNAL_handler_install(int signum, GNUNET_SIGNAL_Handler handler)
58{ 51{
59 struct GNUNET_SIGNAL_Context *ret; 52 struct GNUNET_SIGNAL_Context *ret;
60 53
61#ifndef MINGW
62 struct sigaction sig; 54 struct sigaction sig;
63#endif
64 55
65 ret = GNUNET_new(struct GNUNET_SIGNAL_Context); 56 ret = GNUNET_new(struct GNUNET_SIGNAL_Context);
66 ret->sig = signum; 57 ret->sig = signum;
67 ret->method = handler; 58 ret->method = handler;
68#ifndef MINGW 59
69 memset(&sig, 0, sizeof(sig)); 60 memset(&sig, 0, sizeof(sig));
70 sig.sa_handler = (void *)handler; 61 sig.sa_handler = (void *)handler;
71 sigemptyset(&sig.sa_mask); 62 sigemptyset(&sig.sa_mask);
@@ -75,20 +66,7 @@ GNUNET_SIGNAL_handler_install(int signum, GNUNET_SIGNAL_Handler handler)
75 sig.sa_flags = SA_RESTART; 66 sig.sa_flags = SA_RESTART;
76#endif 67#endif
77 sigaction(signum, &sig, &ret->oldsig); 68 sigaction(signum, &sig, &ret->oldsig);
78#else
79 if (signum == GNUNET_SIGCHLD)
80 w32_sigchld_handler = handler;
81 else
82 {
83 __p_sig_fn_t sigret = signal(signum, (__p_sig_fn_t)handler);
84 69
85 if (sigret == SIG_ERR)
86 {
87 LOG(GNUNET_ERROR_TYPE_WARNING, _("signal (%d, %p) returned %d.\n"),
88 signum, handler, sigret);
89 }
90 }
91#endif
92 GNUNET_CONTAINER_DLL_insert_tail(sc_head, sc_tail, ret); 70 GNUNET_CONTAINER_DLL_insert_tail(sc_head, sc_tail, ret);
93 return ret; 71 return ret;
94} 72}
@@ -96,12 +74,11 @@ GNUNET_SIGNAL_handler_install(int signum, GNUNET_SIGNAL_Handler handler)
96void 74void
97GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx) 75GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx)
98{ 76{
99#ifndef MINGW
100 struct sigaction sig; 77 struct sigaction sig;
101 78
102 sigemptyset(&sig.sa_mask); 79 sigemptyset(&sig.sa_mask);
103 sigaction(ctx->sig, &ctx->oldsig, &sig); 80 sigaction(ctx->sig, &ctx->oldsig, &sig);
104#endif 81
105 GNUNET_CONTAINER_DLL_remove(sc_head, sc_tail, ctx); 82 GNUNET_CONTAINER_DLL_remove(sc_head, sc_tail, ctx);
106 GNUNET_free(ctx); 83 GNUNET_free(ctx);
107} 84}
diff --git a/src/util/strings.c b/src/util/strings.c
index 1b4f75ab0..dc46ad33a 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -789,31 +789,9 @@ GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
789 * (otherwise we'd have to detect current codepage or use W32API character 789 * (otherwise we'd have to detect current codepage or use W32API character
790 * set conversion routines to convert to UTF8). 790 * set conversion routines to convert to UTF8).
791 */ 791 */
792#ifndef WINDOWS 792
793 strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Y", tp); 793 strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Y", tp);
794#else 794
795 {
796 static wchar_t wbuf[255];
797 uint8_t *conved;
798 size_t ssize;
799
800 wcsftime(wbuf,
801 sizeof(wbuf) / sizeof(wchar_t),
802 L"%a %b %d %H:%M:%S %Y",
803 tp);
804
805 ssize = sizeof(buf);
806 conved = u16_to_u8(wbuf,
807 sizeof(wbuf) / sizeof(wchar_t),
808 (uint8_t *)buf,
809 &ssize);
810 if (conved != (uint8_t *)buf)
811 {
812 GNUNET_strlcpy(buf, (char *)conved, sizeof(buf));
813 free(conved);
814 }
815 }
816#endif
817 return buf; 795 return buf;
818} 796}
819 797
@@ -1168,9 +1146,6 @@ GNUNET_STRINGS_path_is_absolute(const char *filename,
1168 int *r_is_uri, 1146 int *r_is_uri,
1169 char **r_uri_scheme) 1147 char **r_uri_scheme)
1170{ 1148{
1171#if WINDOWS
1172 size_t len;
1173#endif
1174 const char *post_scheme_path; 1149 const char *post_scheme_path;
1175 int is_uri; 1150 int is_uri;
1176 char *uri; 1151 char *uri;
@@ -1190,14 +1165,7 @@ GNUNET_STRINGS_path_is_absolute(const char *filename,
1190 *r_uri_scheme = uri; 1165 *r_uri_scheme = uri;
1191 else 1166 else
1192 GNUNET_free_non_null(uri); 1167 GNUNET_free_non_null(uri);
1193#if WINDOWS 1168
1194 len = strlen(post_scheme_path);
1195 /* Special check for file:///c:/blah
1196 * We want to parse 'c:/', not '/c:/'
1197 */
1198 if (post_scheme_path[0] == '/' && len >= 3 && post_scheme_path[2] == ':')
1199 post_scheme_path = &post_scheme_path[1];
1200#endif
1201 return GNUNET_STRINGS_path_is_absolute(post_scheme_path, 1169 return GNUNET_STRINGS_path_is_absolute(post_scheme_path,
1202 GNUNET_NO, 1170 GNUNET_NO,
1203 NULL, 1171 NULL,
@@ -1209,23 +1177,10 @@ GNUNET_STRINGS_path_is_absolute(const char *filename,
1209 if (r_is_uri) 1177 if (r_is_uri)
1210 *r_is_uri = GNUNET_NO; 1178 *r_is_uri = GNUNET_NO;
1211 } 1179 }
1212#if WINDOWS 1180
1213 len = strlen(filename);
1214 if (len >= 3 &&
1215 ((filename[0] >= 'A' && filename[0] <= 'Z') ||
1216 (filename[0] >= 'a' && filename[0] <= 'z')) &&
1217 filename[1] == ':' && (filename[2] == '/' || filename[2] == '\\'))
1218 return GNUNET_YES;
1219#endif
1220 return GNUNET_NO; 1181 return GNUNET_NO;
1221} 1182}
1222 1183
1223#if MINGW
1224#define _IFMT 0170000 /* type of file */
1225#define _IFLNK 0120000 /* symbolic link */
1226#define S_ISLNK(m) (((m) & _IFMT) == _IFLNK)
1227#endif
1228
1229 1184
1230/** 1185/**
1231 * Perform @a checks on @a filename. 1186 * Perform @a checks on @a filename.
@@ -1521,53 +1476,11 @@ GNUNET_STRINGS_get_utf8_args(int argc,
1521 int *u8argc, 1476 int *u8argc,
1522 char *const **u8argv) 1477 char *const **u8argv)
1523{ 1478{
1524#if WINDOWS
1525 wchar_t *wcmd;
1526 wchar_t **wargv;
1527 int wargc;
1528 int i;
1529 char **split_u8argv;
1530
1531 wcmd = GetCommandLineW();
1532 if (NULL == wcmd)
1533 return GNUNET_SYSERR;
1534 wargv = CommandLineToArgvW(wcmd, &wargc);
1535 if (NULL == wargv)
1536 return GNUNET_SYSERR;
1537
1538 split_u8argv = GNUNET_malloc(argc * sizeof(char *));
1539
1540 for (i = 0; i < wargc; i++)
1541 {
1542 size_t strl;
1543 /* Hopefully it will allocate us NUL-terminated strings... */
1544 split_u8argv[i] =
1545 (char *)u16_to_u8(wargv[i], wcslen(wargv[i]) + 1, NULL, &strl);
1546 if (NULL == split_u8argv[i])
1547 {
1548 int j;
1549 for (j = 0; j < i; j++)
1550 free(split_u8argv[j]);
1551 GNUNET_free(split_u8argv);
1552 LocalFree(wargv);
1553 return GNUNET_SYSERR;
1554 }
1555 }
1556
1557 *u8argv = _make_continuous_arg_copy(wargc, split_u8argv);
1558 *u8argc = wargc;
1559
1560 for (i = 0; i < wargc; i++)
1561 free(split_u8argv[i]);
1562 free(split_u8argv);
1563 return GNUNET_OK;
1564#else
1565 char *const *new_argv = 1479 char *const *new_argv =
1566 (char *const *)_make_continuous_arg_copy(argc, argv); 1480 (char *const *)_make_continuous_arg_copy(argc, argv);
1567 *u8argv = new_argv; 1481 *u8argv = new_argv;
1568 *u8argc = argc; 1482 *u8argc = argc;
1569 return GNUNET_OK; 1483 return GNUNET_OK;
1570#endif
1571} 1484}
1572 1485
1573 1486
diff --git a/src/util/test_common_logging_runtime_loglevels.c b/src/util/test_common_logging_runtime_loglevels.c
index f46776c8f..07e2327c9 100644
--- a/src/util/test_common_logging_runtime_loglevels.c
+++ b/src/util/test_common_logging_runtime_loglevels.c
@@ -152,22 +152,12 @@ read_output_line(int phase_from1, int phase_to1, int phase_from2,
152 152
153 case 2: /* read the delay, finished by '\n' */ 153 case 2: /* read the delay, finished by '\n' */
154 t[j++] = r[i]; 154 t[j++] = r[i];
155#if WINDOWS
156 if (r[i] == '\r' && r[i + 1] == '\n')
157 {
158 i += 1;
159 t[j - 1] = '\0';
160 *delay = strtol(t, NULL, 10);
161 stop = 1;
162 }
163#else
164 if (r[i] == '\n') 155 if (r[i] == '\n')
165 { 156 {
166 t[j - 1] = '\0'; 157 t[j - 1] = '\0';
167 *delay = strtol(t, NULL, 10); 158 *delay = strtol(t, NULL, 10);
168 stop = 1; 159 stop = 1;
169 } 160 }
170#endif
171 break; 161 break;
172 } 162 }
173 } 163 }
diff --git a/src/util/test_disk.c b/src/util/test_disk.c
index 13fb18e88..cacbe8be0 100644
--- a/src/util/test_disk.c
+++ b/src/util/test_disk.c
@@ -215,11 +215,9 @@ testCanonicalize()
215static int 215static int
216testChangeOwner() 216testChangeOwner()
217{ 217{
218#ifndef WINDOWS
219 GNUNET_log_skip(1, GNUNET_NO); 218 GNUNET_log_skip(1, GNUNET_NO);
220 if (GNUNET_OK == GNUNET_DISK_file_change_owner("/dev/null", "unknownuser")) 219 if (GNUNET_OK == GNUNET_DISK_file_change_owner("/dev/null", "unknownuser"))
221 return 1; 220 return 1;
222#endif
223 return 0; 221 return 0;
224} 222}
225 223
diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c
index 4efbe91af..abf00a09e 100644
--- a/src/util/test_os_start_process.c
+++ b/src/util/test_os_start_process.c
@@ -121,11 +121,7 @@ run_task(void *cls)
121 const struct GNUNET_DISK_FileHandle *stdout_read_handle; 121 const struct GNUNET_DISK_FileHandle *stdout_read_handle;
122 const struct GNUNET_DISK_FileHandle *wh; 122 const struct GNUNET_DISK_FileHandle *wh;
123 123
124#if !WINDOWS
125 GNUNET_asprintf(&fn, "cat"); 124 GNUNET_asprintf(&fn, "cat");
126#else
127 GNUNET_asprintf(&fn, "w32cat");
128#endif
129 125
130 hello_pipe_stdin = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); 126 hello_pipe_stdin = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
131 hello_pipe_stdout = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); 127 hello_pipe_stdout = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
diff --git a/src/util/test_strings.c b/src/util/test_strings.c
index 4a7861965..a4e548e31 100644
--- a/src/util/test_strings.c
+++ b/src/util/test_strings.c
@@ -114,18 +114,6 @@ main(int argc, char *argv[])
114 114
115 if (atx.abs_value_us != at.abs_value_us) 115 if (atx.abs_value_us != at.abs_value_us)
116 { 116 {
117#ifdef WINDOWS
118 DWORD tzv;
119 TIME_ZONE_INFORMATION tzi;
120 tzv = GetTimeZoneInformation(&tzi);
121 if (TIME_ZONE_ID_INVALID != tzv)
122 {
123 atx.abs_value_us -= 1000LL * 1000LL * tzi.Bias * 60LL;
124 }
125 if (atx.abs_value_us == at.abs_value_us)
126 fprintf(stderr,
127 "WARNING: GNUNET_STRINGS_fancy_time_to_absolute() miscalculates timezone!\n");
128#endif
129 GNUNET_assert(0); 117 GNUNET_assert(0);
130 } 118 }
131 119