From 483b0139a218a5f8a8311bda3eb23bcd88f57688 Mon Sep 17 00:00:00 2001 From: ng0 Date: Mon, 9 Sep 2019 19:17:18 +0000 Subject: Remove win32 and cygwin support --- src/arm/gnunet-service-arm.c | 15 +- src/conversation/gnunet-conversation.c | 82 -- .../gnunet-helper-audio-playback-gst.c | 4 - src/conversation/gnunet-helper-audio-record-gst.c | 4 - src/datacache/plugin_datacache_sqlite.c | 5 - src/fs/fs_file_information.c | 19 - src/fs/gnunet-download.c | 15 - src/fs/gnunet-helper-fs-publish.c | 29 - src/gns/gnunet-gns-import.c | 8 - src/include/gauger.h | 30 - src/include/gnunet_disk_lib.h | 37 +- src/include/gnunet_network_lib.h | 34 - src/include/platform.h | 58 -- src/mysql/mysql.c | 12 +- src/testbed/gnunet-helper-testbed.c | 12 - src/testbed/gnunet-service-testbed_cpustatus.c | 3 - src/testing/testing.c | 4 - src/transport/tcp_service_legacy.c | 11 +- src/transport/transport-testing-filenames.c | 19 - src/util/common_allocation.c | 3 - src/util/common_logging.c | 75 +- src/util/disk.c | 842 +-------------------- src/util/dnsparser.c | 23 - src/util/getopt.c | 6 - src/util/gnunet-helper-w32-console.c | 319 -------- src/util/gnunet-helper-w32-console.h | 70 -- src/util/network.c | 166 +--- src/util/os_installation.c | 135 +--- src/util/os_priority.c | 215 +----- src/util/service.c | 3 +- src/util/signal.c | 27 +- src/util/strings.c | 95 +-- src/util/test_common_logging_runtime_loglevels.c | 10 - src/util/test_disk.c | 2 - src/util/test_os_start_process.c | 4 - src/util/test_strings.c | 12 - 36 files changed, 44 insertions(+), 2364 deletions(-) delete mode 100644 src/util/gnunet-helper-w32-console.c delete mode 100644 src/util/gnunet-helper-w32-console.h (limited to 'src') 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, sli->accept_task = NULL; } } -#if WINDOWS - GNUNET_array_append(lsocks, ls, INVALID_SOCKET); -#else + GNUNET_array_append(lsocks, ls, -1); -#endif /* obtain configuration */ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, @@ -1002,10 +999,8 @@ create_listen_socket(struct sockaddr *sa, struct GNUNET_NETWORK_Handle *sock; struct ServiceListeningInfo *sli; -#ifndef WINDOWS int match_uid; int match_gid; -#endif switch (sa->sa_family) { @@ -1056,10 +1051,8 @@ create_listen_socket(struct sockaddr *sa, GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); #endif -#ifndef WINDOWS if (AF_UNIX == sa->sa_family) GNUNET_NETWORK_unix_precheck((struct sockaddr_un *)sa); -#endif if (GNUNET_OK != GNUNET_NETWORK_socket_bind(sock, (const struct sockaddr *)sa, addr_len)) { @@ -1074,7 +1067,6 @@ create_listen_socket(struct sockaddr *sa, GNUNET_free(sa); return; } -#ifndef WINDOWS if ((AF_UNIX == sa->sa_family) #ifdef LINUX /* Permission settings are not required when abstract sockets are used */ @@ -1090,7 +1082,6 @@ create_listen_socket(struct sockaddr *sa, match_uid, match_gid); } -#endif if (GNUNET_OK != GNUNET_NETWORK_socket_listen(sock, 5)) { GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "listen"); @@ -1884,13 +1875,9 @@ setup_service(void *cls, const char *section) sl->config = config; sl->backoff = GNUNET_TIME_UNIT_MILLISECONDS; sl->restart_at = GNUNET_TIME_UNIT_FOREVER_ABS; -#if WINDOWS - sl->pipe_control = GNUNET_YES; -#else if (GNUNET_CONFIGURATION_have_value(cfg, section, "PIPECONTROL")) sl->pipe_control = GNUNET_CONFIGURATION_get_value_yesno(cfg, section, "PIPECONTROL"); -#endif GNUNET_CONTAINER_DLL_insert(running_head, running_tail, sl); if (GNUNET_YES == 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 @@ #include "gnunet_gnsrecord_lib.h" #include "gnunet_conversation_service.h" #include "gnunet_namestore_service.h" -#ifdef WINDOWS -#include "../util/gnunet-helper-w32-console.h" -#endif /** * Maximum length allowed for the command line input. @@ -42,13 +39,6 @@ #define STRINGIFY(x) (#x) -#ifdef WINDOWS -/** - * Helper that reads the console for us. - */ -struct GNUNET_HELPER_Handle *stdin_hlp; -#endif - /** * Possible states of the phone. */ @@ -1016,13 +1006,6 @@ static void do_stop_task(void *cls) { (void)cls; -#ifdef WINDOWS - if (NULL != stdin_hlp) - { - GNUNET_HELPER_stop(stdin_hlp, GNUNET_NO); - stdin_hlp = NULL; - } -#endif if (NULL != call) { GNUNET_CONVERSATION_call_stop(call); @@ -1090,38 +1073,6 @@ handle_command_string(char *message, size_t str_len) } -#ifdef WINDOWS -static int -console_reader_chars(void *cls, - void *client, - const struct GNUNET_MessageHeader *message) -{ - char *chars; - size_t str_size; - - (void)cls; - switch (ntohs(message->type)) - { - case GNUNET_MESSAGE_TYPE_W32_CONSOLE_HELPER_CHARS: - chars = (char *)&message[1]; - str_size = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader); - if (chars[str_size - 1] != '\0') - return GNUNET_SYSERR; - /* FIXME: is it ok that we pass part of a const struct to - * this function that may mangle the contents? - */ - handle_command_string(chars, str_size - 1); - break; - - default: - GNUNET_break(0); - break; - } - return GNUNET_OK; -} -#endif - - /** * Task to handle commands from the terminal. * @@ -1213,30 +1164,6 @@ run(void *cls, return; } id = GNUNET_IDENTITY_connect(cfg, &identity_cb, NULL); -#ifdef WINDOWS - if (stdin_fh == NULL) - { - static char cpid[64]; - static char *args[] = { "gnunet-helper-w32-console.exe", - "chars", - XSTRINGIFY(MAX_MESSAGE_LENGTH), - cpid, - NULL }; - snprintf(cpid, 64, "%d", GetCurrentProcessId()); - stdin_hlp = GNUNET_HELPER_start(GNUNET_NO, - "gnunet-helper-w32-console", - args, - console_reader_chars, - NULL, - NULL); - if (NULL == stdin_hlp) - { - fprintf(stderr, "%s", _("Failed to start gnunet-helper-w32-console\n")); - return; - } - } - else -#endif handle_cmd_task = GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_UI, &handle_command, @@ -1271,21 +1198,12 @@ main(int argc, char *const *argv) GNUNET_GETOPT_OPTION_END }; int ret; -#ifndef WINDOWS int flags; flags = fcntl(0, F_GETFL, 0); flags |= O_NONBLOCK; if (0 != fcntl(0, F_SETFL, flags)) GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "fcntl"); stdin_fh = GNUNET_DISK_get_handle_from_int_fd(0); -#else - if (FILE_TYPE_CHAR == GetFileType((HANDLE)_get_osfhandle(0))) - { - stdin_fh = NULL; - } - else - stdin_fh = GNUNET_DISK_get_handle_from_int_fd(0); -#endif if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 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) termhandler = signal(SIGTERM, &signalhandler); -#ifdef WINDOWS - setmode(0, _O_BINARY); -#endif - /* Initialisation */ gst_init(&argc, &argv); 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) dump_pure_ogg = getenv("GNUNET_RECORD_PURE_OGG") ? 1 : 0; #endif -#ifdef WINDOWS - setmode(1, _O_BINARY); -#endif - /* Initialisation */ gst_init(&argc, &argv); 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) if (SQLITE_OK != result) LOG_SQLITE(plugin->dbh, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close"); -#if WINDOWS && !defined(__CYGWIN__) - if ((NULL != plugin->fn) && (0 != unlink(plugin->fn))) - LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "unlink", plugin->fn); - GNUNET_free_non_null(plugin->fn); -#endif GNUNET_free(plugin); GNUNET_free(api); 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( const char *fn; const char *ss; -#if WINDOWS - char fn_conv[MAX_PATH]; -#endif - /* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */ if (GNUNET_OK != GNUNET_DISK_file_size(filename, &fsize, GNUNET_NO, GNUNET_YES)) @@ -143,18 +139,12 @@ GNUNET_FS_file_information_create_from_file( return NULL; ret->h = h; ret->filename = GNUNET_strdup(filename); -#if !WINDOWS fn = filename; -#else - plibc_conv_to_win_path(filename, fn_conv); - fn = fn_conv; -#endif while (NULL != (ss = strstr(fn, DIR_SEPARATOR_STR))) fn = ss + 1; /* FIXME: If we assume that on other platforms CRT is UTF-8-aware, then * this should be changed to EXTRACTOR_METAFORMAT_UTF8 */ -#if !WINDOWS GNUNET_CONTAINER_meta_data_insert(ret->meta, "", EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, @@ -162,15 +152,6 @@ GNUNET_FS_file_information_create_from_file( "text/plain", fn, strlen(fn) + 1); -#else - GNUNET_CONTAINER_meta_data_insert(ret->meta, - "", - EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", - fn, - strlen(fn) + 1); -#endif return ret; } 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) unsigned int endeq; float ratio_complete; -#if !WINDOWS if (0 == isatty(1)) return; -#else - if (FILE_TYPE_CHAR != GetFileType(GetStdHandle(STD_OUTPUT_HANDLE))) - return; -#endif ratio_complete = x / (float)n; endeq = ratio_complete * w; GNUNET_snprintf(buf, sizeof(buf), "%3d%% [", (int)(ratio_complete * 100)); @@ -175,13 +170,8 @@ progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) break; case GNUNET_FS_STATUS_DOWNLOAD_ERROR: -#if !WINDOWS if (0 != isatty(1)) fprintf(stdout, "\n"); -#else - if (FILE_TYPE_CHAR == GetFileType(GetStdHandle(STD_OUTPUT_HANDLE))) - fprintf(stdout, "\n"); -#endif fprintf(stderr, _("Error downloading: %s.\n"), info->value.download.specifics.error.message); @@ -192,13 +182,8 @@ progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info) s = GNUNET_STRINGS_byte_size_fancy( info->value.download.completed * 1000 / (info->value.download.duration.rel_value_us + 1)); -#if !WINDOWS if (0 != isatty(1)) fprintf(stdout, "\n"); -#else - if (FILE_TYPE_CHAR == GetFileType(GetStdHandle(STD_OUTPUT_HANDLE))) - fprintf(stdout, "\n"); -#endif fprintf(stdout, _("Downloading `%s' done (%s/s).\n"), 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) } -#ifndef WINDOWS /** * Install a signal handler to ignore SIGPIPE. */ @@ -479,8 +478,6 @@ make_dev_zero(int fd, int flags) GNUNET_assert(0 == close(z)); } -#endif - /** * Main function of the helper process to extract meta data. @@ -499,23 +496,12 @@ main(int argc, char *const *argv) const char *ex; struct ScanTreeNode *root; -#if WINDOWS - /* We're using stdout to communicate binary data back to the parent; use - * binary mode. - */ - _setmode(1, _O_BINARY); - /* Get utf-8-encoded arguments */ - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) - return 5; - output_stream = 1; /* stdout */ -#else ignore_sigpipe(); /* move stdout to some other FD for IPC, bind stdout/stderr to /dev/null */ output_stream = dup(1); make_dev_zero(1, O_WRONLY); make_dev_zero(2, O_WRONLY); -#endif /* parse command line */ if ((3 != argc) && (2 != argc)) @@ -523,9 +509,6 @@ main(int argc, char *const *argv) fprintf(stderr, "%s", "gnunet-helper-fs-publish needs exactly one or two arguments\n"); -#if WINDOWS - GNUNET_free((void *)argv); -#endif return 1; } filename_expanded = argv[1]; @@ -547,9 +530,6 @@ main(int argc, char *const *argv) (void)write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); #if HAVE_LIBEXTRACTOR EXTRACTOR_plugin_remove_all(plugins); -#endif -#if WINDOWS - GNUNET_free((void *)argv); #endif return 2; } @@ -562,9 +542,6 @@ main(int argc, char *const *argv) { #if HAVE_LIBEXTRACTOR EXTRACTOR_plugin_remove_all(plugins); -#endif -#if WINDOWS - GNUNET_free((void *)argv); #endif return 3; } @@ -578,9 +555,6 @@ main(int argc, char *const *argv) free_tree(root); #if HAVE_LIBEXTRACTOR EXTRACTOR_plugin_remove_all(plugins); -#endif -#if WINDOWS - GNUNET_free((void *)argv); #endif return 4; } @@ -592,9 +566,6 @@ main(int argc, char *const *argv) 0); #if HAVE_LIBEXTRACTOR EXTRACTOR_plugin_remove_all(plugins); -#endif -#if WINDOWS - GNUNET_free((void *)argv); #endif return 0; } 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, GNUNET_free(args); return 1; } -#ifdef WINDOWS - if (GNUNET_OS_PROCESS_EXITED != *st || 0 != *code) - { - ret = 7; - fprintf(stderr, "`%s' did not end correctly (%d, %d)\n", args, *st, *code); - return 1; - } -#endif return 0; } 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 @@ #ifndef __GAUGER_H__ #define __GAUGER_H__ -#ifndef WINDOWS - #include #include #include @@ -79,32 +77,4 @@ } \ } -#else /* WINDOWS */ - -#include -#include -#include - -#define GAUGER(category, counter, value, unit) \ - { \ - char __gauger_commandline[MAX_PATH]; \ - \ - snprintf(__gauger_commandline, MAX_PATH, "gauger.py -n \"%s\" -d \"%Lf\" -u \"%s\" -c \"%s\"", \ - (counter), (long double)(value), (unit), (category)); \ - __gauger_commandline[MAX_PATH - 1] = '\0'; \ - system(__gauger_commandline); \ - } - -#define GAUGER_ID(category, counter, value, unit, id) \ - { \ - char __gauger_commandline[MAX_PATH]; \ - \ - snprintf(__gauger_commandline, MAX_PATH, "gauger.py -n \"%s\" -d \"%Lf\" -u \"%s\" -i \"%s\" -c \"%s\"", \ - (counter), (long double)(value), (unit), (id), (category)); \ - __gauger_commandline[MAX_PATH - 1] = '\0'; \ - system(__gauger_commandline); \ - } - -#endif // WINDOWS - #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 { * Handle used to access files (and pipes). */ struct GNUNET_DISK_FileHandle { -#if WINDOWS /** - * File handle under W32. - */ - HANDLE h; - - /** - * Type - */ - enum GNUNET_FILE_Type type; - - /** - * Structure for overlapped reading (for pipes) - */ - OVERLAPPED *oOverlapRead; - - /** - * Structure for overlapped writing (for pipes) - */ - OVERLAPPED *oOverlapWrite; -#else - /** - * File handle on other OSes. + * File handle on Unix-like systems. */ int fd; -#endif }; @@ -495,19 +473,6 @@ const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n); - -#if WINDOWS -/** - * Get a GNUnet file handle from a W32 handle (W32-only). - * Do not call on non-W32 platforms (returns NULL). - * - * @param handle native handle - * @return GNUnet file handle corresponding to the W32 handle - */ -struct GNUNET_DISK_FileHandle * -GNUNET_DISK_get_handle_from_w32_handle(HANDLE osfh); -#endif - /** * Update POSIX permissions mask of a file on disk. If both argumets * 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 { */ fd_set sds; -#ifdef WINDOWS - /** - * Array of file handles (from pipes) that are also in - * the FDSet. Needed as those cannot go into @e sds - * on W32. - */ - const struct GNUNET_DISK_FileHandle **handles; - - /** - * Size of the @e handles array - */ - unsigned int handles_size; - - /** - * Number of @e handles slots in use. Always - * smaller than @e handles_size. - */ - unsigned int handles_pos; -#endif }; #include "gnunet_disk_lib.h" @@ -107,7 +88,6 @@ char * GNUNET_NETWORK_shorten_unixpath(char *unixpath); -#ifndef WINDOWS /** * If services crash, they can leave a unix domain socket file on the * disk. This needs to be manually removed, because otherwise both @@ -119,7 +99,6 @@ GNUNET_NETWORK_shorten_unixpath(char *unixpath); */ void GNUNET_NETWORK_unix_precheck(const struct sockaddr_un *un); -#endif /** @@ -406,19 +385,6 @@ GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc); -#if WINDOWS -/** - * Add a W32 file handle to the fd set - * - * @param fds fd set - * @param h the file handle to add - */ -void -GNUNET_NETWORK_fdset_handle_set_native_w32_handle(struct GNUNET_NETWORK_FDSet *fds, - HANDLE h); -#endif - - /** * Check whether a socket is part of the fd set * 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 @@ #endif #endif -#ifdef WINDOWS -#define BREAKPOINT asm ("int $3;"); -#define GNUNET_SIGCHLD 17 -#else #define BREAKPOINT #define GNUNET_SIGCHLD SIGCHLD -#endif #ifdef HAVE_SYS_TYPES_H #include @@ -70,18 +65,6 @@ #define VERBOSE_STATS 0 -#ifdef CYGWIN -#include -#endif - -#ifdef _MSC_VER -#ifndef FD_SETSIZE -#define FD_SETSIZE 1024 -#endif -#include -#include -#else -#ifndef MINGW #include #include #include @@ -100,10 +83,6 @@ #include #include #include -#else -#include "winproc.h" -#endif -#endif #include #include @@ -114,20 +93,13 @@ #include #include #include -#ifdef WINDOWS -#include /* for alloca(), on other OSes it's in stdlib.h */ -#endif #ifdef HAVE_MALLOC_H #include /* for mallinfo on GNU */ #endif -#ifndef _MSC_VER #include /* KLB_FIX */ -#endif #include #include -#ifndef _MSC_VER #include /* KLB_FIX */ -#endif #include #include #if HAVE_SYS_PARAM_H @@ -170,10 +142,6 @@ #if HAVE_SYS_UCRED_H #include #endif -#ifdef CYGWIN -#include -#include -#endif #if HAVE_IFADDRS_H #include #endif @@ -196,24 +164,11 @@ #include #endif -/* From plibc. */ -#ifdef Q_OS_WIN32 -#define WINDOWS 1 -#endif - -#ifndef WINDOWS #define DIR_SEPARATOR '/' #define DIR_SEPARATOR_STR "/" #define PATH_SEPARATOR ':' #define PATH_SEPARATOR_STR ":" #define NEWLINE "\n" -#else -#define DIR_SEPARATOR '\\' -#define DIR_SEPARATOR_STR "\\" -#define PATH_SEPARATOR ';' -#define PATH_SEPARATOR_STR ";" -#define NEWLINE "\r\n" -#endif #include "compat.h" @@ -231,15 +186,7 @@ #define LIBEXTRACTOR_GETTEXT_DOMAIN "org.gnunet.libextractor" #endif -#ifdef CYGWIN -#define SIOCGIFCONF _IOW('s', 100, struct ifconf) /* get if list */ -#define SIOCGIFFLAGS _IOW('s', 101, struct ifreq) /* Get if flags */ -#define SIOCGIFADDR _IOW('s', 102, struct ifreq) /* Get if addr */ -#endif - -#ifndef MINGW #include -#endif #ifdef FREEBSD #define __BYTE_ORDER BYTE_ORDER @@ -286,13 +233,8 @@ atoll(const char *nptr); #define MAKE_UNALIGNED(val) val #endif -#if WINDOWS -#define FDTYPE HANDLE -#define SOCKTYPE SOCKET -#else #define FDTYPE int #define SOCKTYPE int -#endif /** * 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, char *home_dir; struct stat st; -#ifndef WINDOWS struct passwd *pw; -#endif + int configured; -#ifndef WINDOWS pw = getpwuid(getuid()); if (!pw) { @@ -185,13 +183,7 @@ get_my_cnf_path(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_free(home_dir); configured = GNUNET_NO; } -#else - home_dir = (char *)GNUNET_malloc(_MAX_PATH + 1); - plibc_conv_to_win_path("~/", home_dir); - GNUNET_asprintf(&cnffile, "%s/.my.cnf", home_dir); - GNUNET_free(home_dir); - configured = GNUNET_NO; -#endif + GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "mysql", _("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 @@ /** * We need pipe control only on WINDOWS */ -#if WINDOWS -#define PIPE_CONTROL GNUNET_YES -#else #define PIPE_CONTROL GNUNET_NO -#endif /** @@ -394,25 +390,17 @@ tokenizer_cb(void *cls, const struct GNUNET_MessageHeader *message) { /* unsetting the variable will invalidate the pointer! */ evstr = GNUNET_strdup(evstr); -#ifdef WINDOWS - GNUNET_break(0 != SetEnvironmentVariable(GNUNET_TESTING_PREFIX, NULL)); -#else GNUNET_break(0 == unsetenv(GNUNET_TESTING_PREFIX)); -#endif } test_system = GNUNET_TESTING_system_create("testbed-helper", trusted_ip, hostname, NULL); if (NULL != evstr) { -#ifdef WINDOWS - GNUNET_assert(0 != SetEnvironmentVariable(GNUNET_TESTING_PREFIX, evstr)); -#else char *evar; GNUNET_asprintf(&evar, GNUNET_TESTING_PREFIX "=%s", evstr); GNUNET_assert(0 == putenv(evar)); /* consumes 'evar', see putenv(): becomes part of envrionment! */ -#endif GNUNET_free(evstr); evstr = NULL; } 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 @@ static processor_cpu_load_info_t prev_cpu_load; #endif -#ifdef WINDOWS -#include -#endif #define DEBUG_STATUSCALLS GNUNET_NO 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 @@ /** * We need pipe control only on WINDOWS */ -#if WINDOWS -#define PIPE_CONTROL GNUNET_YES -#else #define PIPE_CONTROL GNUNET_NO -#endif /** 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, (!check_ipv6_listed(sctx->v6_denied, &i6->sin6_addr))); break; -#ifndef WINDOWS case AF_UNIX: ret = GNUNET_OK; /* controlled using file-system ACL now */ break; -#endif + default: LOG(GNUNET_ERROR_TYPE_WARNING, _("Unknown address family %d\n"), @@ -1203,7 +1202,7 @@ service_task(void *cls) sctx->ret = GNUNET_SYSERR; return; } -#ifndef WINDOWS + if (NULL != sctx->addrs) for (i = 0; NULL != sctx->addrs[i]; i++) if ((AF_UNIX == sctx->addrs[i]->sa_family) && @@ -1213,8 +1212,6 @@ service_task(void *cls) ->sun_path, sctx->match_uid, sctx->match_gid); -#endif - if (0 == (sctx->options & LEGACY_SERVICE_OPTION_MANUAL_SHUTDOWN)) { @@ -1647,7 +1644,7 @@ LEGACY_SERVICE_start(const char *service_name, LEGACY_SERVICE_stop(sctx); return NULL; } -#ifndef WINDOWS + if (NULL != sctx->addrs) for (i = 0; NULL != sctx->addrs[i]; i++) if ((AF_UNIX == sctx->addrs[i]->sa_family) && @@ -1657,7 +1654,7 @@ LEGACY_SERVICE_start(const char *service_name, ->sun_path, sctx->match_uid, sctx->match_gid); -#endif + sctx->my_handlers = GNUNET_malloc(sizeof(defhandlers)); GNUNET_memcpy(sctx->my_handlers, defhandlers, sizeof(defhandlers)); 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) char *filename = NULL; char *res; -#if WINDOWS - if ((strlen(pch) >= 3) && pch[1] == ':') - { - if (NULL != strstr(pch, "\\")) - { - pch = strtok(pch, "\\"); - while (pch != NULL) - { - pch = strtok(NULL, "\\"); - if (pch != NULL) - filename = pch; - } - } - } - if (filename != NULL) - pch = filename; /* If we miss the next condition, filename = pch will - * not harm us. - */ -#endif if (NULL != strstr(pch, "/")) { 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) #define BAADFOOD_STR "\xBA\xAD\xF0\x0D" #endif -#if WINDOWS -#define M_SIZE(p) _msize(p) -#endif #if HAVE_MALLOC_NP_H #include #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; static int gnunet_force_log_present; #endif -#ifdef WINDOWS -/** - * Contains the number of performance counts per second. - */ -static LARGE_INTEGER performance_frequency; -#endif - /** * Convert a textual description of a loglevel @@ -283,9 +276,6 @@ get_type(const char *log) void GNUNET_abort_() { -#if WINDOWS - DebugBreak(); -#endif abort(); } @@ -377,14 +367,10 @@ setup_log_file(const struct tm *tm) strerror(errno)); return GNUNET_SYSERR; } -#if WINDOWS - altlog_fd = - open(fn, O_APPEND | O_BINARY | O_WRONLY | O_CREAT, _S_IREAD | _S_IWRITE); -#else altlog_fd = open(fn, O_APPEND | O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); -#endif + if (-1 != altlog_fd) { if (NULL != GNUNET_stderr) @@ -724,9 +710,6 @@ GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile) min_level = get_type(loglevel); #if !defined(GNUNET_CULL_LOGGING) parse_all_definitions(); -#endif -#ifdef WINDOWS - QueryPerformanceFrequency(&performance_frequency); #endif GNUNET_free_non_null(component); GNUNET_asprintf(&component, "%s-%d", comp, getpid()); @@ -809,10 +792,6 @@ GNUNET_logger_remove(GNUNET_Logger logger, void *logger_cls) GNUNET_free(pos); } -#if WINDOWS -CRITICAL_SECTION output_message_cs; -#endif - /** * Actually output the log message. @@ -830,9 +809,6 @@ output_message(enum GNUNET_ErrorType kind, { struct CustomLogger *pos; -#if WINDOWS - EnterCriticalSection(&output_message_cs); -#endif /* only use the standard logger if no custom loggers are present */ if ((NULL != GNUNET_stderr) && (NULL == loggers)) { @@ -887,9 +863,6 @@ output_message(enum GNUNET_ErrorType kind, pos->logger(pos->logger_cls, kind, comp, datestr, msg); pos = pos->next; } -#if WINDOWS - LeaveCriticalSection(&output_message_cs); -#endif } @@ -1003,33 +976,7 @@ mylog(enum GNUNET_ErrorType kind, { char buf[size]; long long offset; -#ifdef WINDOWS - LARGE_INTEGER pc; - time_t timetmp; - offset = GNUNET_TIME_get_offset(); - time(&timetmp); - timetmp += offset / 1000; - tmptr = localtime(&timetmp); - pc.QuadPart = 0; - QueryPerformanceCounter(&pc); - if (NULL == tmptr) - { - strcpy(date, "localtime error"); - } - else - { - if (0 == - strftime(date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%020llu", tmptr)) - abort(); - if (0 > snprintf(date, - sizeof(date), - date2, - (long long)(pc.QuadPart / - (performance_frequency.QuadPart / 1000)))) - abort(); - } -#else struct timeval timeofday; gettimeofday(&timeofday, NULL); @@ -1069,7 +1016,7 @@ mylog(enum GNUNET_ErrorType kind, if (0 > snprintf(date, sizeof(date), date2, timeofday.tv_usec)) abort(); } -#endif + vsnprintf(buf, size, message, va); #if !(defined(GNUNET_CULL_LOGGING) || TALER_WALLET_ONLY) if (NULL != tmptr) @@ -1433,13 +1380,9 @@ GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid) const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen) { -#ifndef WINDOWS #define LEN \ GNUNET_MAX((INET6_ADDRSTRLEN + 8), \ (1 + sizeof(struct sockaddr_un) - sizeof(sa_family_t))) -#else -#define LEN (INET6_ADDRSTRLEN + 8) -#endif static char buf[LEN]; #undef LEN static char b2[6]; @@ -1603,13 +1546,6 @@ GNUNET_async_scope_get(struct GNUNET_AsyncScopeSave *scope_ret) void __attribute__ ((constructor)) GNUNET_util_cl_init() { GNUNET_stderr = stderr; -#ifdef MINGW - GNInitWinEnv(NULL); -#endif -#if WINDOWS - if (!InitializeCriticalSectionAndSpinCount(&output_message_cs, 0x00000400)) - GNUNET_abort_(); -#endif } @@ -1618,12 +1554,7 @@ void __attribute__ ((constructor)) GNUNET_util_cl_init() */ void __attribute__ ((destructor)) GNUNET_util_cl_fini() { -#if WINDOWS - DeleteCriticalSection(&output_message_cs); -#endif -#ifdef MINGW - GNShutdownWinEnv(); -#endif + } /* 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) int GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size) { -#if WINDOWS - BOOL b; - LARGE_INTEGER li; - b = GetFileSizeEx(fh->h, &li); - if (!b) - { - SetErrnoFromWinError(GetLastError()); - return GNUNET_SYSERR; - } - *size = (off_t)li.QuadPart; -#else struct stat sbuf; if (0 != fstat(fh->fd, &sbuf)) return GNUNET_SYSERR; *size = sbuf.st_size; -#endif return GNUNET_OK; } @@ -324,29 +312,6 @@ GNUNET_DISK_file_get_identifiers(const char *filename, uint64_t *dev, uint64_t *ino) { -#if WINDOWS - { - // FIXME NILS: test this - struct GNUNET_DISK_FileHandle *fh; - BY_HANDLE_FILE_INFORMATION info; - int succ; - - fh = GNUNET_DISK_file_open(filename, - GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); - if (NULL == fh) - return GNUNET_SYSERR; - succ = GetFileInformationByHandle(fh->h, &info); - GNUNET_DISK_file_close(fh); - if (!succ) - { - return GNUNET_SYSERR; - } - *dev = info.dwVolumeSerialNumber; - *ino = ((((uint64_t)info.nFileIndexHigh) << (sizeof(DWORD) * 8)) | - info.nFileIndexLow); - } -#else /* !WINDOWS */ #if HAVE_STAT { struct stat sbuf; @@ -384,7 +349,6 @@ GNUNET_DISK_file_get_identifiers(const char *filename, #else *dev = 0; #endif -#endif /* !WINDOWS */ return GNUNET_OK; } @@ -402,11 +366,7 @@ mktemp_name(const char *t) char *tmpl; char *fn; - if ((t[0] != '/') && (t[0] != '\\') -#if WINDOWS - && !(isalpha((int)t[0]) && (t[0] != '\0') && (t[1] == ':')) -#endif - ) + if ((t[0] != '/') && (t[0] != '\\')) { /* FIXME: This uses system codepage on W32, not UTF-8 */ tmpdir = getenv("TMPDIR"); @@ -422,71 +382,10 @@ mktemp_name(const char *t) { GNUNET_asprintf(&tmpl, "%s%s", t, "XXXXXX"); } -#ifdef MINGW - fn = (char *)GNUNET_malloc(MAX_PATH + 1); - if (ERROR_SUCCESS != plibc_conv_to_win_path(tmpl, fn)) - { - GNUNET_free(fn); - GNUNET_free(tmpl); - return NULL; - } - GNUNET_free(tmpl); -#else fn = tmpl; -#endif - return fn; -} - - -#if WINDOWS -static char * -mkdtemp(char *fn) -{ - char *random_fn; - char *tfn; - - while (1) - { - tfn = GNUNET_strdup(fn); - random_fn = _mktemp(tfn); - if (NULL == random_fn) - { - GNUNET_free(tfn); - return NULL; - } - /* FIXME: assume fn to be UTF-8-encoded and do the right thing */ - if (0 == CreateDirectoryA(tfn, NULL)) - { - DWORD error = GetLastError(); - GNUNET_free(tfn); - if (ERROR_ALREADY_EXISTS == error) - continue; - return NULL; - } - break; - } - strcpy(fn, tfn); return fn; } -/** - * Update POSIX permissions mask of a file on disk. If both argumets - * are #GNUNET_NO, the file is made world-read-write-executable (777). - * Does nothing on W32. - * - * @param fn name of the file to update - * @param require_uid_match #GNUNET_YES means 700 - * @param require_gid_match #GNUNET_YES means 770 unless @a require_uid_match is set - */ -void -GNUNET_DISK_fix_permissions(const char *fn, - int require_uid_match, - int require_gid_match) -{ - /* nothing on W32 */ -} - -#else /** * Update POSIX permissions mask of a file on disk. If both argumets @@ -514,7 +413,6 @@ GNUNET_DISK_fix_permissions(const char *fn, GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "chmod", fn); } -#endif /** * Create an (empty) temporary directory on disk. If the given name is not @@ -724,28 +622,9 @@ GNUNET_DISK_directory_create(const char *dir) } len = strlen(rdir); -#ifndef MINGW + pos = 1; /* skip heading '/' */ -#else - /* Local or Network path? */ - if (strncmp(rdir, "\\\\", 2) == 0) - { - pos = 2; - while (rdir[pos]) - { - if (rdir[pos] == '\\') - { - pos++; - break; - } - pos++; - } - } - else - { - pos = 3; /* strlen("C:\\") */ - } -#endif + /* Check which low level directories already exist */ pos2 = len; rdir[len] = DIR_SEPARATOR; @@ -792,17 +671,10 @@ GNUNET_DISK_directory_create(const char *dir) } if (GNUNET_SYSERR == ret) { -#ifndef MINGW ret = mkdir(rdir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); /* 755 */ -#else - wchar_t wrdir[MAX_PATH + 1]; - if (ERROR_SUCCESS == plibc_conv_to_win_pathwconv(rdir, wrdir)) - ret = !CreateDirectoryW(wrdir, NULL); - else - ret = 1; -#endif + if ((ret != 0) && (errno != EEXIST)) { LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_ERROR, "mkdir", rdir); @@ -887,42 +759,7 @@ GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, return GNUNET_SYSERR; } -#ifdef MINGW - DWORD bytes_read; - - if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE) - { - if (!ReadFile(h->h, result, len, &bytes_read, NULL)) - { - SetErrnoFromWinError(GetLastError()); - return GNUNET_SYSERR; - } - } - else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE) - { - if (!ReadFile(h->h, result, len, &bytes_read, h->oOverlapRead)) - { - if (GetLastError() != ERROR_IO_PENDING) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Error reading from pipe: %u\n", - GetLastError()); - SetErrnoFromWinError(GetLastError()); - return GNUNET_SYSERR; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n"); - GetOverlappedResult(h->h, h->oOverlapRead, &bytes_read, TRUE); - } - LOG(GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes from pipe\n", bytes_read); - } - else - { - bytes_read = 0; - } - return bytes_read; -#else return read(h->fd, result, len); -#endif } @@ -947,45 +784,6 @@ GNUNET_DISK_file_read_non_blocking(const struct GNUNET_DISK_FileHandle *h, return GNUNET_SYSERR; } -#ifdef MINGW - DWORD bytes_read; - - if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE) - { - if (!ReadFile(h->h, result, len, &bytes_read, NULL)) - { - SetErrnoFromWinError(GetLastError()); - return GNUNET_SYSERR; - } - } - else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE) - { - if (!ReadFile(h->h, result, len, &bytes_read, h->oOverlapRead)) - { - if (GetLastError() != ERROR_IO_PENDING) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Error reading from pipe: %u\n", - GetLastError()); - SetErrnoFromWinError(GetLastError()); - return GNUNET_SYSERR; - } - else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "ReadFile() queued a read, cancelling\n"); - CancelIo(h->h); - errno = EAGAIN; - return GNUNET_SYSERR; - } - } - LOG(GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes\n", bytes_read); - } - else - { - bytes_read = 0; - } - return bytes_read; -#else int flags; ssize_t ret; @@ -1001,7 +799,6 @@ GNUNET_DISK_file_read_non_blocking(const struct GNUNET_DISK_FileHandle *h, errno = eno; } return ret; -#endif } @@ -1050,78 +847,8 @@ GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, return GNUNET_SYSERR; } -#ifdef MINGW - DWORD bytes_written; - if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE) - { - if (!WriteFile(h->h, buffer, n, &bytes_written, NULL)) - { - SetErrnoFromWinError(GetLastError()); - return GNUNET_SYSERR; - } - } - else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write %u bytes\n", n); - if (!WriteFile(h->h, buffer, n, &bytes_written, h->oOverlapWrite)) - { - if (GetLastError() != ERROR_IO_PENDING) - { - SetErrnoFromWinError(GetLastError()); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Error writing to pipe: %u\n", - GetLastError()); - return GNUNET_SYSERR; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n"); - if (!GetOverlappedResult(h->h, h->oOverlapWrite, &bytes_written, TRUE)) - { - SetErrnoFromWinError(GetLastError()); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Error getting overlapped result while writing to pipe: %u\n", - GetLastError()); - return GNUNET_SYSERR; - } - } - else - { - DWORD ovr; - if (!GetOverlappedResult(h->h, h->oOverlapWrite, &ovr, TRUE)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Error getting control overlapped result while writing to pipe: %u\n", - GetLastError()); - } - else - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Wrote %u bytes (ovr says %u), picking the greatest\n", - bytes_written, - ovr); - } - } - if (bytes_written == 0) - { - if (n > 0) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Wrote %u bytes, returning -1 with EAGAIN\n", - bytes_written); - errno = EAGAIN; - return GNUNET_SYSERR; - } - } - LOG(GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytes_written); - } - else - { - bytes_written = 0; - } - return bytes_written; -#else return write(h->fd, buffer, n); -#endif } @@ -1144,34 +871,7 @@ GNUNET_DISK_file_write_blocking(const struct GNUNET_DISK_FileHandle *h, return GNUNET_SYSERR; } -#ifdef MINGW - DWORD bytes_written; - /* We do a non-overlapped write, which is as blocking as it gets */ - LOG(GNUNET_ERROR_TYPE_DEBUG, "Writing %u bytes\n", n); - if (!WriteFile(h->h, buffer, n, &bytes_written, NULL)) - { - SetErrnoFromWinError(GetLastError()); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Error writing to pipe: %u\n", - GetLastError()); - return GNUNET_SYSERR; - } - if (bytes_written == 0 && n > 0) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "Waiting for pipe to clean\n"); - WaitForSingleObject(h->h, INFINITE); - if (!WriteFile(h->h, buffer, n, &bytes_written, NULL)) - { - SetErrnoFromWinError(GetLastError()); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Error writing to pipe: %u\n", - GetLastError()); - return GNUNET_SYSERR; - } - } - LOG(GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytes_written); - return bytes_written; -#else + int flags; ssize_t ret; @@ -1183,7 +883,6 @@ GNUNET_DISK_file_write_blocking(const struct GNUNET_DISK_FileHandle *h, if (0 == (flags & O_NONBLOCK)) (void)fcntl(h->fd, F_SETFL, flags); return ret; -#endif } @@ -1486,7 +1185,6 @@ GNUNET_DISK_filename_canonicalize(char *fn) int GNUNET_DISK_file_change_owner(const char *filename, const char *user) { -#ifndef MINGW struct passwd *pws; pws = getpwnam(user); @@ -1503,7 +1201,6 @@ GNUNET_DISK_file_change_owner(const char *filename, const char *user) LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "chown", filename); return GNUNET_SYSERR; } -#endif return GNUNET_OK; } @@ -1529,7 +1226,6 @@ GNUNET_DISK_file_lock(struct GNUNET_DISK_FileHandle *fh, return GNUNET_SYSERR; } -#ifndef MINGW struct flock fl; memset(&fl, 0, sizeof(struct flock)); @@ -1539,33 +1235,6 @@ GNUNET_DISK_file_lock(struct GNUNET_DISK_FileHandle *fh, fl.l_len = lock_end; return fcntl(fh->fd, F_SETLK, &fl) != 0 ? GNUNET_SYSERR : GNUNET_OK; -#else - OVERLAPPED o; - off_t diff = lock_end - lock_start; - DWORD diff_low, diff_high; - diff_low = (DWORD)(diff & 0xFFFFFFFF); - diff_high = (DWORD)((diff >> (sizeof(DWORD) * 8)) & 0xFFFFFFFF); - - memset(&o, 0, sizeof(OVERLAPPED)); - o.Offset = (DWORD)(lock_start & 0xFFFFFFFF); - ; - o.OffsetHigh = - (DWORD)(((lock_start & ~0xFFFFFFFF) >> (sizeof(DWORD) * 8)) & 0xFFFFFFFF); - - if (!LockFileEx(fh->h, - (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) | - LOCKFILE_FAIL_IMMEDIATELY, - 0, - diff_low, - diff_high, - &o)) - { - SetErrnoFromWinError(GetLastError()); - return GNUNET_SYSERR; - } - - return GNUNET_OK; -#endif } @@ -1588,7 +1257,6 @@ GNUNET_DISK_file_unlock(struct GNUNET_DISK_FileHandle *fh, return GNUNET_SYSERR; } -#ifndef MINGW struct flock fl; memset(&fl, 0, sizeof(struct flock)); @@ -1598,27 +1266,6 @@ GNUNET_DISK_file_unlock(struct GNUNET_DISK_FileHandle *fh, fl.l_len = unlock_end; return fcntl(fh->fd, F_SETLK, &fl) != 0 ? GNUNET_SYSERR : GNUNET_OK; -#else - OVERLAPPED o; - off_t diff = unlock_end - unlock_start; - DWORD diff_low, diff_high; - diff_low = (DWORD)(diff & 0xFFFFFFFF); - diff_high = (DWORD)((diff >> (sizeof(DWORD) * 8)) & 0xFFFFFFFF); - - memset(&o, 0, sizeof(OVERLAPPED)); - o.Offset = (DWORD)(unlock_start & 0xFFFFFFFF); - ; - o.OffsetHigh = (DWORD)( - ((unlock_start & ~0xFFFFFFFF) >> (sizeof(DWORD) * 8)) & 0xFFFFFFFF); - - if (!UnlockFileEx(fh->h, 0, diff_low, diff_high, &o)) - { - SetErrnoFromWinError(GetLastError()); - return GNUNET_SYSERR; - } - - return GNUNET_OK; -#endif } @@ -1642,16 +1289,9 @@ GNUNET_DISK_file_open(const char *fn, char *expfn; struct GNUNET_DISK_FileHandle *ret; -#ifdef MINGW - DWORD access; - DWORD disp; - HANDLE h; - wchar_t wexpfn[MAX_PATH + 1]; -#else int oflags; int mode; int fd; -#endif expfn = GNUNET_STRINGS_filename_expand(fn); if (NULL == expfn) @@ -1767,12 +1407,9 @@ GNUNET_DISK_file_open(const char *fn, #endif ret = GNUNET_new(struct GNUNET_DISK_FileHandle); -#ifdef MINGW - ret->h = h; - ret->type = GNUNET_DISK_HANLDE_TYPE_FILE; -#else + ret->fd = fd; -#endif + GNUNET_free(expfn); return ret; } @@ -1797,111 +1434,17 @@ GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h) ret = GNUNET_OK; -#if MINGW - if (!CloseHandle(h->h)) - { - SetErrnoFromWinError(GetLastError()); - LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "close"); - ret = GNUNET_SYSERR; - } - if (h->oOverlapRead) - { - if (!CloseHandle(h->oOverlapRead->hEvent)) - { - SetErrnoFromWinError(GetLastError()); - LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "close"); - ret = GNUNET_SYSERR; - } - GNUNET_free(h->oOverlapRead); - } - if (h->oOverlapWrite) - { - if (!CloseHandle(h->oOverlapWrite->hEvent)) - { - SetErrnoFromWinError(GetLastError()); - LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "close"); - ret = GNUNET_SYSERR; - } - GNUNET_free(h->oOverlapWrite); - } -#else if (close(h->fd) != 0) { LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "close"); ret = GNUNET_SYSERR; } -#endif + GNUNET_free(h); return ret; } -#ifdef WINDOWS -/** - * Get a GNUnet file handle from a W32 handle. - * - * @param handle native handle - * @return GNUnet file handle corresponding to the W32 handle - */ -struct GNUNET_DISK_FileHandle * -GNUNET_DISK_get_handle_from_w32_handle(HANDLE osfh) -{ - struct GNUNET_DISK_FileHandle *fh; - DWORD dwret; - enum GNUNET_FILE_Type ftype; - - dwret = GetFileType(osfh); - switch (dwret) - { - case FILE_TYPE_DISK: - ftype = GNUNET_DISK_HANLDE_TYPE_FILE; - break; - - case FILE_TYPE_PIPE: - ftype = GNUNET_DISK_HANLDE_TYPE_PIPE; - break; - - case FILE_TYPE_UNKNOWN: - if ((GetLastError() == NO_ERROR) || - (GetLastError() == ERROR_INVALID_HANDLE)) - { - if (0 != ResetEvent(osfh)) - ftype = GNUNET_DISK_HANLDE_TYPE_EVENT; - else - return NULL; - } - else - return NULL; - break; - - default: - return NULL; - } - - fh = GNUNET_new(struct GNUNET_DISK_FileHandle); - - fh->h = osfh; - fh->type = ftype; - if (ftype == GNUNET_DISK_HANLDE_TYPE_PIPE) - { - /** - * Note that we can't make it overlapped if it isn't already. - * (ReOpenFile() is only available in 2003/Vista). - * The process that opened this file in the first place (usually a parent - * process, if this is stdin/stdout/stderr) must make it overlapped, - * otherwise we're screwed, as selecting on non-overlapped handle - * will block. - */ - fh->oOverlapRead = GNUNET_new(OVERLAPPED); - fh->oOverlapWrite = GNUNET_new(OVERLAPPED); - fh->oOverlapRead->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - fh->oOverlapWrite->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - } - - return fh; -} -#endif - /** * Get a handle from a native integer FD. * @@ -1916,19 +1459,9 @@ GNUNET_DISK_get_handle_from_int_fd(int fno) if ((((off_t)-1) == lseek(fno, 0, SEEK_CUR)) && (EBADF == errno)) return NULL; /* invalid FD */ -#ifndef WINDOWS fh = GNUNET_new(struct GNUNET_DISK_FileHandle); fh->fd = fno; -#else - intptr_t osfh; - - osfh = _get_osfhandle(fno); - if (INVALID_HANDLE_VALUE == (HANDLE)osfh) - return NULL; - - fh = GNUNET_DISK_get_handle_from_w32_handle((HANDLE)osfh); -#endif return fh; } @@ -1962,17 +1495,10 @@ struct GNUNET_DISK_MapHandle { */ void *addr; -#ifdef MINGW - /** - * Underlying OS handle. - */ - HANDLE h; -#else /** * Number of bytes mapped. */ size_t len; -#endif }; @@ -2001,50 +1527,6 @@ GNUNET_DISK_file_map(const struct GNUNET_DISK_FileHandle *h, return NULL; } -#ifdef MINGW - DWORD mapAccess, protect; - - if ((access & GNUNET_DISK_MAP_TYPE_READ) && - (access & GNUNET_DISK_MAP_TYPE_WRITE)) - { - protect = PAGE_READWRITE; - mapAccess = FILE_MAP_ALL_ACCESS; - } - else if (access & GNUNET_DISK_MAP_TYPE_READ) - { - protect = PAGE_READONLY; - mapAccess = FILE_MAP_READ; - } - else if (access & GNUNET_DISK_MAP_TYPE_WRITE) - { - protect = PAGE_READWRITE; - mapAccess = FILE_MAP_WRITE; - } - else - { - GNUNET_break(0); - return NULL; - } - - *m = GNUNET_new(struct GNUNET_DISK_MapHandle); - (*m)->h = CreateFileMapping(h->h, NULL, protect, 0, 0, NULL); - if ((*m)->h == INVALID_HANDLE_VALUE) - { - SetErrnoFromWinError(GetLastError()); - GNUNET_free(*m); - return NULL; - } - - (*m)->addr = MapViewOfFile((*m)->h, mapAccess, 0, 0, len); - if (!(*m)->addr) - { - SetErrnoFromWinError(GetLastError()); - CloseHandle((*m)->h); - GNUNET_free(*m); - } - - return (*m)->addr; -#else int prot; prot = 0; @@ -2062,7 +1544,6 @@ GNUNET_DISK_file_map(const struct GNUNET_DISK_FileHandle *h, } (*m)->len = len; return (*m)->addr; -#endif } /** @@ -2081,18 +1562,8 @@ GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h) return GNUNET_SYSERR; } -#ifdef MINGW - ret = UnmapViewOfFile(h->addr) ? GNUNET_OK : GNUNET_SYSERR; - if (ret != GNUNET_OK) - SetErrnoFromWinError(GetLastError()); - if (!CloseHandle(h->h) && (ret == GNUNET_OK)) - { - ret = GNUNET_SYSERR; - SetErrnoFromWinError(GetLastError()); - } -#else ret = munmap(h->addr, h->len) != -1 ? GNUNET_OK : GNUNET_SYSERR; -#endif + GNUNET_free(h); return ret; } @@ -2112,14 +1583,7 @@ GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h) return GNUNET_SYSERR; } -#ifdef MINGW - int ret; - - ret = FlushFileBuffers(h->h) ? GNUNET_OK : GNUNET_SYSERR; - if (ret != GNUNET_OK) - SetErrnoFromWinError(GetLastError()); - return ret; -#elif defined(FREEBSD) || defined(OPENBSD) || defined(DARWIN) +#if defined(FREEBSD) || defined(OPENBSD) || defined(DARWIN) return fsync(h->fd) == -1 ? GNUNET_SYSERR : GNUNET_OK; #else return fdatasync(h->fd) == -1 ? GNUNET_SYSERR : GNUNET_OK; @@ -2127,151 +1591,6 @@ GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h) } -#if WINDOWS -#ifndef PIPE_BUF -#define PIPE_BUF 512 -#endif -/* Copyright Bob Byrnes curl.com> - http://permalink.gmane.org/gmane.os.cygwin.patches/2121 - */ -/* Create a pipe, and return handles to the read and write ends, - just like CreatePipe, but ensure that the write end permits - FILE_READ_ATTRIBUTES access, on later versions of win32 where - this is supported. This access is needed by NtQueryInformationFile, - which is used to implement select and nonblocking writes. - Note that the return value is either NO_ERROR or GetLastError, - unlike CreatePipe, which returns a bool for success or failure. */ -static int -create_selectable_pipe(PHANDLE read_pipe_ptr, - PHANDLE write_pipe_ptr, - LPSECURITY_ATTRIBUTES sa_ptr, - DWORD psize, - DWORD dwReadMode, - DWORD dwWriteMode) -{ - /* Default to error. */ - *read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE; - - HANDLE read_pipe; - HANDLE write_pipe; - - /* Ensure that there is enough pipe buffer space for atomic writes. */ - if (psize < PIPE_BUF) - psize = PIPE_BUF; - - char pipename[MAX_PATH]; - - /* Retry CreateNamedPipe as long as the pipe name is in use. - * Retrying will probably never be necessary, but we want - * to be as robust as possible. */ - while (1) - { - static volatile LONG pipe_unique_id; - - snprintf(pipename, - sizeof pipename, - "\\\\.\\pipe\\gnunet-%d-%ld", - getpid(), - InterlockedIncrement((LONG *)&pipe_unique_id)); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "CreateNamedPipe: name = %s, size = %lu\n", - pipename, - psize); - /* Use CreateNamedPipe instead of CreatePipe, because the latter - * returns a write handle that does not permit FILE_READ_ATTRIBUTES - * access, on versions of win32 earlier than WinXP SP2. - * CreatePipe also stupidly creates a full duplex pipe, which is - * a waste, since only a single direction is actually used. - * It's important to only allow a single instance, to ensure that - * the pipe was not created earlier by some other process, even if - * the pid has been reused. */ - read_pipe = CreateNamedPipeA(pipename, - PIPE_ACCESS_INBOUND | - FILE_FLAG_FIRST_PIPE_INSTANCE | dwReadMode, - PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, - 1, /* max instances */ - psize, /* output buffer size */ - psize, /* input buffer size */ - NMPWAIT_USE_DEFAULT_WAIT, - sa_ptr); - - if (read_pipe != INVALID_HANDLE_VALUE) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p\n", read_pipe); - break; - } - - DWORD err = GetLastError(); - - switch (err) - { - case ERROR_PIPE_BUSY: - /* The pipe is already open with compatible parameters. - * Pick a new name and retry. */ - LOG(GNUNET_ERROR_TYPE_DEBUG, "pipe busy, retrying\n"); - continue; - - case ERROR_ACCESS_DENIED: - /* The pipe is already open with incompatible parameters. - * Pick a new name and retry. */ - LOG(GNUNET_ERROR_TYPE_DEBUG, "pipe access denied, retrying\n"); - continue; - - case ERROR_CALL_NOT_IMPLEMENTED: - /* We are on an older Win9x platform without named pipes. - * Return an anonymous pipe as the best approximation. */ - LOG(GNUNET_ERROR_TYPE_DEBUG, - "CreateNamedPipe not implemented, resorting to " - "CreatePipe: size = %lu\n", - psize); - if (CreatePipe(read_pipe_ptr, write_pipe_ptr, sa_ptr, psize)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "pipe read handle = %p, write handle = %p\n", - *read_pipe_ptr, - *write_pipe_ptr); - return GNUNET_OK; - } - err = GetLastError(); - LOG(GNUNET_ERROR_TYPE_ERROR, "CreatePipe failed: %d\n", err); - return err; - - default: - LOG(GNUNET_ERROR_TYPE_ERROR, "CreateNamedPipe failed: %d\n", err); - return err; - } - /* NOTREACHED */ - } - LOG(GNUNET_ERROR_TYPE_DEBUG, "CreateFile: name = %s\n", pipename); - - /* Open the named pipe for writing. - * Be sure to permit FILE_READ_ATTRIBUTES access. */ - write_pipe = CreateFileA(pipename, - GENERIC_WRITE | FILE_READ_ATTRIBUTES, - 0, /* share mode */ - sa_ptr, - OPEN_EXISTING, - dwWriteMode, /* flags and attributes */ - 0); /* handle to template file */ - - if (write_pipe == INVALID_HANDLE_VALUE) - { - /* Failure. */ - DWORD err = GetLastError(); - - LOG(GNUNET_ERROR_TYPE_DEBUG, "CreateFile failed: %d\n", err); - CloseHandle(read_pipe); - return err; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, "pipe write handle = %p\n", write_pipe); - /* Success. */ - *read_pipe_ptr = read_pipe; - *write_pipe_ptr = write_pipe; - return GNUNET_OK; -} -#endif - - /** * Creates an interprocess channel * @@ -2287,7 +1606,6 @@ GNUNET_DISK_pipe(int blocking_read, int inherit_read, int inherit_write) { -#ifndef MINGW int fd[2]; int ret; int eno; @@ -2303,99 +1621,6 @@ GNUNET_DISK_pipe(int blocking_read, return NULL; } return GNUNET_DISK_pipe_from_fd(blocking_read, blocking_write, fd); -#else - struct GNUNET_DISK_PipeHandle *p; - BOOL ret; - HANDLE tmp_handle; - int save_errno; - - p = GNUNET_new(struct GNUNET_DISK_PipeHandle); - p->fd[0] = GNUNET_new(struct GNUNET_DISK_FileHandle); - p->fd[1] = GNUNET_new(struct GNUNET_DISK_FileHandle); - - /* All pipes are overlapped. If you want them to block - just - * call WriteFile() and ReadFile() with NULL overlapped pointer. - * NOTE: calling with NULL overlapped pointer works only - * for pipes, and doesn't seem to be a documented feature. - * It will NOT work for files, because overlapped files need - * to read offsets from the overlapped structure, regardless. - * Pipes are not seekable, and need no offsets, which is - * probably why it works for them. - */ - ret = create_selectable_pipe(&p->fd[0]->h, - &p->fd[1]->h, - NULL, - 0, - FILE_FLAG_OVERLAPPED, - FILE_FLAG_OVERLAPPED); - if (!ret) - { - SetErrnoFromWinError(GetLastError()); - save_errno = errno; - GNUNET_free(p->fd[0]); - GNUNET_free(p->fd[1]); - GNUNET_free(p); - errno = save_errno; - return NULL; - } - if (!DuplicateHandle(GetCurrentProcess(), - p->fd[0]->h, - GetCurrentProcess(), - &tmp_handle, - 0, - inherit_read == GNUNET_YES ? TRUE : FALSE, - DUPLICATE_SAME_ACCESS)) - { - SetErrnoFromWinError(GetLastError()); - save_errno = errno; - CloseHandle(p->fd[0]->h); - CloseHandle(p->fd[1]->h); - GNUNET_free(p->fd[0]); - GNUNET_free(p->fd[1]); - GNUNET_free(p); - errno = save_errno; - return NULL; - } - CloseHandle(p->fd[0]->h); - p->fd[0]->h = tmp_handle; - - if (!DuplicateHandle(GetCurrentProcess(), - p->fd[1]->h, - GetCurrentProcess(), - &tmp_handle, - 0, - inherit_write == GNUNET_YES ? TRUE : FALSE, - DUPLICATE_SAME_ACCESS)) - { - SetErrnoFromWinError(GetLastError()); - save_errno = errno; - CloseHandle(p->fd[0]->h); - CloseHandle(p->fd[1]->h); - GNUNET_free(p->fd[0]); - GNUNET_free(p->fd[1]); - GNUNET_free(p); - errno = save_errno; - return NULL; - } - CloseHandle(p->fd[1]->h); - p->fd[1]->h = tmp_handle; - - p->fd[0]->type = GNUNET_DISK_HANLDE_TYPE_PIPE; - p->fd[1]->type = GNUNET_DISK_HANLDE_TYPE_PIPE; - - p->fd[0]->oOverlapRead = GNUNET_new(OVERLAPPED); - p->fd[0]->oOverlapWrite = GNUNET_new(OVERLAPPED); - p->fd[1]->oOverlapRead = GNUNET_new(OVERLAPPED); - p->fd[1]->oOverlapWrite = GNUNET_new(OVERLAPPED); - - p->fd[0]->oOverlapRead->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - p->fd[0]->oOverlapWrite->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - - p->fd[1]->oOverlapRead->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - p->fd[1]->oOverlapWrite->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - - return p; -#endif } @@ -2416,7 +1641,6 @@ GNUNET_DISK_pipe_from_fd(int blocking_read, int blocking_write, int fd[2]) p = GNUNET_new(struct GNUNET_DISK_PipeHandle); -#ifndef MINGW int ret; int flags; int eno = 0; /* make gcc happy */ @@ -2481,44 +1705,7 @@ GNUNET_DISK_pipe_from_fd(int blocking_read, int blocking_write, int fd[2]) errno = eno; return NULL; } -#else - if (fd[0] >= 0) - { - p->fd[0] = GNUNET_new(struct GNUNET_DISK_FileHandle); - p->fd[0]->h = (HANDLE)_get_osfhandle(fd[0]); - if (p->fd[0]->h != INVALID_HANDLE_VALUE) - { - p->fd[0]->type = GNUNET_DISK_HANLDE_TYPE_PIPE; - p->fd[0]->oOverlapRead = GNUNET_new(OVERLAPPED); - p->fd[0]->oOverlapWrite = GNUNET_new(OVERLAPPED); - p->fd[0]->oOverlapRead->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - p->fd[0]->oOverlapWrite->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - } - else - { - GNUNET_free(p->fd[0]); - p->fd[0] = NULL; - } - } - if (fd[1] >= 0) - { - p->fd[1] = GNUNET_new(struct GNUNET_DISK_FileHandle); - p->fd[1]->h = (HANDLE)_get_osfhandle(fd[1]); - if (p->fd[1]->h != INVALID_HANDLE_VALUE) - { - p->fd[1]->type = GNUNET_DISK_HANLDE_TYPE_PIPE; - p->fd[1]->oOverlapRead = GNUNET_new(OVERLAPPED); - p->fd[1]->oOverlapWrite = GNUNET_new(OVERLAPPED); - p->fd[1]->oOverlapRead->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - p->fd[1]->oOverlapWrite->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - } - else - { - GNUNET_free(p->fd[1]); - p->fd[1] = NULL; - } - } -#endif + return p; } @@ -2671,15 +1858,10 @@ GNUNET_DISK_internal_file_handle_(const struct GNUNET_DISK_FileHandle *fh, { if (NULL == fh) return GNUNET_SYSERR; -#ifdef MINGW - if (dst_len < sizeof(HANDLE)) - return GNUNET_SYSERR; - *((HANDLE *)dst) = fh->h; -#else + if (dst_len < sizeof(int)) return GNUNET_SYSERR; *((int *)dst) = fh->fd; -#endif return GNUNET_OK; } 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 @@ #include #endif #endif -#if WINDOWS -#include -#endif #include "gnunet_util_lib.h" @@ -65,11 +62,7 @@ GNUNET_DNSPARSER_check_label(const char *label) if (IDNA_SUCCESS != idna_to_ascii_8z(label, &output, IDNA_ALLOW_UNASSIGNED)) return GNUNET_SYSERR; slen = strlen(output); -#if WINDOWS - idn_free(output); -#else free(output); -#endif return (slen > 63) ? GNUNET_SYSERR : GNUNET_OK; } @@ -101,11 +94,7 @@ GNUNET_DNSPARSER_check_name(const char *name) if (IDNA_SUCCESS != idna_to_ascii_8z(name, &output, IDNA_ALLOW_UNASSIGNED)) return GNUNET_SYSERR; slen = strlen(output); -#if WINDOWS - idn_free(output); -#else free(output); -#endif return (slen > 253) ? GNUNET_SYSERR : GNUNET_OK; } @@ -276,11 +265,7 @@ parse_name(const char *udp_payload, { GNUNET_free(tmp); GNUNET_asprintf(&tmp, "%s%s.", ret, utf8); -#if WINDOWS - idn_free(utf8); -#else free(utf8); -#endif } GNUNET_free(ret); ret = tmp; @@ -954,18 +939,10 @@ GNUNET_DNSPARSER_builder_add_name(char *dst, while (NULL != dot); dst[pos++] = '\0'; /* terminator */ *off = pos; -#if WINDOWS - idn_free(idna_start); -#else free(idna_start); -#endif return GNUNET_OK; fail: -#if WINDOWS - idn_free(idna_start); -#else free(idna_start); -#endif return GNUNET_NO; } 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 @@ #define LOG_STRERROR(kind, syscall) \ GNUNET_log_from_strerror(kind, "util-getopt", syscall) -#if defined(WIN32) && !defined(__CYGWIN32__) -/* It's not Unix, really. See? Capital letters. */ -#include -#define getpid() GetCurrentProcessId() -#endif - #ifndef _ /* This is for other GNU distributions with internationalized messages. 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 @@ -/* - This file is part of GNUnet. - Copyright (C) 2014 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - SPDX-License-Identifier: AGPL3.0-or-later - */ - -/** - * @file src/util/gnunet-helper-w32-console.c - * @brief Does blocking reads from the console, writes the results - * into stdout, turning blocking console I/O into non-blocking - * pipe I/O. For W32 only. - * @author LRN - */ -#include "platform.h" -#include "gnunet_crypto_lib.h" -#include "gnunet_common.h" -#include "gnunet-helper-w32-console.h" - -static unsigned long buffer_size; - -static int chars; - -static HANDLE parent_handle; - -/** - * Write @a size bytes from @a buf into @a output. - * - * @param output the descriptor to write into - * @param buf buffer with data to write - * @param size number of bytes to write - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -static int -write_all(int output, - const void *buf, - size_t size) -{ - const char *cbuf = buf; - size_t total; - ssize_t wr; - - total = 0; - do - { - wr = write(output, - &cbuf[total], - size - total); - if (wr > 0) - total += wr; - } - while ((wr > 0) && (total < size)); - if (wr <= 0) - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Failed to write to stdout: %s\n", - strerror(errno)); - return (total == size) ? GNUNET_OK : GNUNET_SYSERR; -} - - -/** - * Write message to the master process. - * - * @param output the descriptor to write into - * @param message_type message type to use - * @param data data to append, NULL for none - * @param data_length number of bytes in @a data - * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow) - */ -static int -write_message(int output, - uint16_t message_type, - const char *data, - size_t data_length) -{ - struct GNUNET_MessageHeader hdr; - -#if 0 - fprintf(stderr, - "Helper sends %u-byte message of type %u\n", - (unsigned int)(sizeof(struct GNUNET_MessageHeader) + data_length), - (unsigned int)message_type); -#endif - hdr.type = htons(message_type); - hdr.size = htons(sizeof(struct GNUNET_MessageHeader) + data_length); - if (GNUNET_OK != write_all(output, &hdr, sizeof(hdr))) - return GNUNET_SYSERR; - if (GNUNET_OK != write_all(output, data, data_length)) - return GNUNET_SYSERR; - return GNUNET_OK; -} - - -/** - * Main function of the helper process. Reads input events from console, - * writes messages, into stdout. - * - * @param console a handle to a console to read from - * @param output_stream a stream to write messages to - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -static int -read_events(HANDLE console, int output_stream) -{ - DWORD rr; - BOOL b; - INPUT_RECORD *buf; - DWORD i; - int result; - - result = GNUNET_SYSERR; - buf = malloc(sizeof(INPUT_RECORD) * buffer_size); - if (NULL == buf) - return result; - b = TRUE; - rr = 1; - while (TRUE == b && 0 < rr) - { - rr = 0; - b = ReadConsoleInput(console, buf, buffer_size, &rr); - if (FALSE == b && ERROR_SUCCESS != GetLastError()) - break; - for (i = 0; i < rr; i++) - { - int r; - r = write_message(output_stream, - GNUNET_MESSAGE_TYPE_W32_CONSOLE_HELPER_INPUT, - (const char *)&buf[i], - sizeof(INPUT_RECORD)); - if (GNUNET_OK != r) - break; - } - if (rr + 1 != i) - break; - } - return result; -} - - -/** - * Main function of the helper process. Reads chars from console, - * writes messages, into stdout. - * - * @param console a handle to a console to read from - * @param output_stream a stream to write messages to - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -static int -read_chars(HANDLE console, int output_stream) -{ - DWORD rr; - BOOL b; - wchar_t *buf; - char *small_ubuf; - char *large_ubuf; - char *ubuf; - int conv; - int r; - int result; - - result = GNUNET_SYSERR; - buf = malloc(sizeof(wchar_t) * buffer_size); - if (NULL == buf) - return result; - small_ubuf = malloc(sizeof(char) * buffer_size * 2); - if (NULL == small_ubuf) - { - free(buf); - return result; - } - b = TRUE; - rr = 1; - while (TRUE == b) - { - large_ubuf = NULL; - rr = 0; - b = ReadConsoleW(console, buf, buffer_size, &rr, NULL); - if (FALSE == b && ERROR_SUCCESS != GetLastError()) - break; - if (0 == rr) - continue; - /* Caveat: if the UTF-16-encoded string is longer than BUFFER_SIZE, - * there's a possibility that we will read up to a word that constitutes - * a part of a multi-byte UTF-16 codepoint. Converting that to UTF-8 - * will either drop invalid word (flags == 0) or bail out because of it - * (flags == WC_ERR_INVALID_CHARS). - */ - conv = WideCharToMultiByte(CP_UTF8, 0, buf, rr, small_ubuf, 0, NULL, FALSE); - if (0 == conv || 0xFFFD == conv) - continue; - if (conv <= buffer_size * 2 - 1) - { - memset(small_ubuf, 0, buffer_size * 2); - conv = WideCharToMultiByte(CP_UTF8, 0, buf, rr, small_ubuf, buffer_size * 2 - 1, NULL, FALSE); - if (0 == conv || 0xFFFD == conv) - continue; - ubuf = small_ubuf; - } - else - { - large_ubuf = malloc(conv + 1); - if (NULL == large_ubuf) - continue; - memset(large_ubuf, 0, conv + 1); - conv = WideCharToMultiByte(CP_UTF8, 0, buf, rr, large_ubuf, conv, NULL, FALSE); - if (0 == conv || 0xFFFD == conv) - { - free(large_ubuf); - large_ubuf = NULL; - continue; - } - ubuf = large_ubuf; - } - r = write_message(output_stream, - GNUNET_MESSAGE_TYPE_W32_CONSOLE_HELPER_CHARS, - ubuf, - conv + 1); - if (large_ubuf) - free(large_ubuf); - if (GNUNET_OK != r) - break; - } - free(small_ubuf); - free(buf); - return result; -} - - -DWORD WINAPI -watch_parent(LPVOID param) -{ - WaitForSingleObject(parent_handle, INFINITE); - ExitProcess(1); - return 0; -} - -/** - * Main function of the helper process to extract meta data. - * - * @param argc should be 3 - * @param argv [0] our binary name - * [1] name of the file or directory to process - * [2] "-" to disable extraction, NULL for defaults, - * otherwise custom plugins to load from LE - * @return 0 on success - */ -int -main(int argc, - char *const *argv) -{ - HANDLE os_stdin; - DWORD parent_pid; - - /* We're using stdout to communicate binary data back to the parent; use - * binary mode. - */ - _setmode(1, _O_BINARY); - - if (argc != 4) - { - fprintf(stderr, - "Usage: gnunet-helper-w32-console \n"); - return 2; - } - - if (0 == strcmp(argv[1], "chars")) - chars = GNUNET_YES; - else if (0 == strcmp(argv[1], "events")) - chars = GNUNET_NO; - else - return 3; - - buffer_size = strtoul(argv[2], NULL, 10); - if (buffer_size <= 0) - return 4; - - parent_pid = (DWORD)strtoul(argv[3], NULL, 10); - if (parent_pid == 0) - return 5; - parent_handle = OpenProcess(SYNCHRONIZE, FALSE, parent_pid); - if (NULL == parent_handle) - return 6; - - CreateThread(NULL, 0, watch_parent, NULL, 0, NULL); - - if (0 == AttachConsole(ATTACH_PARENT_PROCESS)) - { - if (ERROR_ACCESS_DENIED != GetLastError()) - return 5; - } - - /* Helper API overrides stdin, so we just attach to the console that we - * inherited. If we did. - */ - os_stdin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0); - if (INVALID_HANDLE_VALUE == os_stdin) - return 1; - - if (GNUNET_NO == chars) - return read_events(os_stdin, 1); - else - return read_chars(os_stdin, 1); -} - -/* 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 @@ -/* - This file is part of GNUnet. - Copyright (C) 2014 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - SPDX-License-Identifier: AGPL3.0-or-later - */ - -/** - * @author LRN - * @file src/util/gnunet-helper-w32-console.h - */ -#ifndef GNUNET_HELPER_W32_CONSOLE_H -#define GNUNET_HELPER_W32_CONSOLE_H - -#include "platform.h" -#include "gnunet_crypto_lib.h" -#include "gnunet_common.h" - -/** - * Input event from the console - */ -#define GNUNET_MESSAGE_TYPE_W32_CONSOLE_HELPER_INPUT 60000 - -/** - * Chars from the console - */ -#define GNUNET_MESSAGE_TYPE_W32_CONSOLE_HELPER_CHARS 60001 - -GNUNET_NETWORK_STRUCT_BEGIN - -/** - * This is just a dump of the INPUT_RECORD structure. - */ -struct GNUNET_W32_CONSOLE_input { - /** - * Type: GNUNET_MESSAGE_TYPE_W32_CONSOLE_HELPER_INPUT - */ - struct GNUNET_MessageHeader header; - - INPUT_RECORD input_record GNUNET_PACKED; -}; - -/** - * A header, followed by UTF8-encoded, 0-terminated string - */ -struct GNUNET_W32_CONSOLE_chars { - /** - * Type: GNUNET_MESSAGE_TYPE_W32_CONSOLE_HELPER_CHARS - */ - struct GNUNET_MessageHeader header; - - /* followed by a string */ -}; - -GNUNET_NETWORK_STRUCT_END - -#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 @@ * @brief handle to a socket */ struct GNUNET_NETWORK_Handle { -#ifndef MINGW int fd; -#else - _win_socket fd; -#endif /** * Address family / domain. @@ -119,11 +115,7 @@ GNUNET_NETWORK_test_pf(int pf) } else { -#if WINDOWS - closesocket(s); -#else close(s); -#endif ret = GNUNET_OK; } switch (pf) @@ -189,7 +181,6 @@ GNUNET_NETWORK_shorten_unixpath(char *unixpath) } -#ifndef WINDOWS /** * If services crash, they can leave a unix domain socket file on the * disk. This needs to be manually removed, because otherwise both @@ -238,8 +229,6 @@ GNUNET_NETWORK_unix_precheck(const struct sockaddr_un *un) "unlink", un->sun_path); } -#endif - #ifndef FD_COPY @@ -258,24 +247,6 @@ int GNUNET_NETWORK_socket_set_blocking(struct GNUNET_NETWORK_Handle *fd, int doBlock) { -#if MINGW - u_long mode; - - mode = !doBlock; - if (SOCKET_ERROR == - ioctlsocket(fd->fd, - FIONBIO, - &mode)) - - { - SetErrnoFromWinsockError(WSAGetLastError()); - LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, - "ioctlsocket"); - return GNUNET_SYSERR; - } - return GNUNET_OK; -#else - /* not MINGW */ int flags = fcntl(fd->fd, F_GETFL); if (flags == -1) @@ -299,7 +270,6 @@ GNUNET_NETWORK_socket_set_blocking(struct GNUNET_NETWORK_Handle *fd, return GNUNET_SYSERR; } return GNUNET_OK; -#endif } @@ -313,7 +283,6 @@ GNUNET_NETWORK_socket_set_blocking(struct GNUNET_NETWORK_Handle *fd, static int socket_set_inheritable(const struct GNUNET_NETWORK_Handle *h) { -#ifndef MINGW int i; i = fcntl(h->fd, F_GETFD); if (i < 0) @@ -323,16 +292,7 @@ socket_set_inheritable(const struct GNUNET_NETWORK_Handle *h) i |= FD_CLOEXEC; if (fcntl(h->fd, F_SETFD, i) < 0) return GNUNET_SYSERR; -#else - BOOL b; - SetLastError(0); - b = SetHandleInformation((HANDLE)h->fd, HANDLE_FLAG_INHERIT, 0); - if (!b) - { - SetErrnoFromWinsockError(WSAGetLastError()); - return GNUNET_SYSERR; - } -#endif + return GNUNET_OK; } @@ -368,7 +328,6 @@ socket_set_nosigpipe(const struct GNUNET_NETWORK_Handle *h) static void socket_set_nodelay(const struct GNUNET_NETWORK_Handle *h) { -#ifndef WINDOWS int value = 1; if (0 != @@ -378,18 +337,6 @@ socket_set_nodelay(const struct GNUNET_NETWORK_Handle *h) &value, sizeof(value))) LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "setsockopt"); -#else - const char *abs_value = "1"; - - if (0 != - setsockopt(h->fd, - IPPROTO_TCP, - TCP_NODELAY, - (const void *)abs_value, - sizeof(abs_value))) - LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, - "setsockopt"); -#endif } @@ -416,22 +363,19 @@ initialize_network_handle(struct GNUNET_NETWORK_Handle *h, h->type = type; if (h->fd == INVALID_SOCKET) { -#ifdef MINGW - SetErrnoFromWinsockError(WSAGetLastError()); -#endif eno = errno; GNUNET_free(h); errno = eno; return GNUNET_SYSERR; } -#ifndef MINGW + if (h->fd >= FD_SETSIZE) { GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(h)); errno = EMFILE; return GNUNET_SYSERR; } -#endif + if (GNUNET_OK != socket_set_inheritable(h)) LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "socket_set_inheritable"); @@ -549,7 +493,6 @@ GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, } #endif #endif -#ifndef WINDOWS if (AF_UNIX == address->sa_family) GNUNET_NETWORK_unix_precheck((const struct sockaddr_un *)address); { @@ -576,28 +519,21 @@ GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, not_abstract = 1; if (not_abstract) old_mask = umask(S_IWGRP | S_IRGRP | S_IXGRP | S_IWOTH | S_IROTH | S_IXOTH); -#endif ret = bind(desc->fd, address, address_len); -#ifndef WINDOWS if (not_abstract) (void)umask(old_mask); } -#endif -#ifdef MINGW - if (SOCKET_ERROR == ret) - SetErrnoFromWinsockError(WSAGetLastError()); -#endif if (0 != ret) return GNUNET_SYSERR; -#ifndef MINGW + desc->addr = GNUNET_malloc(address_len); GNUNET_memcpy(desc->addr, address, address_len); desc->addrlen = address_len; -#endif + return GNUNET_OK; } @@ -613,22 +549,8 @@ GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc) { int ret; -#ifdef WINDOWS - DWORD error = 0; - - SetLastError(0); - ret = closesocket(desc->fd); - error = WSAGetLastError(); - SetErrnoFromWinsockError(error); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Closed 0x%x, closesocket() returned %d, GLE is %u\n", - desc->fd, - ret, - error); -#else ret = close(desc->fd); -#endif -#ifndef WINDOWS + const struct sockaddr_un *un = (const struct sockaddr_un *)desc->addr; /* 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) } GNUNET_free(dirname); } -#endif GNUNET_NETWORK_socket_free_memory_only_(desc); return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR; } @@ -704,28 +625,12 @@ GNUNET_NETWORK_socket_box_native(SOCKTYPE fd) { struct GNUNET_NETWORK_Handle *ret; -#if MINGW - unsigned long i; - DWORD d; - /* FIXME: Find a better call to check that FD is valid */ - if (0 != - WSAIoctl(fd, FIONBIO, - (void *)&i, sizeof(i), - NULL, 0, &d, - NULL, NULL)) - return NULL; /* invalid FD */ - ret = GNUNET_new(struct GNUNET_NETWORK_Handle); - ret->fd = fd; - ret->af = AF_UNSPEC; - return ret; -#else if (fcntl(fd, F_GETFD) < 0) return NULL; /* invalid FD */ ret = GNUNET_new(struct GNUNET_NETWORK_Handle); ret->fd = fd; ret->af = AF_UNSPEC; return ret; -#endif } @@ -747,14 +652,7 @@ GNUNET_NETWORK_socket_connect(const struct GNUNET_NETWORK_Handle *desc, ret = connect(desc->fd, address, address_len); -#ifdef MINGW - if (SOCKET_ERROR == ret) - { - SetErrnoFromWinsockError(WSAGetLastError()); - if (errno == EWOULDBLOCK) - errno = EINPROGRESS; - } -#endif + return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; } @@ -783,14 +681,6 @@ GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Handle *desc, optname, optval, optlen); -#ifdef MINGW - if ((0 == ret) && - (SOL_SOCKET == level) && - (SO_ERROR == optname)) - *((int *)optval) = GetErrnoFromWinsockError(*((int *)optval)); - else if (SOCKET_ERROR == ret) - SetErrnoFromWinsockError(WSAGetLastError()); -#endif return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; } @@ -810,10 +700,7 @@ GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, ret = listen(desc->fd, backlog); -#ifdef MINGW - if (SOCKET_ERROR == ret) - SetErrnoFromWinsockError(WSAGetLastError()); -#endif + return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; } @@ -830,7 +717,6 @@ GNUNET_NETWORK_socket_recvfrom_amount(const struct GNUNET_NETWORK_Handle *desc) int error; /* How much is there to be read? */ -#ifndef WINDOWS int pending; error = ioctl(desc->fd, @@ -839,16 +725,6 @@ GNUNET_NETWORK_socket_recvfrom_amount(const struct GNUNET_NETWORK_Handle *desc) if (0 == error) return (ssize_t)pending; return GNUNET_SYSERR; -#else - u_long pending; - - error = ioctlsocket(desc->fd, - FIONREAD, - &pending); - if (error != SOCKET_ERROR) - return (ssize_t)pending; - return GNUNET_SYSERR; -#endif } @@ -1096,28 +972,7 @@ GNUNET_NETWORK_socket_disable_corking(struct GNUNET_NETWORK_Handle *desc) { int ret = 0; -#if WINDOWS - int value = 0; - - if (0 != - (ret = - setsockopt(desc->fd, - SOL_SOCKET, - SO_SNDBUF, - (char *)&value, - sizeof(value)))) - LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, - "setsockopt"); - if (0 != - (ret = - setsockopt(desc->fd, - SOL_SOCKET, - SO_RCVBUF, - (char *)&value, - sizeof(value)))) - LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, - "setsockopt"); -#elif LINUX +#if LINUX int value = 0; if (0 != @@ -1153,9 +1008,6 @@ GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds) { FD_ZERO(&fds->sds); fds->nsds = 0; -#ifdef MINGW - fds->handles_pos = 0; -#endif } 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 @@ #if DARWIN #include #include -#elif WINDOWS -#include #endif @@ -212,124 +210,6 @@ get_path_from_proc_exe() #endif -#if WINDOWS -static HINSTANCE dll_instance; - - -/** - * GNUNET_util_cl_init() in common_logging.c is preferred. - * This function is only for thread-local storage (not used in GNUnet) - * and hInstance saving. - */ -BOOL WINAPI -DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) -{ - switch (fdwReason) - { - case DLL_PROCESS_ATTACH: - dll_instance = hinstDLL; - break; - - case DLL_THREAD_ATTACH: - break; - - case DLL_THREAD_DETACH: - break; - - case DLL_PROCESS_DETACH: - break; - } - return TRUE; -} - - -/** - * Try to determine path with win32-specific function - * - * @return NULL on error - */ -static char * -get_path_from_module_filename() -{ - size_t pathlen = 512; - DWORD real_pathlen; - wchar_t *idx; - wchar_t *modulepath = NULL; - char *upath; - uint8_t *u8_string; - size_t u8_string_length; - - /* This braindead function won't tell us how much space it needs, so - * we start at 1024 and double the space up if it doesn't fit, until - * it fits, or we exceed the threshold. - */ - do - { - pathlen = pathlen * 2; - modulepath = GNUNET_realloc(modulepath, pathlen * sizeof(wchar_t)); - SetLastError(0); - real_pathlen = - GetModuleFileNameW(dll_instance, modulepath, pathlen * sizeof(wchar_t)); - } - while (real_pathlen >= pathlen && pathlen < 16 * 1024); - if (real_pathlen >= pathlen) - GNUNET_assert(0); - /* To be safe */ - modulepath[real_pathlen] = '\0'; - - idx = modulepath + real_pathlen; - while ((idx > modulepath) && (*idx != L'\\') && (*idx != L'/')) - idx--; - *idx = L'\0'; - - /* Now modulepath holds full path to the directory where libgnunetutil is. - * This directory should look like /bin or . - */ - if (wcschr(modulepath, L'/') || wcschr(modulepath, L'\\')) - { - /* At least one directory component (i.e. we're not in a root directory) */ - wchar_t *dirname = idx; - while ((dirname > modulepath) && (*dirname != L'\\') && (*dirname != L'/')) - dirname--; - *dirname = L'\0'; - if (dirname > modulepath) - { - dirname++; - /* Now modulepath holds full path to the parent directory of the directory - * where libgnunetutil is. - * dirname holds the name of the directory where libgnunetutil is. - */ - if (wcsicmp(dirname, L"bin") == 0) - { - /* pass */ - } - else - { - /* Roll back our changes to modulepath */ - dirname--; - *dirname = L'/'; - } - } - } - - /* modulepath is GNUNET_PREFIX */ - u8_string = - u16_to_u8(modulepath, wcslen(modulepath), NULL, &u8_string_length); - if (NULL == u8_string) - GNUNET_assert(0); - - upath = GNUNET_malloc(u8_string_length + 1); - GNUNET_memcpy(upath, u8_string, u8_string_length); - upath[u8_string_length] = '\0'; - - free(u8_string); - GNUNET_free(modulepath); - - return upath; -} -#endif - - #if DARWIN /** * Signature of the '_NSGetExecutablePath" function. @@ -433,12 +313,9 @@ get_path_from_PATH(const char *binary) if (NULL == (p = getenv("PATH"))) return NULL; -#if WINDOWS - /* On W32 look in CWD first. */ - GNUNET_asprintf(&path, ".%c%s", PATH_SEPARATOR, p); -#else + path = GNUNET_strdup(p); /* because we write on it */ -#endif + buf = GNUNET_malloc(strlen(path) + strlen(binary) + 1 + 1); pos = path; while (NULL != (end = strchr(pos, PATH_SEPARATOR))) @@ -512,10 +389,6 @@ os_get_gnunet_path() if (NULL != (ret = get_path_from_proc_exe())) return ret; #endif -#if WINDOWS - if (NULL != (ret = get_path_from_module_filename())) - return ret; -#endif #if DARWIN if (NULL != (ret = get_path_from_dyld_image())) return ret; @@ -548,10 +421,6 @@ os_get_exec_path() if (NULL != (ret = get_path_from_proc_exe())) return ret; #endif -#if WINDOWS - if (NULL != (ret = get_path_from_module_filename())) - return ret; -#endif #if DARWIN if (NULL != (ret = get_path_from_NSGetExecutablePath())) 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 { */ pid_t pid; -#if WINDOWS - /** - * Process handle. - */ - HANDLE handle; -#endif /** * Pipe we use to signal the process. @@ -174,12 +168,7 @@ GNUNET_OS_install_parent_control_handler(void *cls) putenv(GNUNET_OS_CONTROL_PIPE "="); return; } -#if !defined(WINDOWS) if (pipe_fd >= FD_SETSIZE) -#else - if ((FILE_TYPE_UNKNOWN == GetFileType((HANDLE)(uintptr_t)pipe_fd)) && - (0 != GetLastError())) -#endif { LOG(GNUNET_ERROR_TYPE_ERROR, "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n", @@ -187,12 +176,9 @@ GNUNET_OS_install_parent_control_handler(void *cls) putenv(GNUNET_OS_CONTROL_PIPE "="); return; } -#if WINDOWS - control_pipe = - GNUNET_DISK_get_handle_from_w32_handle((HANDLE)(uintptr_t)pipe_fd); -#else + control_pipe = GNUNET_DISK_get_handle_from_int_fd((int)pipe_fd); -#endif + if (NULL == control_pipe) { LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "open", env_buf); @@ -222,12 +208,7 @@ GNUNET_OS_install_parent_control_handler(void *cls) struct GNUNET_OS_Process * GNUNET_OS_process_current() { -#if WINDOWS - current_process.pid = GetCurrentProcessId(); - current_process.handle = GetCurrentProcess(); -#else current_process.pid = 0; -#endif return ¤t_process; } @@ -259,72 +240,24 @@ GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig) /* pipe failed or non-existent, try other methods */ switch (sig) { -#if !defined(WINDOWS) case SIGHUP: -#endif case SIGINT: case SIGKILL: case SIGTERM: #if (SIGTERM != GNUNET_TERM_SIG) case GNUNET_TERM_SIG: #endif -#if defined(WINDOWS) && !defined(__CYGWIN__) - { - DWORD exitcode; - int must_kill = GNUNET_YES; - if (0 != GetExitCodeProcess(proc->handle, &exitcode)) - must_kill = (exitcode == STILL_ACTIVE) ? GNUNET_YES : GNUNET_NO; - if (GNUNET_YES == must_kill) - { - if (0 == SafeTerminateProcess(proc->handle, 0, 0)) - { - DWORD error_code = GetLastError(); - if ((error_code != WAIT_TIMEOUT) && - (error_code != ERROR_PROCESS_ABORTED)) - { - LOG((error_code == ERROR_ACCESS_DENIED) ? GNUNET_ERROR_TYPE_INFO - : GNUNET_ERROR_TYPE_WARNING, - "SafeTermiateProcess failed with code %lu\n", - error_code); - /* The problem here is that a process that is already dying - * might cause SafeTerminateProcess to fail with - * ERROR_ACCESS_DENIED, but the process WILL die eventually. - * If we really had a permissions problem, hanging up (which - * is what will happen in process_wait() in that case) is - * a valid option. - */ - if (ERROR_ACCESS_DENIED == error_code) - { - errno = 0; - } - else - { - SetErrnoFromWinError(error_code); - return -1; - } - } - } - } - } - return 0; -#else LOG(GNUNET_ERROR_TYPE_DEBUG, "Sending signal %d to pid: %u via system call\n", sig, proc->pid); return kill(proc->pid, sig); -#endif default: -#if defined(WINDOWS) - errno = EINVAL; - return -1; -#else LOG(GNUNET_ERROR_TYPE_DEBUG, "Sending signal %d to pid: %u via system call\n", sig, proc->pid); return kill(proc->pid, sig); -#endif } } @@ -354,152 +287,11 @@ GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc) { if (NULL != proc->control_pipe) GNUNET_DISK_file_close(proc->control_pipe); -#if defined(WINDOWS) - if (NULL != proc->handle) - CloseHandle(proc->handle); -#endif + GNUNET_free(proc); } -#if WINDOWS -#include "gnunet_signal_lib.h" - -extern GNUNET_SIGNAL_Handler w32_sigchld_handler; - -/** - * Make seaspider happy. - */ -#define DWORD_WINAPI DWORD WINAPI - - -/** - * @brief Waits for a process to terminate and invokes the SIGCHLD handler - * @param proc pointer to process structure - */ -static DWORD_WINAPI -child_wait_thread(void *arg) -{ - struct GNUNET_OS_Process *proc = (struct GNUNET_OS_Process *)arg; - - WaitForSingleObject(proc->handle, INFINITE); - - if (w32_sigchld_handler) - w32_sigchld_handler(); - - return 0; -} -#endif - - -#if MINGW -static char * -CreateCustomEnvTable(char **vars) -{ - char *win32_env_table; - char *ptr; - char **var_ptr; - char *result; - char *result_ptr; - size_t tablesize = 0; - size_t items_count = 0; - size_t n_found = 0; - size_t n_var; - char *index = NULL; - size_t c; - size_t var_len; - char *var; - char *val; - - win32_env_table = GetEnvironmentStringsA(); - if (NULL == win32_env_table) - return NULL; - for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++) - ; - n_var = c; - index = GNUNET_malloc(sizeof(char *) * n_var); - for (c = 0; c < n_var; c++) - index[c] = 0; - for (items_count = 0, ptr = win32_env_table; ptr[0] != 0; items_count++) - { - size_t len = strlen(ptr); - int found = 0; - - for (var_ptr = vars; *var_ptr; var_ptr++) - { - var = *var_ptr++; - val = *var_ptr; - var_len = strlen(var); - if (strncmp(var, ptr, var_len) == 0) - { - found = 1; - index[c] = 1; - tablesize += var_len + strlen(val) + 1; - break; - } - } - if (!found) - tablesize += len + 1; - ptr += len + 1; - } - for (n_found = 0, c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++) - { - var = *var_ptr++; - val = *var_ptr; - if (index[c] != 1) - n_found += strlen(var) + strlen(val) + 1; - } - result = GNUNET_malloc(tablesize + n_found + 1); - for (result_ptr = result, ptr = win32_env_table; ptr[0] != 0;) - { - size_t len = strlen(ptr); - int found = 0; - - for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++) - { - var = *var_ptr++; - val = *var_ptr; - var_len = strlen(var); - if (strncmp(var, ptr, var_len) == 0) - { - found = 1; - break; - } - } - if (!found) - { - strcpy(result_ptr, ptr); - result_ptr += len + 1; - } - else - { - strcpy(result_ptr, var); - result_ptr += var_len; - strcpy(result_ptr, val); - result_ptr += strlen(val) + 1; - } - ptr += len + 1; - } - for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++) - { - var = *var_ptr++; - val = *var_ptr; - var_len = strlen(var); - if (index[c] != 1) - { - strcpy(result_ptr, var); - result_ptr += var_len; - strcpy(result_ptr, val); - result_ptr += strlen(val) + 1; - } - } - FreeEnvironmentStrings(win32_env_table); - GNUNET_free(index); - *result_ptr = 0; - return result; -} - -#else /** * Open '/dev/null' and make the result the given @@ -529,7 +321,6 @@ open_dev_null(int target_fd, int flags) } GNUNET_break(0 == close(fd)); } -#endif /** 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) (!check_ipv6_listed(sh->v6_denied, &v6->sin6_addr)))); break; -#ifndef WINDOWS case AF_UNIX: ok = GNUNET_OK; /* controlled using file-system ACL now */ break; -#endif + default: LOG(GNUNET_ERROR_TYPE_WARNING, _("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 { GNUNET_SIGNAL_Handler method; -#ifndef MINGW struct sigaction oldsig; -#endif }; static struct GNUNET_SIGNAL_Context *sc_head; static struct GNUNET_SIGNAL_Context *sc_tail; - -#ifdef WINDOWS -GNUNET_SIGNAL_Handler w32_sigchld_handler = NULL; -#endif - struct GNUNET_SIGNAL_Context * GNUNET_SIGNAL_handler_install(int signum, GNUNET_SIGNAL_Handler handler) { struct GNUNET_SIGNAL_Context *ret; -#ifndef MINGW struct sigaction sig; -#endif ret = GNUNET_new(struct GNUNET_SIGNAL_Context); ret->sig = signum; ret->method = handler; -#ifndef MINGW + memset(&sig, 0, sizeof(sig)); sig.sa_handler = (void *)handler; sigemptyset(&sig.sa_mask); @@ -75,20 +66,7 @@ GNUNET_SIGNAL_handler_install(int signum, GNUNET_SIGNAL_Handler handler) sig.sa_flags = SA_RESTART; #endif sigaction(signum, &sig, &ret->oldsig); -#else - if (signum == GNUNET_SIGCHLD) - w32_sigchld_handler = handler; - else - { - __p_sig_fn_t sigret = signal(signum, (__p_sig_fn_t)handler); - if (sigret == SIG_ERR) - { - LOG(GNUNET_ERROR_TYPE_WARNING, _("signal (%d, %p) returned %d.\n"), - signum, handler, sigret); - } - } -#endif GNUNET_CONTAINER_DLL_insert_tail(sc_head, sc_tail, ret); return ret; } @@ -96,12 +74,11 @@ GNUNET_SIGNAL_handler_install(int signum, GNUNET_SIGNAL_Handler handler) void GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx) { -#ifndef MINGW struct sigaction sig; sigemptyset(&sig.sa_mask); sigaction(ctx->sig, &ctx->oldsig, &sig); -#endif + GNUNET_CONTAINER_DLL_remove(sc_head, sc_tail, ctx); GNUNET_free(ctx); } 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) * (otherwise we'd have to detect current codepage or use W32API character * set conversion routines to convert to UTF8). */ -#ifndef WINDOWS + strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Y", tp); -#else - { - static wchar_t wbuf[255]; - uint8_t *conved; - size_t ssize; - - wcsftime(wbuf, - sizeof(wbuf) / sizeof(wchar_t), - L"%a %b %d %H:%M:%S %Y", - tp); - - ssize = sizeof(buf); - conved = u16_to_u8(wbuf, - sizeof(wbuf) / sizeof(wchar_t), - (uint8_t *)buf, - &ssize); - if (conved != (uint8_t *)buf) - { - GNUNET_strlcpy(buf, (char *)conved, sizeof(buf)); - free(conved); - } - } -#endif + return buf; } @@ -1168,9 +1146,6 @@ GNUNET_STRINGS_path_is_absolute(const char *filename, int *r_is_uri, char **r_uri_scheme) { -#if WINDOWS - size_t len; -#endif const char *post_scheme_path; int is_uri; char *uri; @@ -1190,14 +1165,7 @@ GNUNET_STRINGS_path_is_absolute(const char *filename, *r_uri_scheme = uri; else GNUNET_free_non_null(uri); -#if WINDOWS - len = strlen(post_scheme_path); - /* Special check for file:///c:/blah - * We want to parse 'c:/', not '/c:/' - */ - if (post_scheme_path[0] == '/' && len >= 3 && post_scheme_path[2] == ':') - post_scheme_path = &post_scheme_path[1]; -#endif + return GNUNET_STRINGS_path_is_absolute(post_scheme_path, GNUNET_NO, NULL, @@ -1209,23 +1177,10 @@ GNUNET_STRINGS_path_is_absolute(const char *filename, if (r_is_uri) *r_is_uri = GNUNET_NO; } -#if WINDOWS - len = strlen(filename); - if (len >= 3 && - ((filename[0] >= 'A' && filename[0] <= 'Z') || - (filename[0] >= 'a' && filename[0] <= 'z')) && - filename[1] == ':' && (filename[2] == '/' || filename[2] == '\\')) - return GNUNET_YES; -#endif + return GNUNET_NO; } -#if MINGW -#define _IFMT 0170000 /* type of file */ -#define _IFLNK 0120000 /* symbolic link */ -#define S_ISLNK(m) (((m) & _IFMT) == _IFLNK) -#endif - /** * Perform @a checks on @a filename. @@ -1521,53 +1476,11 @@ GNUNET_STRINGS_get_utf8_args(int argc, int *u8argc, char *const **u8argv) { -#if WINDOWS - wchar_t *wcmd; - wchar_t **wargv; - int wargc; - int i; - char **split_u8argv; - - wcmd = GetCommandLineW(); - if (NULL == wcmd) - return GNUNET_SYSERR; - wargv = CommandLineToArgvW(wcmd, &wargc); - if (NULL == wargv) - return GNUNET_SYSERR; - - split_u8argv = GNUNET_malloc(argc * sizeof(char *)); - - for (i = 0; i < wargc; i++) - { - size_t strl; - /* Hopefully it will allocate us NUL-terminated strings... */ - split_u8argv[i] = - (char *)u16_to_u8(wargv[i], wcslen(wargv[i]) + 1, NULL, &strl); - if (NULL == split_u8argv[i]) - { - int j; - for (j = 0; j < i; j++) - free(split_u8argv[j]); - GNUNET_free(split_u8argv); - LocalFree(wargv); - return GNUNET_SYSERR; - } - } - - *u8argv = _make_continuous_arg_copy(wargc, split_u8argv); - *u8argc = wargc; - - for (i = 0; i < wargc; i++) - free(split_u8argv[i]); - free(split_u8argv); - return GNUNET_OK; -#else char *const *new_argv = (char *const *)_make_continuous_arg_copy(argc, argv); *u8argv = new_argv; *u8argc = argc; return GNUNET_OK; -#endif } 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, case 2: /* read the delay, finished by '\n' */ t[j++] = r[i]; -#if WINDOWS - if (r[i] == '\r' && r[i + 1] == '\n') - { - i += 1; - t[j - 1] = '\0'; - *delay = strtol(t, NULL, 10); - stop = 1; - } -#else if (r[i] == '\n') { t[j - 1] = '\0'; *delay = strtol(t, NULL, 10); stop = 1; } -#endif break; } } 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() static int testChangeOwner() { -#ifndef WINDOWS GNUNET_log_skip(1, GNUNET_NO); if (GNUNET_OK == GNUNET_DISK_file_change_owner("/dev/null", "unknownuser")) return 1; -#endif return 0; } 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) const struct GNUNET_DISK_FileHandle *stdout_read_handle; const struct GNUNET_DISK_FileHandle *wh; -#if !WINDOWS GNUNET_asprintf(&fn, "cat"); -#else - GNUNET_asprintf(&fn, "w32cat"); -#endif hello_pipe_stdin = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); 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[]) if (atx.abs_value_us != at.abs_value_us) { -#ifdef WINDOWS - DWORD tzv; - TIME_ZONE_INFORMATION tzi; - tzv = GetTimeZoneInformation(&tzi); - if (TIME_ZONE_ID_INVALID != tzv) - { - atx.abs_value_us -= 1000LL * 1000LL * tzi.Bias * 60LL; - } - if (atx.abs_value_us == at.abs_value_us) - fprintf(stderr, - "WARNING: GNUNET_STRINGS_fancy_time_to_absolute() miscalculates timezone!\n"); -#endif GNUNET_assert(0); } -- cgit v1.2.3