/* $Id$ * client cmdline interface command "create" for libcaptive * Copyright (C) 2003 Jan Kratochvil * * 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 #include #include #include #include "cmd_create.h" /* self */ #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) { GQuark r=0; if (!r) r=g_quark_from_static_string("cmdline-cmd-create"); return r; } static int optarg_read; static int optarg_write; static int optarg_random; static int optarg_exclusive; static int optarg_read_only; const struct poptOption cmd_create_table[]={ CMDLINE_POPT("read",'r',POPT_ARG_NONE,&optarg_read, N_("Create file with 'GNOME_VFS_OPEN_READ' disposition flag"),NULL), CMDLINE_POPT("write",'w',POPT_ARG_NONE,&optarg_write, N_("Create file with 'GNOME_VFS_OPEN_WRITE' disposition flag"),NULL), CMDLINE_POPT("random",'R',POPT_ARG_NONE,&optarg_random, N_("Create file with 'GNOME_VFS_OPEN_RANDOM' disposition flag"),NULL), CMDLINE_POPT("exclusive",'x',POPT_ARG_NONE,&optarg_exclusive, N_("Create file with exclusive access rights"),NULL), CMDLINE_POPT("read-only",0,POPT_ARG_NONE,&optarg_read_only, N_("Create file with read-only access mode"),NULL), CMDLINE_POPT_AUTOHELP POPT_TABLEEND }; void cmd_create(const char **cmd_argv,GError **errp) { CaptiveFileObject *captive_file_object; const gchar *filename; GnomeVFSOpenMode mode; const gchar *handle_name; gboolean exclusive; gboolean read_only; g_return_if_fail(!errp || !*errp); handle_name=cmd_argv[0]; filename=cmdline_path_from_cwd(cmd_argv[1]); mode=0 | (!optarg_read ? 0 : GNOME_VFS_OPEN_READ) | (!optarg_write ? 0 : GNOME_VFS_OPEN_WRITE) | (!optarg_random ? 0 : GNOME_VFS_OPEN_RANDOM); optarg_read=0; optarg_write=0; optarg_random=0; exclusive=!!optarg_exclusive; optarg_exclusive=0; read_only=!!optarg_read_only; optarg_read_only=0; if (!handle_check_not_used(handle_name,errp)) return; if (!errvfsresult_to_gerr(errp,captive_file_new_create( &captive_file_object, /* captive_file_object_return */ cmdline_captive_vfs_object, /* captive_vfs_object */ filename, /* pathname */ mode, /* mode */ exclusive, /* exclusive */ (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'"),CMD_LOCALE_FROM_UTF8_ALLOCA(filename)); return; } handle_set(handle_name,captive_file_object); g_object_unref(captive_file_object); }