-Fri Sep 6 00:00:00 UTC 2019
+Mon Sep 9 00:00:00 UTC 2019
+ Drop win32 and mingw support after discussion with
+ Christian. It has been unmaintained in out code base
+ for years and there are no known users.
+ Future implementors for Windows 10 support can
+ refer to this commit as reference. -ng0
+
+Mon Sep 9 00:00:00 UTC 2019
Remove plibc, closes #5877 as discussed in
https://lists.gnu.org/archive/html/gnunet-developers/2019-09/msg00002.html
-ng0
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,
struct GNUNET_NETWORK_Handle *sock;
struct ServiceListeningInfo *sli;
-#ifndef WINDOWS
int match_uid;
int match_gid;
-#endif
switch (sa->sa_family)
{
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))
{
GNUNET_free(sa);
return;
}
-#ifndef WINDOWS
if ((AF_UNIX == sa->sa_family)
#ifdef LINUX
/* Permission settings are not required when abstract sockets are used */
match_uid,
match_gid);
}
-#endif
if (GNUNET_OK != GNUNET_NETWORK_socket_listen(sock, 5))
{
GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "listen");
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"))
#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.
#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.
*/
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);
}
-#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.
*
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,
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;
termhandler = signal(SIGTERM,
&signalhandler);
-#ifdef WINDOWS
- setmode(0, _O_BINARY);
-#endif
-
/* Initialisation */
gst_init(&argc, &argv);
dump_pure_ogg = getenv("GNUNET_RECORD_PURE_OGG") ? 1 : 0;
#endif
-#ifdef WINDOWS
- setmode(1, _O_BINARY);
-#endif
-
/* Initialisation */
gst_init(&argc, &argv);
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;
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))
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,
"<gnunet>",
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
"text/plain",
fn,
strlen(fn) + 1);
-#else
- GNUNET_CONTAINER_meta_data_insert(ret->meta,
- "<gnunet>",
- EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
- EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- fn,
- strlen(fn) + 1);
-#endif
return ret;
}
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));
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);
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,
}
-#ifndef WINDOWS
/**
* Install a signal handler to ignore SIGPIPE.
*/
GNUNET_assert(0 == close(z));
}
-#endif
-
/**
* Main function of the helper process to extract meta data.
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))
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];
(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;
}
{
#if HAVE_LIBEXTRACTOR
EXTRACTOR_plugin_remove_all(plugins);
-#endif
-#if WINDOWS
- GNUNET_free((void *)argv);
#endif
return 3;
}
free_tree(root);
#if HAVE_LIBEXTRACTOR
EXTRACTOR_plugin_remove_all(plugins);
-#endif
-#if WINDOWS
- GNUNET_free((void *)argv);
#endif
return 4;
}
0);
#if HAVE_LIBEXTRACTOR
EXTRACTOR_plugin_remove_all(plugins);
-#endif
-#if WINDOWS
- GNUNET_free((void *)argv);
#endif
return 0;
}
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;
}
#ifndef __GAUGER_H__
#define __GAUGER_H__
-#ifndef WINDOWS
-
#include <unistd.h>
#include <stdio.h>
#include <sys/wait.h>
} \
}
-#else /* WINDOWS */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <windef.h>
-
-#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
* 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
};
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).
*/
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"
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
*/
void
GNUNET_NETWORK_unix_precheck(const struct sockaddr_un *un);
-#endif
/**
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
*
#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 <sys/types.h>
#define VERBOSE_STATS 0
-#ifdef CYGWIN
-#include <sys/reent.h>
-#endif
-
-#ifdef _MSC_VER
-#ifndef FD_SETSIZE
-#define FD_SETSIZE 1024
-#endif
-#include <Winsock2.h>
-#include <ws2tcpip.h>
-#else
-#ifndef MINGW
#include <netdb.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <grp.h>
-#else
-#include "winproc.h"
-#endif
-#endif
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <libgen.h>
-#ifdef WINDOWS
-#include <malloc.h> /* for alloca(), on other OSes it's in stdlib.h */
-#endif
#ifdef HAVE_MALLOC_H
#include <malloc.h> /* for mallinfo on GNU */
#endif
-#ifndef _MSC_VER
#include <unistd.h> /* KLB_FIX */
-#endif
#include <sys/stat.h>
#include <sys/types.h>
-#ifndef _MSC_VER
#include <dirent.h> /* KLB_FIX */
-#endif
#include <fcntl.h>
#include <math.h>
#if HAVE_SYS_PARAM_H
#if HAVE_SYS_UCRED_H
#include <sys/ucred.h>
#endif
-#ifdef CYGWIN
-#include <windows.h>
-#include <cygwin/if.h>
-#endif
#if HAVE_IFADDRS_H
#include <ifaddrs.h>
#endif
#include <sys/endian.h>
#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"
#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 <sys/mman.h>
-#endif
#ifdef FREEBSD
#define __BYTE_ORDER BYTE_ORDER
#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
char *home_dir;
struct stat st;
-#ifndef WINDOWS
struct passwd *pw;
-#endif
+
int configured;
-#ifndef WINDOWS
pw = getpwuid(getuid());
if (!pw)
{
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"),
/**
* We need pipe control only on WINDOWS
*/
-#if WINDOWS
-#define PIPE_CONTROL GNUNET_YES
-#else
#define PIPE_CONTROL GNUNET_NO
-#endif
/**
{
/* 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;
}
static processor_cpu_load_info_t prev_cpu_load;
#endif
-#ifdef WINDOWS
-#include <winternl.h>
-#endif
#define DEBUG_STATUSCALLS GNUNET_NO
/**
* We need pipe control only on WINDOWS
*/
-#if WINDOWS
-#define PIPE_CONTROL GNUNET_YES
-#else
#define PIPE_CONTROL GNUNET_NO
-#endif
/**
(!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"),
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) &&
->sun_path,
sctx->match_uid,
sctx->match_gid);
-#endif
-
if (0 == (sctx->options & LEGACY_SERVICE_OPTION_MANUAL_SHUTDOWN))
{
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) &&
->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;
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, "/");
#define BAADFOOD_STR "\xBA\xAD\xF0\x0D"
#endif
-#if WINDOWS
-#define M_SIZE(p) _msize(p)
-#endif
#if HAVE_MALLOC_NP_H
#include <malloc_np.h>
#endif
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
void
GNUNET_abort_()
{
-#if WINDOWS
- DebugBreak();
-#endif
abort();
}
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)
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());
GNUNET_free(pos);
}
-#if WINDOWS
-CRITICAL_SECTION output_message_cs;
-#endif
-
/**
* Actually output the log message.
{
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))
{
pos->logger(pos->logger_cls, kind, comp, datestr, msg);
pos = pos->next;
}
-#if WINDOWS
- LeaveCriticalSection(&output_message_cs);
-#endif
}
{
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);
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)
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];
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
}
*/
void __attribute__ ((destructor)) GNUNET_util_cl_fini()
{
-#if WINDOWS
- DeleteCriticalSection(&output_message_cs);
-#endif
-#ifdef MINGW
- GNShutdownWinEnv();
-#endif
+
}
/* end of common_logging.c */
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;
}
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;
#else
*dev = 0;
#endif
-#endif /* !WINDOWS */
return GNUNET_OK;
}
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");
{
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
GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "chmod", fn);
}
-#endif
/**
* Create an (empty) temporary directory on disk. If the given name is not
}
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;
}
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);
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
}
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;
errno = eno;
}
return ret;
-#endif
}
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
}
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;
if (0 == (flags & O_NONBLOCK))
(void)fcntl(h->fd, F_SETFL, flags);
return ret;
-#endif
}
int
GNUNET_DISK_file_change_owner(const char *filename, const char *user)
{
-#ifndef MINGW
struct passwd *pws;
pws = getpwnam(user);
LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "chown", filename);
return GNUNET_SYSERR;
}
-#endif
return GNUNET_OK;
}
return GNUNET_SYSERR;
}
-#ifndef MINGW
struct flock fl;
memset(&fl, 0, sizeof(struct flock));
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
}
return GNUNET_SYSERR;
}
-#ifndef MINGW
struct flock fl;
memset(&fl, 0, sizeof(struct flock));
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
}
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)
#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;
}
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.
*
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;
}
*/
void *addr;
-#ifdef MINGW
- /**
- * Underlying OS handle.
- */
- HANDLE h;
-#else
/**
* Number of bytes mapped.
*/
size_t len;
-#endif
};
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;
}
(*m)->len = len;
return (*m)->addr;
-#endif
}
/**
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;
}
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;
}
-#if WINDOWS
-#ifndef PIPE_BUF
-#define PIPE_BUF 512
-#endif
-/* Copyright Bob Byrnes <byrnes <at> 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
*
int inherit_read,
int inherit_write)
{
-#ifndef MINGW
int fd[2];
int ret;
int eno;
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
}
p = GNUNET_new(struct GNUNET_DISK_PipeHandle);
-#ifndef MINGW
int ret;
int flags;
int eno = 0; /* make gcc happy */
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;
}
{
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;
}
#include <idn/idna.h>
#endif
#endif
-#if WINDOWS
-#include <idn-free.h>
-#endif
#include "gnunet_util_lib.h"
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;
}
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;
}
{
GNUNET_free(tmp);
GNUNET_asprintf(&tmp, "%s%s.", ret, utf8);
-#if WINDOWS
- idn_free(utf8);
-#else
free(utf8);
-#endif
}
GNUNET_free(ret);
ret = tmp;
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;
}
#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 <windows.h>
-#define getpid() GetCurrentProcessId()
-#endif
-
#ifndef _
/* This is for other GNU distributions with internationalized messages.
When compiling libc, the _ macro is predefined. */
+++ /dev/null
-/*
- 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 <http://www.gnu.org/licenses/>.
-
- 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 <chars|events> <buffer size> <parent pid>\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 */
+++ /dev/null
-/*
- 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 <http://www.gnu.org/licenses/>.
-
- 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
* @brief handle to a socket
*/
struct GNUNET_NETWORK_Handle {
-#ifndef MINGW
int fd;
-#else
- _win_socket fd;
-#endif
/**
* Address family / domain.
}
else
{
-#if WINDOWS
- closesocket(s);
-#else
close(s);
-#endif
ret = GNUNET_OK;
}
switch (pf)
}
-#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
"unlink",
un->sun_path);
}
-#endif
-
#ifndef FD_COPY
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)
return GNUNET_SYSERR;
}
return GNUNET_OK;
-#endif
}
static int
socket_set_inheritable(const struct GNUNET_NETWORK_Handle *h)
{
-#ifndef MINGW
int i;
i = fcntl(h->fd, F_GETFD);
if (i < 0)
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;
}
static void
socket_set_nodelay(const struct GNUNET_NETWORK_Handle *h)
{
-#ifndef WINDOWS
int value = 1;
if (0 !=
&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
}
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");
}
#endif
#endif
-#ifndef WINDOWS
if (AF_UNIX == address->sa_family)
GNUNET_NETWORK_unix_precheck((const struct sockaddr_un *)address);
{
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;
}
{
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
}
GNUNET_free(dirname);
}
-#endif
GNUNET_NETWORK_socket_free_memory_only_(desc);
return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR;
}
{
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
}
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;
}
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;
}
ret = listen(desc->fd,
backlog);
-#ifdef MINGW
- if (SOCKET_ERROR == ret)
- SetErrnoFromWinsockError(WSAGetLastError());
-#endif
+
return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
}
int error;
/* How much is there to be read? */
-#ifndef WINDOWS
int pending;
error = ioctl(desc->fd,
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
}
{
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 !=
{
FD_ZERO(&fds->sds);
fds->nsds = 0;
-#ifdef MINGW
- fds->handles_pos = 0;
-#endif
}
#if DARWIN
#include <mach-o/ldsyms.h>
#include <mach-o/dyld.h>
-#elif WINDOWS
-#include <windows.h>
#endif
#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 <GNUNET_PREFIX>/bin or <GNUNET_PREFIX>.
- */
- 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.
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)))
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;
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;
*/
pid_t pid;
-#if WINDOWS
- /**
- * Process handle.
- */
- HANDLE handle;
-#endif
/**
* Pipe we use to signal the process.
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",
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);
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;
}
/* 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
}
}
{
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
}
GNUNET_break(0 == close(fd));
}
-#endif
/**
(!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"),
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);
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;
}
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);
}
* (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;
}
int *r_is_uri,
char **r_uri_scheme)
{
-#if WINDOWS
- size_t len;
-#endif
const char *post_scheme_path;
int is_uri;
char *uri;
*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,
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.
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
}
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;
}
}
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;
}
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);
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);
}