1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* gnome-vfs-error.c - Error handling for the GNOME Virtual File System.
4 Copyright (C) 1999 Free Software Foundation
6 The Gnome Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The Gnome Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the Gnome Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
21 Author: Ettore Perazzoli <ettore@gnu.org>
25 #include "gnome-vfs-result.h"
27 #include "gnome-vfs-i18n.h"
28 #include <glib/gtypes.h>
34 static char *status_strings[] = {
35 /* GNOME_VFS_OK */ N_("No error"),
36 /* GNOME_VFS_ERROR_NOT_FOUND */ N_("File not found"),
37 /* GNOME_VFS_ERROR_GENERIC */ N_("Generic error"),
38 /* GNOME_VFS_ERROR_INTERNAL */ N_("Internal error"),
39 /* GNOME_VFS_ERROR_BAD_PARAMETERS */ N_("Invalid parameters"),
40 /* GNOME_VFS_ERROR_NOT_SUPPORTED */ N_("Unsupported operation"),
41 /* GNOME_VFS_ERROR_IO */ N_("I/O error"),
42 /* GNOME_VFS_ERROR_CORRUPTED_DATA */ N_("Data corrupted"),
43 /* GNOME_VFS_ERROR_WRONG_FORMAT */ N_("Format not valid"),
44 /* GNOME_VFS_ERROR_BAD_FILE */ N_("Bad file handle"),
45 /* GNOME_VFS_ERROR_TOO_BIG */ N_("File too big"),
46 /* GNOME_VFS_ERROR_NO_SPACE */ N_("No space left on device"),
47 /* GNOME_VFS_ERROR_READ_ONLY */ N_("Read-only file system"),
48 /* GNOME_VFS_ERROR_INVALID_URI */ N_("Invalid URI"),
49 /* GNOME_VFS_ERROR_NOT_OPEN */ N_("File not open"),
50 /* GNOME_VFS_ERROR_INVALID_OPEN_MODE */ N_("Open mode not valid"),
51 /* GNOME_VFS_ERROR_ACCESS_DENIED */ N_("Access denied"),
52 /* GNOME_VFS_ERROR_TOO_MANY_OPEN_FILES */ N_("Too many open files"),
53 /* GNOME_VFS_ERROR_EOF */ N_("End of file"),
54 /* GNOME_VFS_ERROR_NOT_A_DIRECTORY */ N_("Not a directory"),
55 /* GNOME_VFS_ERROR_IN_PROGRESS */ N_("Operation in progress"),
56 /* GNOME_VFS_ERROR_INTERRUPTED */ N_("Operation interrupted"),
57 /* GNOME_VFS_ERROR_FILE_EXISTS */ N_("File exists"),
58 /* GNOME_VFS_ERROR_LOOP */ N_("Looping links encountered"),
59 /* GNOME_VFS_ERROR_NOT_PERMITTED */ N_("Operation not permitted"),
60 /* GNOME_VFS_ERROR_IS_DIRECTORY */ N_("Is a directory"),
61 /* GNOME_VFS_ERROR_NO_MEMMORY */ N_("Not enough memory"),
62 /* GNOME_VFS_ERROR_HOST_NOT_FOUND */ N_("Host not found"),
63 /* GNOME_VFS_ERROR_INVALID_HOST_NAME */ N_("Host name not valid"),
64 /* GNOME_VFS_ERROR_HOST_HAS_NO_ADDRESS */ N_("Host has no address"),
65 /* GNOME_VFS_ERROR_LOGIN_FAILED */ N_("Login failed"),
66 /* GNOME_VFS_ERROR_CANCELLED */ N_("Operation cancelled"),
67 /* GNOME_VFS_ERROR_DIRECTORY_BUSY */ N_("Directory busy"),
68 /* GNOME_VFS_ERROR_DIRECTORY_NOT_EMPTY */ N_("Directory not empty"),
69 /* GNOME_VFS_ERROR_TOO_MANY_LINKS */ N_("Too many links"),
70 /* GNOME_VFS_ERROR_READ_ONLY_FILE_SYSTEM */ N_("Read only file system"),
71 /* GNOME_VFS_ERROR_NOT_SAME_FILE_SYSTEM */ N_("Not on the same file system"),
72 /* GNOME_VFS_ERROR_NAME_TOO_LONG */ N_("Name too long"),
73 /* GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE */ N_("Service not available"),
74 /* GNOME_VFS_ERROR_SERVICE_OBSOLETE */ N_("Request obsoletes service's data"),
75 /* GNOME_VFS_ERROR_PROTOCOL_ERROR */ N_("Protocol error"),
76 /* GNOME_VFS_ERROR_NO_MASTER_BROWSER */ N_("Could not find master browser"),
77 /* GNOME_VFS_ERROR_NO_DEFAULT */ N_("No default action associated"),
78 /* GNOME_VFS_ERROR_NO_HANDLER */ N_("No handler for URL scheme"),
79 /* GNOME_VFS_ERROR_PARSE */ N_("Error parsing command line"),
80 /* GNOME_VFS_ERROR_LAUNCH */ N_("Error launching command")
85 * gnome_vfs_result_from_errno_code
86 * @errno_code: integer of the same type as the system "errno"
88 * Converts a system errno value to a GnomeVFSResult.
90 * Return value: a GnomeVFSResult equivalent to @errno_code
93 gnome_vfs_result_from_errno_code (int errno_code)
95 /* Please keep these in alphabetical order. */
97 case E2BIG: return GNOME_VFS_ERROR_TOO_BIG;
98 case EACCES: return GNOME_VFS_ERROR_ACCESS_DENIED;
99 case EBUSY: return GNOME_VFS_ERROR_DIRECTORY_BUSY;
100 case EBADF: return GNOME_VFS_ERROR_BAD_FILE;
101 case EEXIST: return GNOME_VFS_ERROR_FILE_EXISTS;
102 case EFAULT: return GNOME_VFS_ERROR_INTERNAL;
103 case EFBIG: return GNOME_VFS_ERROR_TOO_BIG;
104 case EINTR: return GNOME_VFS_ERROR_INTERRUPTED;
105 case EINVAL: return GNOME_VFS_ERROR_BAD_PARAMETERS;
106 case EIO: return GNOME_VFS_ERROR_IO;
107 case EISDIR: return GNOME_VFS_ERROR_IS_DIRECTORY;
108 case ELOOP: return GNOME_VFS_ERROR_LOOP;
109 case EMFILE: return GNOME_VFS_ERROR_TOO_MANY_OPEN_FILES;
110 case EMLINK: return GNOME_VFS_ERROR_TOO_MANY_LINKS;
111 case ENFILE: return GNOME_VFS_ERROR_TOO_MANY_OPEN_FILES;
112 case ENOTEMPTY: return GNOME_VFS_ERROR_DIRECTORY_NOT_EMPTY;
113 case ENOENT: return GNOME_VFS_ERROR_NOT_FOUND;
114 case ENOMEM: return GNOME_VFS_ERROR_NO_MEMORY;
115 case ENOSPC: return GNOME_VFS_ERROR_NO_SPACE;
116 case ENOTDIR: return GNOME_VFS_ERROR_NOT_A_DIRECTORY;
117 case EPERM: return GNOME_VFS_ERROR_NOT_PERMITTED;
118 case EROFS: return GNOME_VFS_ERROR_READ_ONLY_FILE_SYSTEM;
119 case EXDEV: return GNOME_VFS_ERROR_NOT_SAME_FILE_SYSTEM;
120 /* FIXME bugzilla.eazel.com 1191: To be completed. */
121 default: return GNOME_VFS_ERROR_GENERIC;
126 * gnome_vfs_result_from_errno:
128 * Converts the system errno to a GnomeVFSResult.
130 * Return value: a GnomeVFSResult equivalent to the current system errno
133 gnome_vfs_result_from_errno (void)
135 return gnome_vfs_result_from_errno_code(errno);
140 * gnome_vfs_result_from_h_errno:
142 * Converts the system "h_errno" to a GnomeVFSResult (h_errno represents errors
143 * accessing and finding internet hosts)
145 * Return value: a GnomeVFSResult equivalent to the current system "h_errno"
148 gnome_vfs_result_from_h_errno (void)
151 case HOST_NOT_FOUND: return GNOME_VFS_ERROR_HOST_NOT_FOUND;
152 case NO_ADDRESS: return GNOME_VFS_ERROR_HOST_HAS_NO_ADDRESS;
153 case TRY_AGAIN: /* FIXME bugzilla.eazel.com 1190 */
154 case NO_RECOVERY: /* FIXME bugzilla.eazel.com 1190 */
156 return GNOME_VFS_ERROR_GENERIC;
161 * gnome_vfs_result_to_string:
162 * @result: the result to convert to a string
164 * Returns a string representation of @result, useful for debugging
165 * purposes, but probably not appropriate for passing to the user.
167 * Return value: a string representing @result
170 gnome_vfs_result_to_string (GnomeVFSResult result)
172 if ((guint) result >= (guint) (sizeof (status_strings)
173 / sizeof (*status_strings)))
174 return _("Unknown error");
176 return _(status_strings[(guint) result]);