aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-12-30 22:44:49 +0000
committerChristian Grothoff <christian@grothoff.org>2011-12-30 22:44:49 +0000
commitd60192bbfe69cb3d8e36afaf459f72bb9fa4d288 (patch)
tree5feadcb1dc083dc1dd166f31c101242db6c0567b /src
parentf5a017ed63ee50feeefc6f0c2b28549aeca92ded (diff)
downloadgnunet-d60192bbfe69cb3d8e36afaf459f72bb9fa4d288.tar.gz
gnunet-d60192bbfe69cb3d8e36afaf459f72bb9fa4d288.zip
-LRN: utf8-ization, #2051
Diffstat (limited to 'src')
-rw-r--r--src/fs/fs_file_information.c14
-rw-r--r--src/util/disk.c52
-rw-r--r--src/util/os_installation.c18
-rw-r--r--src/util/os_priority.c19
-rw-r--r--src/util/test_container_bloomfilter.c2
5 files changed, 76 insertions, 29 deletions
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c
index 4ea264892..c2ab84ec2 100644
--- a/src/fs/fs_file_information.c
+++ b/src/fs/fs_file_information.c
@@ -173,10 +173,17 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
173#endif 173#endif
174 while (NULL != (ss = strstr (fn, DIR_SEPARATOR_STR))) 174 while (NULL != (ss = strstr (fn, DIR_SEPARATOR_STR)))
175 fn = ss + 1; 175 fn = ss + 1;
176#if !WINDOWS
176 GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>", 177 GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>",
177 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, 178 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
178 EXTRACTOR_METAFORMAT_C_STRING, 179 EXTRACTOR_METAFORMAT_C_STRING,
179 "text/plain", fn, strlen (fn) + 1); 180 "text/plain", fn, strlen (fn) + 1);
181#else
182 GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>",
183 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
184 EXTRACTOR_METAFORMAT_UTF8,
185 "text/plain", fn, strlen (fn) + 1);
186#endif
180 return ret; 187 return ret;
181} 188}
182 189
@@ -770,10 +777,17 @@ GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
770 while ((NULL != (ss = strstr (fn, DIR_SEPARATOR_STR))) && (strlen (ss) > 1)) 777 while ((NULL != (ss = strstr (fn, DIR_SEPARATOR_STR))) && (strlen (ss) > 1))
771 fn = ss + 1; 778 fn = ss + 1;
772 GNUNET_asprintf (&dn, "%s/", fn); 779 GNUNET_asprintf (&dn, "%s/", fn);
780#if !WINDOWS
773 GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>", 781 GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>",
774 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, 782 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
775 EXTRACTOR_METAFORMAT_C_STRING, 783 EXTRACTOR_METAFORMAT_C_STRING,
776 "text/plain", dn, strlen (dn) + 1); 784 "text/plain", dn, strlen (dn) + 1);
785#else
786 GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>",
787 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
788 EXTRACTOR_METAFORMAT_UTF8,
789 "text/plain", dn, strlen (dn) + 1);
790#endif
777 GNUNET_free (dn); 791 GNUNET_free (dn);
778 ret->filename = GNUNET_strdup (filename); 792 ret->filename = GNUNET_strdup (filename);
779 return ret; 793 return ret;
diff --git a/src/util/disk.c b/src/util/disk.c
index 0c9093fbc..9e64a3a60 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -397,6 +397,7 @@ GNUNET_DISK_mktemp (const char *t)
397#endif 397#endif
398 ) 398 )
399 { 399 {
400 /* FIXME: This uses system codepage on W32, not UTF-8 */
400 tmpdir = getenv ("TMPDIR"); 401 tmpdir = getenv ("TMPDIR");
401 tmpdir = tmpdir ? tmpdir : "/tmp"; 402 tmpdir = tmpdir ? tmpdir : "/tmp";
402 GNUNET_asprintf (&tmpl, "%s/%s%s", tmpdir, t, "XXXXXX"); 403 GNUNET_asprintf (&tmpl, "%s/%s%s", tmpdir, t, "XXXXXX");
@@ -417,6 +418,9 @@ GNUNET_DISK_mktemp (const char *t)
417#else 418#else
418 fn = tmpl; 419 fn = tmpl;
419#endif 420#endif
421 /* FIXME: why is this not MKSTEMP()? This function is implemented in plibc.
422 * It will assume that fn is UTF-8-encoded, if compiled with UTF-8 support.
423 */
420 fd = mkstemp (fn); 424 fd = mkstemp (fn);
421 if (fd == -1) 425 if (fd == -1)
422 { 426 {
@@ -452,18 +456,26 @@ GNUNET_DISK_get_blocks_available (const char *part)
452#elif MINGW 456#elif MINGW
453 DWORD dwDummy; 457 DWORD dwDummy;
454 DWORD dwBlocks; 458 DWORD dwBlocks;
455 char szDrive[4]; 459 wchar_t szDrive[4];
460 wchar_t wpath[MAX_PATH + 1];
456 char *path; 461 char *path;
457 462
458 path = GNUNET_STRINGS_filename_expand (part); 463 path = GNUNET_STRINGS_filename_expand (part);
459 if (path == NULL) 464 if (path == NULL)
460 return -1; 465 return -1;
461 memcpy (szDrive, path, 3); 466 /* "part" was in UTF-8, and so is "path" */
467 if (ERROR_SUCCESS != plibc_conv_to_win_pathwconv(path, wpath))
468 {
469 GNUNET_free (path);
470 return -1;
471 }
462 GNUNET_free (path); 472 GNUNET_free (path);
473 wcsncpy (szDrive, wpath, 3);
474 GNUNET_free (wpath);
463 szDrive[3] = 0; 475 szDrive[3] = 0;
464 if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy)) 476 if (!GetDiskFreeSpaceW (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy))
465 { 477 {
466 LOG (GNUNET_ERROR_TYPE_WARNING, _("`%s' failed for drive `%s': %u\n"), 478 LOG (GNUNET_ERROR_TYPE_WARNING, _("`%s' failed for drive `%S': %u\n"),
467 "GetDiskFreeSpace", szDrive, GetLastError ()); 479 "GetDiskFreeSpace", szDrive, GetLastError ());
468 480
469 return -1; 481 return -1;
@@ -621,7 +633,11 @@ GNUNET_DISK_directory_create (const char *dir)
621#ifndef MINGW 633#ifndef MINGW
622 ret = mkdir (rdir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); /* 755 */ 634 ret = mkdir (rdir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); /* 755 */
623#else 635#else
624 ret = mkdir (rdir); 636 wchar_t wrdir[MAX_PATH + 1];
637 if (ERROR_SUCCESS == plibc_conv_to_win_pathwconv(rdir, wrdir))
638 ret = !CreateDirectoryW (wrdir, NULL);
639 else
640 ret = 1;
625#endif 641#endif
626 if ((ret != 0) && (errno != EEXIST)) 642 if ((ret != 0) && (errno != EEXIST))
627 { 643 {
@@ -874,14 +890,14 @@ GNUNET_DISK_directory_scan (const char *dirName,
874 { 890 {
875 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "opendir", dname); 891 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "opendir", dname);
876 if (dinfo != NULL) 892 if (dinfo != NULL)
877 closedir (dinfo); 893 CLOSEDIR (dinfo);
878 GNUNET_free (dname); 894 GNUNET_free (dname);
879 return GNUNET_SYSERR; 895 return GNUNET_SYSERR;
880 } 896 }
881 name_len = 256; 897 name_len = 256;
882 n_size = strlen (dname) + name_len + 2; 898 n_size = strlen (dname) + name_len + 2;
883 name = GNUNET_malloc (n_size); 899 name = GNUNET_malloc (n_size);
884 while ((finfo = readdir (dinfo)) != NULL) 900 while ((finfo = READDIR (dinfo)) != NULL)
885 { 901 {
886 if ((0 == strcmp (finfo->d_name, ".")) || 902 if ((0 == strcmp (finfo->d_name, ".")) ||
887 (0 == strcmp (finfo->d_name, ".."))) 903 (0 == strcmp (finfo->d_name, "..")))
@@ -903,7 +919,7 @@ GNUNET_DISK_directory_scan (const char *dirName,
903 0) ? "" : DIR_SEPARATOR_STR, finfo->d_name); 919 0) ? "" : DIR_SEPARATOR_STR, finfo->d_name);
904 if (GNUNET_OK != callback (callback_cls, name)) 920 if (GNUNET_OK != callback (callback_cls, name))
905 { 921 {
906 closedir (dinfo); 922 CLOSEDIR (dinfo);
907 GNUNET_free (name); 923 GNUNET_free (name);
908 GNUNET_free (dname); 924 GNUNET_free (dname);
909 return GNUNET_SYSERR; 925 return GNUNET_SYSERR;
@@ -911,7 +927,7 @@ GNUNET_DISK_directory_scan (const char *dirName,
911 } 927 }
912 count++; 928 count++;
913 } 929 }
914 closedir (dinfo); 930 CLOSEDIR (dinfo);
915 GNUNET_free (name); 931 GNUNET_free (name);
916 GNUNET_free (dname); 932 GNUNET_free (dname);
917 return count; 933 return count;
@@ -995,12 +1011,12 @@ GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator *iter,
995 GNUNET_assert (iter->next_name == NULL); 1011 GNUNET_assert (iter->next_name == NULL);
996 if (can == GNUNET_YES) 1012 if (can == GNUNET_YES)
997 { 1013 {
998 closedir (iter->directory); 1014 CLOSEDIR (iter->directory);
999 GNUNET_free (iter->dirname); 1015 GNUNET_free (iter->dirname);
1000 GNUNET_free (iter); 1016 GNUNET_free (iter);
1001 return GNUNET_SYSERR; 1017 return GNUNET_SYSERR;
1002 } 1018 }
1003 while (NULL != (finfo = readdir (iter->directory))) 1019 while (NULL != (finfo = READDIR (iter->directory)))
1004 { 1020 {
1005 if ((0 == strcmp (finfo->d_name, ".")) || 1021 if ((0 == strcmp (finfo->d_name, ".")) ||
1006 (0 == strcmp (finfo->d_name, ".."))) 1022 (0 == strcmp (finfo->d_name, "..")))
@@ -1340,6 +1356,7 @@ GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags,
1340 DWORD access; 1356 DWORD access;
1341 DWORD disp; 1357 DWORD disp;
1342 HANDLE h; 1358 HANDLE h;
1359 wchar_t wexpfn[MAX_PATH + 1];
1343#else 1360#else
1344 int oflags; 1361 int oflags;
1345 int mode; 1362 int mode;
@@ -1418,10 +1435,12 @@ GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags,
1418 disp = OPEN_EXISTING; 1435 disp = OPEN_EXISTING;
1419 } 1436 }
1420 1437
1421 /* TODO: access priviledges? */ 1438 if (ERROR_SUCCESS == plibc_conv_to_win_pathwconv(expfn, wexpfn))
1422 h = CreateFile (expfn, access, 1439 h = CreateFileW (wexpfn, access,
1423 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, 1440 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
1424 disp, FILE_ATTRIBUTE_NORMAL, NULL); 1441 disp, FILE_ATTRIBUTE_NORMAL, NULL);
1442 else
1443 h = INVALID_HANDLE_VALUE;
1425 if (h == INVALID_HANDLE_VALUE) 1444 if (h == INVALID_HANDLE_VALUE)
1426 { 1445 {
1427 SetErrnoFromWinError (GetLastError ()); 1446 SetErrnoFromWinError (GetLastError ());
@@ -2155,6 +2174,9 @@ GNUNET_DISK_npipe_create (char **fn, enum GNUNET_DISK_OpenFlags flags,
2155 LOG (GNUNET_ERROR_TYPE_DEBUG, 2174 LOG (GNUNET_ERROR_TYPE_DEBUG,
2156 "Trying to create an instance of named pipe `%s'\n", name); 2175 "Trying to create an instance of named pipe `%s'\n", name);
2157#endif 2176#endif
2177 /* 1) This might work just fine with UTF-8 strings as it is.
2178 * 2) This is only used by GNUnet itself, and only with latin names.
2179 */
2158 h = CreateNamedPipe (name, openMode | FILE_FLAG_OVERLAPPED, 2180 h = CreateNamedPipe (name, openMode | FILE_FLAG_OVERLAPPED,
2159 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 0, 2181 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 0,
2160 NULL); 2182 NULL);
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index 6d25c5709..c0b7c8583 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -112,15 +112,19 @@ get_path_from_proc_exe ()
112static char * 112static char *
113get_path_from_module_filename () 113get_path_from_module_filename ()
114{ 114{
115 char path[4097]; 115 wchar_t path[4097];
116 char *idx; 116 char upath[4097];
117 wchar_t *idx;
117 118
118 GetModuleFileName (NULL, path, sizeof (path) - 1); 119 GetModuleFileNameW (NULL, path, sizeof (path) - 1);
119 idx = path + strlen (path); 120 idx = path + wcslen (path);
120 while ((idx > path) && (*idx != '\\') && (*idx != '/')) 121 while ((idx > path) && (*idx != L'\\') && (*idx != L'/'))
121 idx--; 122 idx--;
122 *idx = '\0'; 123 *idx = L'\0';
123 return GNUNET_strdup (path); 124 upath[0] = '\0';
125 WideCharToMultiByte (CP_UTF8, 0, path, -1, upath, 4097, NULL, NULL);
126
127 return GNUNET_strdup (upath);
124} 128}
125#endif 129#endif
126 130
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index 6f5fa5007..e1f64ba0c 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -28,6 +28,7 @@
28#include "gnunet_common.h" 28#include "gnunet_common.h"
29#include "gnunet_os_lib.h" 29#include "gnunet_os_lib.h"
30#include "gnunet_scheduler_lib.h" 30#include "gnunet_scheduler_lib.h"
31#include "gnunet_strings_lib.h"
31#include "disk.h" 32#include "disk.h"
32 33
33#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) 34#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
@@ -653,7 +654,7 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin,
653 char *arg; 654 char *arg;
654 unsigned int cmdlen; 655 unsigned int cmdlen;
655 char *cmd, *idx; 656 char *cmd, *idx;
656 STARTUPINFO start; 657 STARTUPINFOW start;
657 PROCESS_INFORMATION proc; 658 PROCESS_INFORMATION proc;
658 659
659 HANDLE stdin_handle; 660 HANDLE stdin_handle;
@@ -670,6 +671,7 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin,
670 char *libdir; 671 char *libdir;
671 char *ptr; 672 char *ptr;
672 char *non_const_filename; 673 char *non_const_filename;
674 wchar_t wpath[MAX_PATH + 1], wcmd[32768];
673 675
674 /* Search in prefix dir (hopefully - the directory from which 676 /* Search in prefix dir (hopefully - the directory from which
675 * the current module was loaded), bindir and libdir, then in PATH 677 * the current module was loaded), bindir and libdir, then in PATH
@@ -786,8 +788,10 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin,
786 GNUNET_free (our_env[0]); 788 GNUNET_free (our_env[0]);
787 GNUNET_free (our_env[1]); 789 GNUNET_free (our_env[1]);
788 790
789 if (!CreateProcessA 791 if (ERROR_SUCCESS != plibc_conv_to_win_pathwconv(path, wpath)
790 (path, cmd, NULL, NULL, TRUE, DETACHED_PROCESS | CREATE_SUSPENDED, 792 || ERROR_SUCCESS != plibc_conv_to_win_pathwconv(cmd, wcmd)
793 || !CreateProcessW
794 (wpath, wcmd, NULL, NULL, TRUE, DETACHED_PROCESS | CREATE_SUSPENDED,
791 env_block, NULL, &start, &proc)) 795 env_block, NULL, &start, &proc))
792 { 796 {
793 SetErrnoFromWinError (GetLastError ()); 797 SetErrnoFromWinError (GetLastError ());
@@ -973,7 +977,7 @@ GNUNET_OS_start_process_v (const SOCKTYPE *lsocks,
973 char **arg, **non_const_argv; 977 char **arg, **non_const_argv;
974 unsigned int cmdlen; 978 unsigned int cmdlen;
975 char *cmd, *idx; 979 char *cmd, *idx;
976 STARTUPINFO start; 980 STARTUPINFOW start;
977 PROCESS_INFORMATION proc; 981 PROCESS_INFORMATION proc;
978 int argcount = 0; 982 int argcount = 0;
979 struct GNUNET_OS_Process *gnunet_proc = NULL; 983 struct GNUNET_OS_Process *gnunet_proc = NULL;
@@ -993,6 +997,7 @@ GNUNET_OS_start_process_v (const SOCKTYPE *lsocks,
993 const struct GNUNET_DISK_FileHandle *lsocks_write_fd; 997 const struct GNUNET_DISK_FileHandle *lsocks_write_fd;
994 HANDLE lsocks_read; 998 HANDLE lsocks_read;
995 HANDLE lsocks_write; 999 HANDLE lsocks_write;
1000 wchar_t wpath[MAX_PATH + 1], wcmd[32768];
996 1001
997 int fail; 1002 int fail;
998 1003
@@ -1151,8 +1156,10 @@ GNUNET_OS_start_process_v (const SOCKTYPE *lsocks,
1151 GNUNET_free_non_null (our_env[2]); 1156 GNUNET_free_non_null (our_env[2]);
1152 GNUNET_free_non_null (our_env[3]); 1157 GNUNET_free_non_null (our_env[3]);
1153 1158
1154 if (!CreateProcessA 1159 if (ERROR_SUCCESS != plibc_conv_to_win_pathwconv(path, wpath)
1155 (path, cmd, NULL, NULL, TRUE, DETACHED_PROCESS | CREATE_SUSPENDED, 1160 || ERROR_SUCCESS != plibc_conv_to_win_pathwconv(cmd, wcmd)
1161 || !CreateProcessW
1162 (wpath, wcmd, NULL, NULL, TRUE, DETACHED_PROCESS | CREATE_SUSPENDED,
1156 env_block, NULL, &start, &proc)) 1163 env_block, NULL, &start, &proc))
1157 { 1164 {
1158 SetErrnoFromWinError (GetLastError ()); 1165 SetErrnoFromWinError (GetLastError ());
diff --git a/src/util/test_container_bloomfilter.c b/src/util/test_container_bloomfilter.c
index aad6e99a4..f881bb367 100644
--- a/src/util/test_container_bloomfilter.c
+++ b/src/util/test_container_bloomfilter.c
@@ -69,7 +69,7 @@ main (int argc, char *argv[])
69 69
70 GNUNET_log_setup ("test-container-bloomfilter", "WARNING", NULL); 70 GNUNET_log_setup ("test-container-bloomfilter", "WARNING", NULL);
71 GNUNET_CRYPTO_seed_weak_random (1); 71 GNUNET_CRYPTO_seed_weak_random (1);
72 if (0 == stat (TESTFILE, &sbuf)) 72 if (0 == STAT (TESTFILE, &sbuf))
73 if (0 != UNLINK (TESTFILE)) 73 if (0 != UNLINK (TESTFILE))
74 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "unlink", TESTFILE); 74 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "unlink", TESTFILE);
75 bf = GNUNET_CONTAINER_bloomfilter_load (TESTFILE, SIZE, K); 75 bf = GNUNET_CONTAINER_bloomfilter_load (TESTFILE, SIZE, K);