--- /file_io/unix/dir.c.path_iconv
+++ /file_io/unix/dir.c
@@ -24,6 +24,8 @@
#include <limits.h>
#endif
+#include "path_iconv.h"
+
static apr_status_t dir_cleanup(void *thedir)
{
apr_dir_t *dir = thedir;
@@ -71,6 +73,9 @@
apr_status_t apr_dir_open(apr_dir_t **new, const char *dirname,
apr_pool_t *pool)
{
+ char dirname_fs[APR_PATH_MAX];
+ apr_status_t rv;
+
/* On some platforms (e.g., Linux+GNU libc), d_name[] in struct
* dirent is declared with enough storage for the name. On other
* platforms (e.g., Solaris 8 for Intel), d_name is declared as a
@@ -79,7 +84,11 @@
apr_size_t dirent_size =
sizeof(*(*new)->entry) +
(sizeof((*new)->entry->d_name) > 1 ? 0 : 255);
- DIR *dir = opendir(dirname);
+
+ rv = apr_iconv_proc2fs(dirname, dirname_fs);
+ if (rv != APR_SUCCESS)
+ return rv;
+ DIR *dir = opendir(dirname_fs);
if (!dir) {
return errno;
@@ -133,7 +142,8 @@
apr_status_t apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted,
apr_dir_t *thedir)
{
- apr_status_t ret = 0;
+ apr_status_t ret = 0,rv;
+ char procname[APR_PATH_MAX];
#ifdef DIRENT_TYPE
apr_filetype_e type;
#endif
@@ -194,6 +204,10 @@
}
#endif
+ rv = apr_iconv_fs2proc(thedir->entry->d_name, procname);
+ if (rv != APR_SUCCESS)
+ return rv;
+
/* No valid bit flag to test here - do we want one? */
finfo->fname = NULL;
@@ -239,7 +253,7 @@
if (end > fspec && end[-1] != '/' && (end < fspec + APR_PATH_MAX))
*end++ = '/';
- apr_cpystrn(end, thedir->entry->d_name,
+ apr_cpystrn(end, procname,
sizeof fspec - (end - fspec));
ret = apr_stat(finfo, fspec, APR_FINFO_LINK | wanted, thedir->pool);
@@ -270,7 +284,7 @@
#endif
}
- finfo->name = apr_pstrdup(thedir->pool, thedir->entry->d_name);
+ finfo->name = apr_pstrndup(thedir->pool, procname,NAME_MAX);
finfo->valid |= APR_FINFO_NAME;
if (wanted)
@@ -289,8 +303,11 @@
apr_pool_t *pool)
{
mode_t mode = apr_unix_perms2mode(perm);
-
- if (mkdir(path, mode) == 0) {
+ char fsname[APR_PATH_MAX];
+ apr_status_t rv = apr_iconv_proc2fs(path, fsname);
+ if (rv != APR_SUCCESS)
+ return rv;
+ if (mkdir(fsname, mode) == 0) {
return APR_SUCCESS;
}
else {
@@ -329,6 +346,12 @@
apr_status_t apr_dir_remove(const char *path, apr_pool_t *pool)
{
- if (rmdir(path) == 0) {
+ char fsname[APR_PATH_MAX];
+ apr_status_t rv = apr_iconv_proc2fs(path, fsname);
+
+ if (rv != APR_SUCCESS)
+ return rv;
+
+ if (rmdir(fsname) == 0) {
return APR_SUCCESS;
}
else {
--- /file_io/unix/filepath.c.path_iconv
+++ /file_io/unix/filepath.c
@@ -32,20 +32,28 @@
#include <dirent.h>
#endif
+#include "path_iconv.h"
+
/* Any OS that requires/refuses trailing slashes should be dealt with here.
*/
APR_DECLARE(apr_status_t) apr_filepath_get(char **defpath, apr_int32_t flags,
apr_pool_t *p)
{
- char path[APR_PATH_MAX];
+ char fspath[APR_PATH_MAX], procpath[APR_PATH_MAX];
+ apr_status_t rv;
- if (!getcwd(path, sizeof(path))) {
+ if (!getcwd(fspath, sizeof(fspath))) {
if (errno == ERANGE)
return APR_ENAMETOOLONG;
else
return errno;
}
- *defpath = apr_pstrdup(p, path);
+
+ rv = apr_iconv_fs2proc(fspath, procpath);
+ if (rv != APR_SUCCESS)
+ return rv;
+
+ *defpath = apr_pstrdup(p, procpath);
return APR_SUCCESS;
}
@@ -55,8 +63,14 @@
*/
APR_DECLARE(apr_status_t) apr_filepath_set(const char *path, apr_pool_t *p)
{
- if (chdir(path) != 0)
- return errno;
+ char fspath[APR_PATH_MAX];
+ apr_status_t rv = apr_iconv_proc2fs(path, fspath);
+
+ if (rv != APR_SUCCESS)
+ return rv;
+
+ if (chdir(fspath) != 0)
+return errno;
return APR_SUCCESS;
}
--- /file_io/unix/open.c.path_iconv
+++ /file_io/unix/open.c
@@ -26,10 +26,13 @@
#include "fsio.h"
#endif
+#include "path_iconv.h"
+
apr_status_t apr_unix_file_cleanup(void *thefile)
{
apr_file_t *file = thefile;
- apr_status_t flush_rv = APR_SUCCESS, rv = APR_SUCCESS;
+ apr_status_t flush_rv = APR_SUCCESS, rv = APR_SUCCESS, rv2 = APR_SUCCESS;
+ char fsname[APR_PATH_MAX];
if (file->buffered) {
flush_rv = apr_file_flush(file);
@@ -38,6 +41,10 @@
file->filedes = -1;
if (file->flags & APR_DELONCLOSE) {
unlink(file->fname);
+ rv2 = apr_iconv_proc2fs(file->fname, fsname);
+ if (rv2 != APR_SUCCESS)
+ return rv2;
+ unlink(fsname);
}
#if APR_HAS_THREADS
if (file->thlock) {
@@ -64,7 +71,7 @@
}
APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new,
- const char *fname,
+ const char *procname,
apr_int32_t flag,
apr_fileperms_t perm,
apr_pool_t *pool)
@@ -73,8 +80,12 @@
int oflags = 0;
#if APR_HAS_THREADS
apr_thread_mutex_t *thlock;
- apr_status_t rv;
#endif
+ char fsname[APR_PATH_MAX];
+ apr_status_t rv = apr_iconv_proc2fs(procname, fsname);
+
+ if (rv != APR_SUCCESS)
+ return rv;
if ((flag & APR_READ) && (flag & APR_WRITE)) {
oflags = O_RDWR;
@@ -130,10 +141,10 @@
#endif
if (perm == APR_OS_DEFAULT) {
- fd = open(fname, oflags, 0666);
+ fd = open(fsname, oflags, 0666);
}
else {
- fd = open(fname, oflags, apr_unix_perms2mode(perm));
+ fd = open(fsname, oflags, apr_unix_perms2mode(perm));
}
if (fd < 0) {
return errno;
@@ -144,7 +155,7 @@
(*new)->flags = flag;
(*new)->filedes = fd;
- (*new)->fname = apr_pstrdup(pool, fname);
+ (*new)->fname = apr_pstrdup(pool, procname);
(*new)->blocking = BLK_ON;
(*new)->buffered = (flag & APR_BUFFERED) > 0;
@@ -190,7 +201,12 @@
APR_DECLARE(apr_status_t) apr_file_remove(const char *path, apr_pool_t *pool)
{
- if (unlink(path) == 0) {
+ char fsname[APR_PATH_MAX];
+ apr_status_t rv = apr_iconv_proc2fs(path, fsname);
+ if (rv != APR_SUCCESS)
+ return rv;
+
+ if (unlink(fsname) == 0) {
return APR_SUCCESS;
}
else {
@@ -202,7 +218,18 @@
const char *to_path,
apr_pool_t *p)
{
- if (rename(from_path, to_path) != 0) {
+ char from_path_fs[APR_PATH_MAX], to_path_fs[APR_PATH_MAX];
+ apr_status_t rv;
+
+ rv = apr_iconv_proc2fs(from_path, from_path_fs);
+ if (rv != APR_SUCCESS)
+ return rv;
+
+ rv = apr_iconv_proc2fs(to_path, to_path_fs);
+ if (rv != APR_SUCCESS)
+ return rv;
+
+ if (rename(from_path_fs, to_path_fs) != 0) {
return errno;
}
return APR_SUCCESS;
--- /file_io/unix/path_iconv.c
+++ /file_io/unix/path_iconv.c
@@ -0,0 +1,148 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+#include "apr_file_io.h"
+#include "apr_file_info.h"
+#include <iconv.h>
+#include <string.h>
+#include <stdlib.h>
+#include "apr_strings.h"
+#include "path_iconv.h"
+
+static char *FS_ENCODING = (char *)-1;
+
+/*
+ * convert a processing encoding to the filesystem encoding
+ */
+APR_DECLARE(apr_status_t) apr_iconv_proc2fs(const char *procname,
+ char *fsname)
+{
+ static iconv_t cd_proc2fs = NULL;
+ char *procname_v = (char *)procname;
+ size_t fssize = APR_PATH_MAX, procsize;
+
+ if (procname == NULL || fsname == NULL)
+ return APR_EGENERAL;
+
+ if (FS_ENCODING == (char *)-1)
+ FS_ENCODING = getenv("APACHE_FS_ENCODING");
+
+ if (FS_ENCODING == NULL) {
+ apr_cpystrn(fsname, procname, APR_PATH_MAX);
+ return APR_SUCCESS;
+ }
+
+ procsize = strlen(procname) + 1;
+
+ if (cd_proc2fs == NULL) {
+ cd_proc2fs = iconv_open(FS_ENCODING, PROC_ENCODING);
+ if (cd_proc2fs == (iconv_t)-1) {
+ return errno;
+ }
+ }
+
+#if 1
+ if (iconv(cd_proc2fs, NULL, NULL, NULL, NULL) < 0)
+ return errno;
+#endif
+
+ if (iconv(cd_proc2fs, &procname_v, &procsize, &fsname, &fssize) < 0)
+ return errno;
+
+ return APR_SUCCESS;
+}
+
+
+/*
+ * initialize iconv descripters
+ */
+APR_DECLARE(apr_status_t) apr_iconv_fs2proc(const char *fsname,
+ char *procname)
+{
+ static iconv_t cd_fs2proc = NULL;
+ char *fsname_v = (char *)fsname;
+ size_t procsize = APR_PATH_MAX, fssize;
+
+ if (fsname == NULL || procname == NULL)
+ return APR_EGENERAL;
+
+ if (FS_ENCODING == (char *)-1)
+ FS_ENCODING = getenv("APACHE_FS_ENCODING");
+
+ if (FS_ENCODING == NULL) {
+ apr_cpystrn(procname, fsname, APR_PATH_MAX);
+ return APR_SUCCESS;
+ }
+
+ fssize = strlen(fsname) + 1;
+
+ if (cd_fs2proc == NULL) {
+ cd_fs2proc = iconv_open(PROC_ENCODING, FS_ENCODING);
+ if (cd_fs2proc == (iconv_t)-1) {
+ return errno;
+ }
+ }
+
+#if 1
+ if (iconv(cd_fs2proc, NULL, NULL, NULL, NULL) < 0)
+ return errno;
+#endif
+
+ if (iconv(cd_fs2proc, &fsname_v, &fssize, &procname, &procsize) < 0)
+ return errno;
+
+ return APR_SUCCESS;
+}
+
+
--- /file_io/unix/path_iconv.h
+++ /file_io/unix/path_iconv.h
@@ -0,0 +1,74 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+#ifndef PATH_ICONV_H
+#define PATH_ICONV_H
+
+
+#define PROC_ENCODING "UTF-8"
+
+
+/*
+ * convert a processing encoding to the filesystem encoding
+ */
+APR_DECLARE(apr_status_t) apr_iconv_proc2fs(const char *procname,
+ char *fsname);
+
+/*
+ * initialize iconv descripters
+ */
+APR_DECLARE(apr_status_t) apr_iconv_fs2proc(const char *fsname,
+ char *procname);
+
+#endif /* PATH_ICONV_H */
--- /file_io/unix/pipe.c.path_iconv
+++ /file_io/unix/pipe.c
@@ -17,7 +17,7 @@
#include "apr_arch_file_io.h"
#include "apr_strings.h"
#include "apr_portable.h"
-
+#include "path_iconv.h"
#include "apr_arch_inherit.h"
/* Figure out how to get pipe block/nonblock on BeOS...
@@ -222,12 +222,17 @@
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_file_namedpipe_create(const char *filename,
+APR_DECLARE(apr_status_t) apr_file_namedpipe_create(const char *procname,
apr_fileperms_t perm, apr_pool_t *pool)
{
+ char fsname[APR_PATH_MAX];
+ apr_status_t rv = apr_iconv_proc2fs(procname, fsname);
mode_t mode = apr_unix_perms2mode(perm);
- if (mkfifo(filename, mode) == -1) {
+ if (rv != APR_SUCCESS)
+ return rv;
+
+ if (mkfifo(fsname, mode) == -1) {
return errno;
}
return APR_SUCCESS;
--- /file_io/unix/filestat.c.path_iconv
+++ /file_io/unix/filestat.c
@@ -19,6 +19,7 @@
#include "apr_general.h"
#include "apr_strings.h"
#include "apr_errno.h"
+#include "path_iconv.h"
#ifdef HAVE_UTIME
#include <utime.h>
@@ -123,12 +124,17 @@
}
}
-APR_DECLARE(apr_status_t) apr_file_perms_set(const char *fname,
+APR_DECLARE(apr_status_t) apr_file_perms_set(const char *procname,
apr_fileperms_t perms)
{
+ char fsname[APR_PATH_MAX];
+ apr_status_t rv = apr_iconv_proc2fs(procname, fsname);
mode_t mode = apr_unix_perms2mode(perms);
- if (chmod(fname, mode) == -1)
+ if (rv != APR_SUCCESS)
+ return rv;
+
+ if (chmod(fsname, mode) == -1)
return errno;
return APR_SUCCESS;
}
@@ -234,20 +240,25 @@
APR_DECLARE(apr_status_t) apr_stat(apr_finfo_t *finfo,
- const char *fname,
+ const char *procname,
apr_int32_t wanted, apr_pool_t *pool)
{
struct_stat info;
int srv;
+ char fsname[APR_PATH_MAX];
+ apr_status_t rv = apr_iconv_proc2fs(procname, fsname);
+
+ if (rv != APR_SUCCESS)
+ return rv;
if (wanted & APR_FINFO_LINK)
- srv = lstat(fname, &info);
+ srv = lstat(fsname, &info);
else
- srv = stat(fname, &info);
+ srv = stat(fsname, &info);
if (srv == 0) {
finfo->pool = pool;
- finfo->fname = fname;
+ finfo->fname = procname;
fill_out_finfo(finfo, &info, wanted);
if (wanted & APR_FINFO_LINK)
wanted &= ~APR_FINFO_LINK;
=========================パッチここまで====================![]()

