2 * Client fuse interface handling of 'GnomeVFSResult' for libcaptive
3 * Copyright (C) 2005 Jan Kratochvil <project-captive@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <libgnomevfs/gnome-vfs-result.h>
23 #include <glib/ghash.h>
24 #include <glib/gmessages.h>
28 #include "gnomevfsresult.h" /* self */
32 #define ERRNO_VALUE_MAX 0x400
35 /* map: GINT_TO_POINTER(GnomeVFSResult) -> GINT_TO_POINTER(errno) */
36 static GHashTable *gnomevfsresult_to_errno_hash;
38 static void gnomevfsresult_to_errno_hash_init(void)
42 if (gnomevfsresult_to_errno_hash)
44 gnomevfsresult_to_errno_hash=g_hash_table_new(g_direct_hash,g_direct_equal);
45 for (errno_i=1;errno_i<ERRNO_VALUE_MAX;errno_i++) {
46 GnomeVFSResult gnomevfsresult;
48 /* gnome_vfs_result_from_errno_code() returns 'GNOME_VFS_ERROR_GENERIC'
49 * for invalid input values.
51 gnomevfsresult=gnome_vfs_result_from_errno_code(errno_i);
52 if (GNOME_VFS_ERROR_GENERIC==gnomevfsresult)
55 gnomevfsresult_to_errno_hash, /* hash_table */
56 GINT_TO_POINTER(gnomevfsresult), /* key */
57 GINT_TO_POINTER(errno_i)); /* value */
61 int gnomevfsresult_to_errno(GnomeVFSResult gnomevfsresult)
65 g_return_val_if_fail(sizeof(GnomeVFSResult)<=sizeof(gint),EINVAL);
67 /* 'GNOME_VFS_OK' may map to NULL or fallback somehow or whatever weird. */
68 if (GNOME_VFS_OK==gnomevfsresult)
71 gnomevfsresult_to_errno_hash_init();
72 if (!(r=GPOINTER_TO_INT(g_hash_table_lookup(gnomevfsresult_to_errno_hash,GINT_TO_POINTER(gnomevfsresult))))) {
73 #if 0 /* Too many 'GnomeVFSResult's have no corresponding 'errno' value: */
74 g_error(_("Unable to translate GnomeVFSResult %d back to errno"),(int)gnomevfsresult);