2 * Client fuse interface operation "statfs" 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>
27 #include "gnomevfsresult.h" /* self */
31 #define ERRNO_VALUE_MAX 0x400
34 /* map: GINT_TO_POINTER(GnomeVFSResult) -> GINT_TO_POINTER(errno) */
35 static GHashTable *gnomevfsresult_to_errno_hash;
37 static void gnomevfsresult_to_errno_hash_init(void)
41 if (gnomevfsresult_to_errno_hash)
43 gnomevfsresult_to_errno_hash=g_hash_table_new(g_direct_hash,g_direct_equal);
44 for (errno_i=1;errno_i<ERRNO_VALUE_MAX;errno_i++) {
45 GnomeVFSResult gnomevfsresult;
47 /* gnome_vfs_result_from_errno_code() returns 'GNOME_VFS_ERROR_GENERIC'
48 * for invalid input values.
50 gnomevfsresult=gnome_vfs_result_from_errno_code(errno_i);
51 if (GNOME_VFS_ERROR_GENERIC==gnomevfsresult)
54 gnomevfsresult_to_errno_hash, /* hash_table */
55 GINT_TO_POINTER(gnomevfsresult), /* key */
56 GINT_TO_POINTER(errno_i)); /* value */
60 int gnomevfsresult_to_errno(GnomeVFSResult gnomevfsresult)
64 g_return_val_if_fail(sizeof(GnomeVFSResult)>sizeof(gint),EINVAL);
66 /* 'GNOME_VFS_OK' may map to NULL or fallback somehow or whatever weird. */
67 if (GNOME_VFS_OK==gnomevfsresult)
70 gnomevfsresult_to_errno_hash_init();
71 if (!(r=GPOINTER_TO_INT(g_hash_table_lookup(gnomevfsresult_to_errno_hash,GINT_TO_POINTER(gnomevfsresult))))) {
72 g_assert_not_reached();