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