source: trunk/third/gnome-vfs/libgnomevfs/gnome-vfs-result.c @ 17128

Revision 17128, 5.8 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r17127, which included commits to RCS files with non-trunk default branches.
Line 
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.
3
4   Copyright (C) 1999 Free Software Foundation
5
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.
10
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.
15
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.
20
21   Author: Ettore Perazzoli <ettore@gnu.org>
22*/
23
24#include <config.h>
25#include "gnome-vfs-result.h"
26
27#include <netdb.h>
28#include <errno.h>
29
30#include "gnome-vfs.h"
31#include "gnome-vfs-private.h"
32
33
34extern int h_errno;
35
36
37static gchar *status_strings[] = {
38        /* GNOME_VFS_OK */                              N_("No error"),
39        /* GNOME_VFS_ERROR_NOT_FOUND */                 N_("File not found"),
40        /* GNOME_VFS_ERROR_GENERIC */                   N_("Generic error"),
41        /* GNOME_VFS_ERROR_INTERNAL */                  N_("Internal error"),
42        /* GNOME_VFS_ERROR_BAD_PARAMETERS */            N_("Invalid parameters"),
43        /* GNOME_VFS_ERROR_NOT_SUPPORTED */             N_("Unsupported operation"),
44        /* GNOME_VFS_ERROR_IO */                        N_("I/O error"),
45        /* GNOME_VFS_ERROR_CORRUPTED_DATA */            N_("Data corrupted"),
46        /* GNOME_VFS_ERROR_WRONG_FORMAT */              N_("Format not valid"),
47        /* GNOME_VFS_ERROR_BAD_FILE */                  N_("Bad file handle"),
48        /* GNOME_VFS_ERROR_TOO_BIG */                   N_("File too big"),
49        /* GNOME_VFS_ERROR_NO_SPACE */                  N_("No space left on device"),
50        /* GNOME_VFS_ERROR_READ_ONLY */                 N_("Read-only file system"),
51        /* GNOME_VFS_ERROR_INVALID_URI */               N_("Invalid URI"),
52        /* GNOME_VFS_ERROR_NOT_OPEN */                  N_("File not open"),
53        /* GNOME_VFS_ERROR_INVALID_OPEN_MODE */         N_("Open mode not valid"),
54        /* GNOME_VFS_ERROR_ACCESS_DENIED */             N_("Access denied"),
55        /* GNOME_VFS_ERROR_TOO_MANY_OPEN_FILES */       N_("Too many open files"),
56        /* GNOME_VFS_ERROR_EOF */                       N_("End of file"),
57        /* GNOME_VFS_ERROR_NOT_A_DIRECTORY */           N_("Not a directory"),
58        /* GNOME_VFS_ERROR_IN_PROGRESS */               N_("Operation in progress"),
59        /* GNOME_VFS_ERROR_INTERRUPTED */               N_("Operation interrupted"),
60        /* GNOME_VFS_ERROR_FILE_EXISTS */               N_("File exists"),
61        /* GNOME_VFS_ERROR_LOOP */                      N_("Looping links encountered"),
62        /* GNOME_VFS_ERROR_NOT_PERMITTED */             N_("Operation not permitted"),
63        /* GNOME_VFS_ERROR_IS_DIRECTORY */              N_("Is a directory"),
64        /* GNOME_VFS_ERROR_NO_MEMMORY */                N_("Not enough memory"),
65        /* GNOME_VFS_ERROR_HOST_NOT_FOUND */            N_("Host not found"),
66        /* GNOME_VFS_ERROR_INVALID_HOST_NAME */         N_("Host name not valid"),
67        /* GNOME_VFS_ERROR_HOST_HAS_NO_ADDRESS */       N_("Host has no address"),
68        /* GNOME_VFS_ERROR_LOGIN_FAILED */              N_("Login failed"),
69        /* GNOME_VFS_ERROR_CANCELLED */                 N_("Operation cancelled"),
70        /* GNOME_VFS_ERROR_DIRECTORY_BUSY */            N_("Directory busy"),
71        /* GNOME_VFS_ERROR_DIRECTORY_NOT_EMPTY */       N_("Directory not empty"),
72        /* GNOME_VFS_ERROR_TOO_MANY_LINKS */            N_("Too many links"),
73        /* GNOME_VFS_ERROR_READ_ONLY_FILE_SYSTEM */     N_("Read only file system"),
74        /* GNOME_VFS_ERROR_NOT_SAME_FILE_SYSTEM */      N_("Not on the same file system"),
75        /* GNOME_VFS_ERROR_NAME_TOO_LONG */             N_("Name too long"),
76        /* GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE */     N_("Service not available"),
77        /* GNOME_VFS_ERROR_SERVICE_OBSOLETE */          N_("Request obsoletes service's data"),
78        /* GNOME_VFS_ERROR_PROTOCOL_ERROR */            N_("Protocol error")
79};
80
81
82GnomeVFSResult
83gnome_vfs_result_from_errno_code (int errno_code)
84{
85        /* Please keep these in alphabetical order.  */
86        switch (errno_code) {
87        case E2BIG:     return GNOME_VFS_ERROR_TOO_BIG;
88        case EACCES:    return GNOME_VFS_ERROR_ACCESS_DENIED;
89        case EBUSY:     return GNOME_VFS_ERROR_DIRECTORY_BUSY;
90        case EBADF:     return GNOME_VFS_ERROR_BAD_FILE;
91        case EEXIST:    return GNOME_VFS_ERROR_FILE_EXISTS;
92        case EFAULT:    return GNOME_VFS_ERROR_INTERNAL;
93        case EFBIG:     return GNOME_VFS_ERROR_TOO_BIG;
94        case EINTR:     return GNOME_VFS_ERROR_INTERRUPTED;
95        case EINVAL:    return GNOME_VFS_ERROR_BAD_PARAMETERS;
96        case EIO:       return GNOME_VFS_ERROR_IO;
97        case EISDIR:    return GNOME_VFS_ERROR_IS_DIRECTORY;
98        case ELOOP:     return GNOME_VFS_ERROR_LOOP;
99        case EMFILE:    return GNOME_VFS_ERROR_TOO_MANY_OPEN_FILES;
100        case EMLINK:    return GNOME_VFS_ERROR_TOO_MANY_LINKS;
101        case ENFILE:    return GNOME_VFS_ERROR_TOO_MANY_OPEN_FILES;
102        case ENOTEMPTY: return GNOME_VFS_ERROR_DIRECTORY_NOT_EMPTY;
103        case ENOENT:    return GNOME_VFS_ERROR_NOT_FOUND;
104        case ENOMEM:    return GNOME_VFS_ERROR_NO_MEMORY;
105        case ENOSPC:    return GNOME_VFS_ERROR_NO_SPACE;
106        case ENOTDIR:   return GNOME_VFS_ERROR_NOT_A_DIRECTORY;
107        case EPERM:     return GNOME_VFS_ERROR_NOT_PERMITTED;
108        case EROFS:     return GNOME_VFS_ERROR_READ_ONLY_FILE_SYSTEM;
109        case EXDEV:     return GNOME_VFS_ERROR_NOT_SAME_FILE_SYSTEM;
110                /* FIXME bugzilla.eazel.com 1191: To be completed.  */
111        default:        return GNOME_VFS_ERROR_GENERIC;
112        }
113}
114
115GnomeVFSResult
116gnome_vfs_result_from_errno (void)
117{
118       return gnome_vfs_result_from_errno_code(errno);
119}
120 
121
122GnomeVFSResult
123gnome_vfs_result_from_h_errno (void)
124{
125        switch (h_errno) {
126        case HOST_NOT_FOUND:    return GNOME_VFS_ERROR_HOST_NOT_FOUND;
127        case NO_ADDRESS:        return GNOME_VFS_ERROR_HOST_HAS_NO_ADDRESS;
128        case TRY_AGAIN:         /* FIXME bugzilla.eazel.com 1190 */
129        case NO_RECOVERY:       /* FIXME bugzilla.eazel.com 1190 */
130        default:
131                return GNOME_VFS_ERROR_GENERIC;
132        }
133}
134
135
136const gchar *
137gnome_vfs_result_to_string (GnomeVFSResult error)
138{
139        if ((guint) error >= (guint) (sizeof (status_strings)
140                                      / sizeof (*status_strings)))
141                return _("Unknown error");
142
143        return _(status_strings[(guint) error]);
144}
Note: See TracBrowser for help on using the repository browser.