handle.c \
handle.h \
main.c \
- main.h
+ main.h \
+ utf8.c \
+ utf8.h
captive_cmdline_CFLAGS= $(GNOME_VFS_CFLAGS)
captive_cmdline_LDADD =$(captive_library) $(GNOME_VFS_LIBS) $(READLINE_LIBS) $(INTLLIBS)
captive_cmdline_LDFLAGS=$(READLINE_LDFLAGS)
#include "cmd_cd.h" /* self */
#include "main.h"
+#include "utf8.h"
/* Config: */
targetdir))) { /* pathname */
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_CD_ERROR,CMDLINE_CMD_CD_ERROR_CANNOT_OPEN_DIRECTORY,
- _("Cannot open directory: %s"),targetdir);
+ _("Cannot open directory: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetdir));
return;
}
#include "cmd_cd.h" /* for cmdline_path_from_cwd() */
#include "main.h"
#include "handle.h"
+#include "utf8.h"
GQuark cmdline_cmd_create_error_quark(void)
(read_only ? 0400 : 0000)))) { /* perm */
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_CREATE_ERROR,CMDLINE_CMD_CREATE_ERROR_CREATING_FILE,
- _("Error creating guest-os file '%s'"),filename);
+ _("Error creating guest-os file '%s'"),CMD_LOCALE_FROM_UTF8_ALLOCA(filename));
return;
}
#include "cmd_get.h" /* self */
#include "cmd_cd.h" /* for cmdline_path_from_cwd() */
#include "main.h"
+#include "utf8.h"
/* Config: */
transfer_buffer_size=strtol(string,&endptr,0);
if (transfer_buffer_size<=0 || transfer_buffer_size>=LONG_MAX || (endptr && *endptr)) {
g_set_error(errp,CMDLINE_CMD_GET_ERROR,CMDLINE_CMD_GET_ERROR_PARSING_TRANSFER_BUFFER_SIZE,
- _("Error parsing transfer buffer size: %s"),string);
+ _("Error parsing transfer buffer size: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(string));
return;
}
}
targetfile=s+1;
}
- if (-1==(fdtgt=open(targetfile,
+ if (-1==(fdtgt=open(CMD_FILENAME_FROM_UTF8_ALLOCA(targetfile),
O_CREAT|O_EXCL|O_WRONLY /* flags */
#ifdef O_BINARY
| O_BINARY
,
perm))) { /* mode */
g_set_error(errp,CMDLINE_CMD_GET_ERROR,CMDLINE_CMD_GET_ERROR_CANNOT_CREATE_TARGET_HOSTOS_FILE,
- _("Cannot create target host-os file '%s': %s"),targetfile,g_strerror(errno));
+ _("Cannot create target host-os file '%s': %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile),g_strerror(errno));
return;
}
GNOME_VFS_OPEN_READ))) { /* mode */
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_GET_ERROR,CMDLINE_CMD_GET_ERROR_OPENING_SOURCE_FILE,
- _("Error opening source guest-os file: %s"),sourcefile);
+ _("Error opening source guest-os file: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(sourcefile));
goto err_close_fdtgt;
}
g_assert(errbool==FALSE);
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_GET_ERROR,CMDLINE_CMD_GET_ERROR_READING_SOURCE_FILE,
- _("Error reading source guest-os file '%s': %s"),sourcefile,g_strerror(errno));
+ _("Error reading source guest-os file '%s': %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(sourcefile),g_strerror(errno));
goto err_free_transfer_buffer;
}
if (bytes_read!=(GnomeVFSFileSize)(gotssize=write(fdtgt,transfer_buffer,bytes_read))) {
g_set_error(errp,CMDLINE_CMD_GET_ERROR,CMDLINE_CMD_GET_ERROR_WRITING_TARGET_HOSTOS_FILE,
- _("Error writing target host-os file: %s"),targetfile);
+ _("Error writing target host-os file: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile));
goto err_free_transfer_buffer;
}
}
if (close(fdtgt)) {
err_cleanup(errp); /* may be clean */
g_set_error(errp,CMDLINE_CMD_GET_ERROR,CMDLINE_CMD_GET_ERROR_CLOSING_TARGET_HOSTOS_FILE,
- _("Error closing target host-os file '%s': %s"),targetfile,g_strerror(errno));
+ _("Error closing target host-os file '%s': %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile),g_strerror(errno));
}
}
#include "cmd_cd.h" /* for cmdline_path_from_cwd() */
#include "main.h"
#include "file_info.h"
+#include "utf8.h"
GQuark cmdline_cmd_info_error_quark(void)
GNOME_VFS_OPEN_READ))) { /* mode */
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_INFO_ERROR,CMDLINE_CMD_INFO_ERROR_CANNOT_OPEN_FILE,
- _("Cannot open file: %s"),filepath);
+ _("Cannot open file: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(filepath));
return;
}
&file_info))) { /* file_info */
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_INFO_ERROR,CMDLINE_CMD_INFO_ERROR_GETTING_FILE_INFO,
- _("Cannot get file information about: %s"),filepath);
+ _("Cannot get file information about: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(filepath));
goto err_unref;
}
file_info_dump_full(&file_info,errp);
#include "cmd_lcd.h" /* self */
#include "main.h" /* for CMDLINE_POPT_AUTOHELP */
+#include "utf8.h"
const gchar *cmdline_cwd;
void cmd_lcd(const char **cmd_argv,GError **errp)
{
-gchar *currentdir;
+gchar *currentdir_filename;
g_return_if_fail(!errp || !*errp);
if (cmd_argv[0]) {
- if (chdir(cmd_argv[0])) {
+ if (chdir(CMD_FILENAME_FROM_UTF8_ALLOCA(cmd_argv[0]))) {
g_set_error(errp,CMDLINE_CMD_LCD_ERROR,CMDLINE_CMD_LCD_ERROR_CANNOT_CHANGE_HOSTOS_DIRECTORY,
- _("Cannot change host-os directory to '%s': %s"),cmd_argv[0],g_strerror(errno));
+ _("Cannot change host-os directory to '%s': %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(cmd_argv[0]),g_strerror(errno));
return;
}
}
- currentdir=g_get_current_dir();
- printf("Host-OS CWD: %s\n",currentdir);
- g_free(currentdir);
+ currentdir_filename=g_get_current_dir();
+ printf("Host-OS CWD: %s\n",CMD_LOCALE_FROM_UTF8_ALLOCA(CMD_FILENAME_TO_UTF8_ALLOCA(currentdir_filename)));
+ g_free(currentdir_filename);
}
#include "cmd_cd.h" /* for cmdline_path_from_cwd() */
#include "main.h"
#include "file_info.h"
+#include "utf8.h"
GQuark cmdline_cmd_ls_error_quark(void)
targetdir))) { /* pathname */
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_LS_ERROR,CMDLINE_CMD_LS_ERROR_CANNOT_OPEN_DIRECTORY,
- _("Cannot open directory: %s"),targetdir);
+ _("Cannot open directory: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetdir));
return;
}
g_assert(errbool==FALSE);
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_LS_ERROR,CMDLINE_CMD_LS_ERROR_READING_DIRECTORY,
- _("Error reading directory: %s"),targetdir);
+ _("Error reading directory: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetdir));
goto err_unref;
}
#include "cmd_mkdir.h" /* self */
#include "cmd_cd.h" /* for cmdline_path_from_cwd() */
#include "main.h"
+#include "utf8.h"
GQuark cmdline_cmd_mkdir_error_quark(void)
perms))) { /* perms */
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_MKDIR_ERROR,CMDLINE_CMD_MKDIR_ERROR_CANNOT_CREATE_DIRECTORY,
- _("Cannot create directory: %s"),targetdir);
+ _("Cannot create directory: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetdir));
return;
}
#include "cmd_mv.h" /* self */
#include "cmd_cd.h" /* for cmdline_path_from_cwd() */
#include "main.h"
+#include "utf8.h"
GQuark cmdline_cmd_mv_error_quark(void)
GNOME_VFS_OPEN_NONE))) { /* mode */
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_MV_ERROR,CMDLINE_CMD_MV_ERROR_CANNOT_OPEN_FILE_TO_MOVE,
- _("Cannot open file to be moved: %s"),targetfile);
+ _("Cannot open file to be moved: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile));
return;
}
FALSE))) { /* force_replace */
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_MV_ERROR,CMDLINE_CMD_MV_ERROR_CANNOT_MOVE_FILE,
- _("Cannot move file '%s' to its target name '%s'"),sourcefile,targetfile);
+ _("Cannot move file '%s' to its target name '%s'"),
+ CMD_LOCALE_FROM_UTF8_ALLOCA(sourcefile),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile));
goto err_unref;
}
#include "cmd_cd.h" /* for cmdline_path_from_cwd() */
#include "main.h"
#include "handle.h"
+#include "utf8.h"
GQuark cmdline_cmd_open_error_quark(void)
mode))) { /* mode */
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_OPEN_ERROR,CMDLINE_CMD_OPEN_ERROR_OPENING_FILE,
- _("Error opening guest-os file '%s'"),filename);
+ _("Error opening guest-os file '%s'"),CMD_LOCALE_FROM_UTF8_ALLOCA(filename));
return;
}
#include "cmd_put.h" /* self */
#include "cmd_cd.h" /* for cmdline_path_from_cwd() */
#include "main.h"
+#include "utf8.h"
/* Config: */
transfer_buffer_size=strtol(string,&endptr,0);
if (transfer_buffer_size<=0 || transfer_buffer_size>=LONG_MAX || (endptr && *endptr)) {
g_set_error(errp,CMDLINE_CMD_PUT_ERROR,CMDLINE_CMD_PUT_ERROR_PARSING_TRANSFER_BUFFER_SIZE,
- _("Error parsing transfer buffer size: %s"),string);
+ _("Error parsing transfer buffer size: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(string));
return;
}
}
g_free(sourcefile_basename);
}
- if (-1==(fdsrc=open(sourcefile,O_RDONLY
+ if (-1==(fdsrc=open(CMD_FILENAME_FROM_UTF8_ALLOCA(sourcefile),O_RDONLY
#ifdef O_BINARY
| O_BINARY
#endif /* O_BINARY */
#endif /* O_LARGEFILE */
))) {
g_set_error(errp,CMDLINE_CMD_PUT_ERROR,CMDLINE_CMD_PUT_ERROR_OPENING_SOURCE_FILE,
- _("Error opening source host-os file '%s': %s"),sourcefile,g_strerror(errno));
+ _("Error opening source host-os file '%s': %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(sourcefile),g_strerror(errno));
return;
}
perm))) { /* perm */
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_PUT_ERROR,CMDLINE_CMD_PUT_ERROR_CANNOT_CREATE_TARGET_GUESTOS_FILE,
- _("Cannot create target guest-os file: %s"),targetfile);
+ _("Cannot create target guest-os file: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile));
goto err_close_fdsrc;
}
&bytes_written))) { /* bytes_written_return */
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_PUT_ERROR,CMDLINE_CMD_PUT_ERROR_WRITING_TARGET_GUESTOS_FILE,
- _("Error writing target guest-os file: %s"),targetfile);
+ _("Error writing target guest-os file: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile));
goto err_free_transfer_buffer;
}
if (bytes_written!=(GnomeVFSFileSize)got) {
g_set_error(errp,CMDLINE_CMD_PUT_ERROR,CMDLINE_CMD_PUT_ERROR_WRITING_TARGET_GUESTOS_FILE,
_("Error writing target guest-os file '%s': requested %d, written %Lu"),
- targetfile,got,(unsigned long long)bytes_written);
+ CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile),got,(unsigned long long)bytes_written);
goto err_free_transfer_buffer;
}
}
if (got==-1) {
g_set_error(errp,CMDLINE_CMD_PUT_ERROR,CMDLINE_CMD_PUT_ERROR_READING_SOURCE_FILE,
- _("Error reading source host-os file '%s': %s"),sourcefile,g_strerror(errno));
+ _("Error reading source host-os file '%s': %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(sourcefile),g_strerror(errno));
goto err_free_transfer_buffer;
}
g_assert(got==0);
if (close(fdsrc)) {
err_cleanup(errp); /* may be clean */
g_set_error(errp,CMDLINE_CMD_PUT_ERROR,CMDLINE_CMD_PUT_ERROR_CLOSING_SOURCE_FILE,
- _("Error closing source host-os file '%s': %s"),sourcefile,g_strerror(errno));
+ _("Error closing source host-os file '%s': %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(sourcefile),g_strerror(errno));
}
}
#include "cmd_rm.h" /* self */
#include "cmd_cd.h" /* for cmdline_path_from_cwd() */
#include "main.h"
+#include "utf8.h"
GQuark cmdline_cmd_rm_error_quark(void)
GNOME_VFS_OPEN_NONE))) { /* mode */
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_RM_ERROR,CMDLINE_CMD_RM_ERROR_CANNOT_CREATE_REMOVAL_FILE,
- _("Cannot open file for removal: %s"),targetfile);
+ _("Cannot open file for removal: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile));
return;
}
captive_file_object))) { /* captive_file_object */
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_RM_ERROR,CMDLINE_CMD_RM_ERROR_CANNOT_SET_FILE_REMOVAL,
- _("Cannot set file removal state: %s"),targetfile);
+ _("Cannot set file removal state: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetfile));
goto err_unref;
}
#include "cmd_rmdir.h" /* self */
#include "cmd_cd.h" /* for cmdline_path_from_cwd() */
#include "main.h"
+#include "utf8.h"
GQuark cmdline_cmd_rmdir_error_quark(void)
targetdir))) { /* pathname */
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_RMDIR_ERROR,CMDLINE_CMD_RMDIR_ERROR_CANNOT_CREATE_REMOVAL_DIRECTORY,
- _("Cannot open directory for removal: %s"),targetdir);
+ _("Cannot open directory for removal: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetdir));
return;
}
captive_directory_object))) { /* captive_directory_object */
err_cleanup(errp);
g_set_error(errp,CMDLINE_CMD_RMDIR_ERROR,CMDLINE_CMD_RMDIR_ERROR_CANNOT_SET_DIRECTORY_REMOVAL,
- _("Cannot set directory removal state: %s"),targetdir);
+ _("Cannot set directory removal state: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(targetdir));
goto err_unref;
}
#include "file_info.h" /* self */
+#include "utf8.h"
GQuark cmdline_file_info_error_quark(void)
file_size=g_strdup_printf("%8s","???");
/* type pm sz nm */
- printf("[%s] %s %s %s\n",file_type,file_perms,file_size,file_info->name);
+ printf("[%s] %s %s %s\n",file_type,file_perms,file_size,CMD_LOCALE_FROM_UTF8_ALLOCA(file_info->name));
g_free(file_size);
}
{
g_return_if_fail(!errp || !*errp);
- printf("Filename: %s\n",file_info->name);
+ printf("Filename: %s\n",CMD_LOCALE_FROM_UTF8_ALLOCA(file_info->name));
fputs("File type: ",stdout);
switch (!(file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE) ? GNOME_VFS_FILE_TYPE_UNKNOWN : file_info->type) {
#include <captive/client-file.h>
#include "handle.h" /* self */
+#include "utf8.h"
GQuark cmdline_handle_error_quark(void)
if (!(r=g_hash_table_lookup(handle_hash,handle_name)))
g_set_error(errp,CMDLINE_HANDLE_ERROR,CMDLINE_HANDLE_ERROR_LOOKUP,
- _("Error looking up existing handle: %s"),handle_name);
+ _("Error looking up existing handle: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(handle_name));
return r;
}
if (!(r=!g_hash_table_lookup(handle_hash,handle_name)))
g_set_error(errp,CMDLINE_HANDLE_ERROR,CMDLINE_HANDLE_ERROR_ALREADY_USED,
- _("Specified handle already used: %s"),handle_name);
+ _("Specified handle already used: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(handle_name));
return r;
}
if (!g_hash_table_remove(handle_hash,handle_name)) {
g_set_error(errp,CMDLINE_HANDLE_ERROR,CMDLINE_HANDLE_ERROR_DELETE,
- _("Handle to be deleted not found: %s"),handle_name);
+ _("Handle to be deleted not found: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(handle_name));
return;
}
#include "cmd_close.h"
#include "cmd_quit.h"
#include "cmd_help.h"
+#include "utf8.h"
CaptiveVfsObject *cmdline_captive_vfs_object;
poptContext cmd_context;
int errint;
const char **cmdarg_argv;
-int cmdarg_argc;
-const char **csp;
+int cmdarg_argc,argci;
+const char **csp,*cs;
const char *emptyargv_NULL=NULL;
g_return_if_fail(cmd_argc>=0);
cmd_argv=stub_shell;
}
+ for (argci=0;argci<cmd_argc;argci++) {
+ if ((cs=CMD_LOCALE_TO_UTF8_ALLOCA(cmd_argv[argci])))
+ cmd_argv[argci]=cs;
+ }
+
cmd_name=*cmd_argv;
for (commandp=cmdline_command_table;commandp->name;commandp++) {
if (!cmd_name /* NULL cmd_name fallback to the first table entry - "shell" */
}
if (!commandp->name) {
g_set_error(errp,CMDLINE_MAIN_ERROR,CMDLINE_MAIN_ERROR_UNKNOWN_COMMAND,
- _("Unknown command, try 'help': %s"),cmd_name);
+ _("Unknown command, try 'help': %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(cmd_name));
return;
}
displayArgs_hit=FALSE;
POPT_CONTEXT_POSIXMEHARDER); /* flags; !POPT_CONTEXT_KEEP_FIRST */
if (cmd_context==NULL) {
g_set_error(errp,CMDLINE_MAIN_ERROR,CMDLINE_MAIN_ERROR_INVALID_COMMAND_ARGUMENTS,
- _("Invalid arguments for command: %s"),cmd_name);
+ _("Invalid arguments for command: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(cmd_name));
return;
}
errint=poptReadDefaultConfig(cmd_context,
TRUE); /* useEnv */
if (errint!=0) {
g_set_error(errp,CMDLINE_MAIN_ERROR,CMDLINE_MAIN_ERROR_READING_COMMAND_CONFIG,
- _("Error '%s' reading default configuration for command: %s"),poptStrerror(errint),cmd_name);
+ _("Error '%s' reading default configuration for command: %s"),
+ poptStrerror(errint),CMD_LOCALE_FROM_UTF8_ALLOCA(cmd_name));
goto err_free_context;
}
errint=poptGetNextOpt(cmd_context);
if (errint!=-1) {
g_set_error(errp,CMDLINE_MAIN_ERROR,CMDLINE_MAIN_ERROR_EXCEEDING_COMMAND_OPTION,
- _("Exceeding command option for command: %s"),cmd_name);
+ _("Exceeding command option for command: %s"),CMD_LOCALE_FROM_UTF8_ALLOCA(cmd_name));
goto err_free_context;
}
if (!(cmdarg_argv=poptGetArgs(cmd_context)))
if (cmdarg_argc<commandp->argsn_min || cmdarg_argc>commandp->argsn_max) {
g_set_error(errp,CMDLINE_MAIN_ERROR,CMDLINE_MAIN_ERROR_INVALID_COMMAND_ARGUMENT_COUNT,
_("Invalid number of command '%s' arguments: %d; expected from %d to %d incl."),
- cmd_name,cmdarg_argc,commandp->argsn_min,commandp->argsn_max);
+ CMD_LOCALE_FROM_UTF8_ALLOCA(cmd_name),cmdarg_argc,commandp->argsn_min,commandp->argsn_max);
goto err_free_context;
}
--- /dev/null
+/* $Id$
+ * client cmdline interface GnomeVFSFileInfo utils for libcaptive
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "config.h"
+
+#include <glib/gmessages.h>
+#include <glib/gerror.h>
+
+
+#include "utf8.h" /* self */
+
+
+gchar *cmd_utf8_macro_malloc_errorchecking(
+ gchar *(*func)(const gchar *string,gssize len,gsize *bytes_read,gsize *bytes_written,GError **error),
+ const gchar *string)
+{
+GError *error;
+gchar *r;
+
+ g_return_val_if_fail(func!=NULL,NULL);
+ g_return_val_if_fail(string!=NULL,NULL);
+
+ error=NULL;
+ r=(*func)(
+ string, /* opsysstring/utf8string */
+ -1, /* len; '\0'-terminated */
+ NULL, /* bytes_read */
+ NULL, /* bytes_written */
+ &error); /* error */
+ if (error) {
+ g_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING,"captivefs g_filename_from_utf8(): name=\"%s\": %s",
+ string,error->message);
+ g_clear_error(&error);
+ }
+ return r;
+}
--- /dev/null
+/* $Id$
+ * Include file for client cmdline interface GnomeVFSFileInfo utils for libcaptive
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef _CAPTIVE_CLIENT_CMDLINE_UTF8_H
+#define _CAPTIVE_CLIENT_CMDLINE_UTF8_H 1
+
+
+#include <captive/macros.h>
+#include <glib/gconvert.h>
+#include <glib/gtypes.h>
+
+
+gchar *cmd_utf8_macro_malloc_errorchecking(
+ gchar *(*func)(const gchar *string,gssize len,gsize *bytes_read,gsize *bytes_written,GError **error),
+ const gchar *name);
+
+
+#define CMD_UTF8_MACRO_ALLOCA(func,string) ({ \
+ const gchar *_cmd_utf8_macro_alloca_string=(string); \
+ gchar *_cmd_utf8_macro_alloca_r_malloc; \
+ const gchar *_cmd_utf8_macro_alloca_r; \
+ \
+ _cmd_utf8_macro_alloca_r_malloc=cmd_utf8_macro_malloc_errorchecking( \
+ func, \
+ _cmd_utf8_macro_alloca_string); \
+ if (!_cmd_utf8_macro_alloca_r_malloc) \
+ _cmd_utf8_macro_alloca_r=_cmd_utf8_macro_alloca_string; \
+ else { \
+ _cmd_utf8_macro_alloca_r=captive_strdup_alloca(_cmd_utf8_macro_alloca_r_malloc); \
+ g_free(_cmd_utf8_macro_alloca_r_malloc); \
+ } \
+ _cmd_utf8_macro_alloca_r; \
+ })
+
+
+#define CMD_FILENAME_TO_UTF8_ALLOCA(string) CMD_UTF8_MACRO_ALLOCA(g_filename_to_utf8,(string))
+#define CMD_FILENAME_FROM_UTF8_ALLOCA(string) CMD_UTF8_MACRO_ALLOCA(g_filename_from_utf8,(string))
+#define CMD_LOCALE_TO_UTF8_ALLOCA(string) CMD_UTF8_MACRO_ALLOCA(g_locale_to_utf8,(string))
+#define CMD_LOCALE_FROM_UTF8_ALLOCA(string) CMD_UTF8_MACRO_ALLOCA(g_locale_from_utf8,(string))
+
+
+#endif /* _CAPTIVE_CLIENT_CMDLINE_UTF8_H */
if (captivefs_vfs->options.debug_messages)
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_readdir: dir_name=%s",dir_name);
+ dir_name=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(dir_name);
+
G_LOCK(libcaptive);
errvfsresult=captive_directory_new_open(&captive_directory_object,captivefs_vfs->captive_vfs_object,dir_name);
G_UNLOCK(libcaptive);
}
for (;;) {
+char *file_info_name_filename;
+int errint;
+
G_LOCK(libcaptive);
errvfsresult=captive_directory_read(captive_directory_object,&file_info);
G_UNLOCK(libcaptive);
if (!captivefs_GnomeVFSFileInfo_to_lufs_fattr(captivefs_vfs,&fattr,&file_info))
goto fail_unref;
- if (0>lu_cache_add2dir(ddir,file_info.name,NULL,&fattr)) {
+ file_info_name_filename=captivefs_filename_from_utf8_malloc_errorchecking(file_info.name);
+ errint=lu_cache_add2dir(ddir,
+ (file_info_name_filename ? file_info_name_filename : file_info.name),
+ NULL,&fattr);
+ g_free(file_info_name_filename); /* may be NULL */
+ if (0>errint) {
g_warning("Failed lu_cache_add2dir() for: %s",file_info.name);
goto fail_unref;
}
if (captivefs_vfs->options.debug_messages)
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_mkdir: dir=%s,mode=0x%X",dir,mode);
+ dir=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(dir);
+
G_LOCK(libcaptive);
errvfsresult=captive_directory_new_make(&captive_directory_object,captivefs_vfs->captive_vfs_object,dir,mode);
G_UNLOCK(libcaptive);
if (captivefs_vfs->options.debug_messages)
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_rmdir: dir=%s",dir);
+ dir=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(dir);
+
G_LOCK(libcaptive);
errvfsresult=captive_directory_new_open(&captive_directory_object,captivefs_vfs->captive_vfs_object,dir);
G_UNLOCK(libcaptive);
#define CLIENT_LUFS_USE_COUNT "client-lufs-use_count"
-/* map: (const gchar *) -> (CaptiveFileObject *) */
+/* map: (const gchar *utf8) -> (CaptiveFileObject *) */
static GHashTable *FileHandle_hash;
G_LOCK_DEFINE_STATIC(FileHandle_hash);
if (captivefs_vfs->options.debug_messages)
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_stat: name=%s",name);
+ name=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(name);
+
captive_file_object=FileHandle_lookup_open_enter(captivefs_vfs,name,FALSE);
if (!captive_file_object)
return -1;
if (captivefs_vfs->options.debug_messages)
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_create: file=%s,mode=0x%X",file,mode);
+ file=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(file);
+
captive_file_object=FileHandle_lookup_open_enter(captivefs_vfs,file,TRUE);
if (!captive_file_object)
return -1;
if (captivefs_vfs->options.debug_messages)
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_unlink: file=%s",file);
+ file=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(file);
+
captive_file_object=FileHandle_lookup_open_enter(captivefs_vfs,file,FALSE);
if (!captive_file_object)
return -1;
if (captivefs_vfs->options.debug_messages)
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_rename: old_name=%s,new_name=%s",old_name,new_name);
+ old_name=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(old_name);
+ new_name=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(new_name);
+
captive_file_object=FileHandle_lookup_open_enter(captivefs_vfs,old_name,FALSE);
if (!captive_file_object)
return -1;
if (captivefs_vfs->options.debug_messages)
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_open: file=%s,mode=0x%X",file,mode);
+ file=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(file);
+
if (!captivefs_vfs_validate(captivefs_vfs))
return -1;
if (captivefs_vfs->options.debug_messages)
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_release: file=%s",file);
+ file=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(file);
+
if (!(captive_file_object=FileHandle_lookup_enter(file)))
return -1;
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_read: file=%s,offset=%" G_GINT64_FORMAT ",count=0x%lX",
file,(gint64)offset,count);
+ file=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(file);
+
if (!(captive_file_object=FileHandle_lookup_enter(file)))
return -1;
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_write: file=%s,offset=%" G_GINT64_FORMAT ",count=0x%lX",
file,(gint64)offset,count);
+ file=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(file);
+
if (!(captive_file_object=FileHandle_lookup_enter(file)))
return -1;
if (captivefs_vfs->options.debug_messages)
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_setattr: file=%s",file);
+ file=CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(file);
+
if (!captivefs_lufs_fattr_to_GnomeVFSFileInfo(&file_info,fattr))
return -1;
return -1; /* unsupported by W32 */
}
+
+
+char *captivefs_filename_to_utf8_malloc_errorchecking(const char *name)
+{
+GError *error;
+char *r;
+
+ g_return_val_if_fail(name!=NULL,NULL);
+
+ error=NULL;
+ r=g_filename_to_utf8(
+ name, /* opsysstring */
+ -1, /* len; '\0'-terminated */
+ NULL, /* bytes_read */
+ NULL, /* bytes_written */
+ &error); /* error */
+ if (error) {
+ g_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING,
+ _("captivefs %s(): name=\"%s\": %s (see locale(7) and mount(8) environment variables)"),
+ "g_filename_to_utf8",name,error->message);
+ g_clear_error(&error);
+ }
+ return r;
+}
+
+
+char *captivefs_filename_from_utf8_malloc_errorchecking(const char *name)
+{
+GError *error;
+char *r;
+
+ g_return_val_if_fail(name!=NULL,NULL);
+
+ error=NULL;
+ r=g_filename_from_utf8(
+ name, /* utf8string */
+ -1, /* len; '\0'-terminated */
+ NULL, /* bytes_read */
+ NULL, /* bytes_written */
+ &error); /* error */
+ if (error) {
+ g_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING,
+ _("captivefs %s(): name=\"%s\": %s (see locale(7) and mount(8) environment variables)"),
+ "g_filename_from_utf8",name,error->message);
+ g_clear_error(&error);
+ }
+ return r;
+}
#include <glib/gthread.h>
+#include <captive/macros.h>
G_BEGIN_DECLS
G_LOCK_EXTERN(libcaptive);
+
+char *captivefs_filename_to_utf8_malloc_errorchecking(const char *name);
+char *captivefs_filename_from_utf8_malloc_errorchecking(const char *name);
+
+#define CAPTIVEFS_FILENAME_TO_UTF8_ALLOCA(name) ({ \
+ const char *_captivefs_filename_to_utf8_alloca_name=(name); \
+ char *_captivefs_filename_to_utf8_alloca_r_malloc; \
+ const char *_captivefs_filename_to_utf8_alloca_r; \
+ \
+ _captivefs_filename_to_utf8_alloca_r_malloc=captivefs_filename_to_utf8_malloc_errorchecking( \
+ _captivefs_filename_to_utf8_alloca_name); \
+ if (!_captivefs_filename_to_utf8_alloca_r_malloc) \
+ _captivefs_filename_to_utf8_alloca_r=_captivefs_filename_to_utf8_alloca_name; \
+ else { \
+ _captivefs_filename_to_utf8_alloca_r=captive_strdup_alloca(_captivefs_filename_to_utf8_alloca_r_malloc); \
+ g_free(_captivefs_filename_to_utf8_alloca_r_malloc); \
+ } \
+ _captivefs_filename_to_utf8_alloca_r; \
+ })
+
G_END_DECLS
#include <glib/gmessages.h>
#include "captivefs-misc.h"
#include <unistd.h>
+#include <locale.h>
#include <captive/client-vfs.h>
#include <captive/options.h>
}
G_UNLOCK(libcaptive);
+ /* Initialize i18n for proper nl_langinfo(CODESET) for _g_locale_charset_raw() for g_filename_from_utf8(). */
+ setlocale(LC_ALL,"");
+
if (!g_thread_supported())
g_thread_init(NULL); /* g_thread_init() fails on second initialization */