2007-11-26 17:13:05 +01:00
|
|
|
/* GIO - GLib Input, Output and Streaming Library
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006-2007 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General
|
|
|
|
* Public License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Author: Alexander Larsson <alexl@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2008-06-22 17:10:51 +02:00
|
|
|
#include "config.h"
|
2007-11-26 17:13:05 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include "gioerror.h"
|
|
|
|
|
2007-11-28 13:39:07 +01:00
|
|
|
|
2007-11-27 15:00:13 +01:00
|
|
|
/**
|
|
|
|
* SECTION:gioerror
|
2007-11-28 07:43:33 +01:00
|
|
|
* @short_description: Error helper functions
|
2008-02-21 19:20:17 +01:00
|
|
|
* @include: gio/gio.h
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
2007-12-09 16:51:12 +01:00
|
|
|
* Contains helper functions for reporting errors to the user.
|
2007-11-27 15:00:13 +01:00
|
|
|
**/
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
/**
|
|
|
|
* g_io_error_quark:
|
2007-11-27 15:00:13 +01:00
|
|
|
*
|
|
|
|
* Gets the GIO Error Quark.
|
2007-11-26 17:13:05 +01:00
|
|
|
*
|
2007-11-27 15:00:13 +01:00
|
|
|
* Return value: a #GQuark.
|
2007-11-26 17:13:05 +01:00
|
|
|
**/
|
|
|
|
GQuark
|
|
|
|
g_io_error_quark (void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string ("g-io-error-quark");
|
|
|
|
}
|
|
|
|
|
2007-11-27 15:00:13 +01:00
|
|
|
/**
|
|
|
|
* g_io_error_from_errno:
|
|
|
|
* @err_no: Error number as defined in errno.h.
|
|
|
|
*
|
|
|
|
* Converts errno.h error codes into GIO error codes.
|
|
|
|
*
|
|
|
|
* Returns: #GIOErrorEnum value for the given errno.h error number.
|
|
|
|
**/
|
2007-11-26 17:13:05 +01:00
|
|
|
GIOErrorEnum
|
|
|
|
g_io_error_from_errno (gint err_no)
|
|
|
|
{
|
|
|
|
switch (err_no)
|
|
|
|
{
|
|
|
|
#ifdef EEXIST
|
|
|
|
case EEXIST:
|
|
|
|
return G_IO_ERROR_EXISTS;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EISDIR
|
|
|
|
case EISDIR:
|
|
|
|
return G_IO_ERROR_IS_DIRECTORY;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EACCES
|
|
|
|
case EACCES:
|
|
|
|
return G_IO_ERROR_PERMISSION_DENIED;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENAMETOOLONG
|
|
|
|
case ENAMETOOLONG:
|
|
|
|
return G_IO_ERROR_FILENAME_TOO_LONG;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENOENT
|
|
|
|
case ENOENT:
|
|
|
|
return G_IO_ERROR_NOT_FOUND;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENOTDIR
|
|
|
|
case ENOTDIR:
|
|
|
|
return G_IO_ERROR_NOT_DIRECTORY;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EROFS
|
|
|
|
case EROFS:
|
|
|
|
return G_IO_ERROR_READ_ONLY;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ELOOP
|
|
|
|
case ELOOP:
|
|
|
|
return G_IO_ERROR_TOO_MANY_LINKS;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENOSPC
|
|
|
|
case ENOSPC:
|
|
|
|
return G_IO_ERROR_NO_SPACE;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENOMEM
|
|
|
|
case ENOMEM:
|
|
|
|
return G_IO_ERROR_NO_SPACE;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EINVAL
|
|
|
|
case EINVAL:
|
|
|
|
return G_IO_ERROR_INVALID_ARGUMENT;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EPERM
|
|
|
|
case EPERM:
|
|
|
|
return G_IO_ERROR_PERMISSION_DENIED;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ECANCELED
|
|
|
|
case ECANCELED:
|
|
|
|
return G_IO_ERROR_CANCELLED;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2009-02-12 02:52:17 +01:00
|
|
|
#if defined(ENOTEMPTY) && (!defined (EEXIST) || (ENOTEMPTY != EEXIST))
|
2007-11-26 17:13:05 +01:00
|
|
|
case ENOTEMPTY:
|
|
|
|
return G_IO_ERROR_NOT_EMPTY;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENOTSUP
|
|
|
|
case ENOTSUP:
|
|
|
|
return G_IO_ERROR_NOT_SUPPORTED;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ETIMEDOUT
|
|
|
|
case ETIMEDOUT:
|
|
|
|
return G_IO_ERROR_TIMED_OUT;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EBUSY
|
|
|
|
case EBUSY:
|
|
|
|
return G_IO_ERROR_BUSY;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2009-01-29 16:55:11 +01:00
|
|
|
/* some magic to deal with EWOULDBLOCK and EAGAIN.
|
|
|
|
* apparently on HP-UX these are actually defined to different values,
|
|
|
|
* but on Linux, for example, they are the same.
|
|
|
|
*/
|
|
|
|
#if defined(EWOULDBLOCK) && defined(EAGAIN) && EWOULDBLOCK == EAGAIN
|
|
|
|
/* we have both and they are the same: only emit one case. */
|
|
|
|
case EAGAIN:
|
|
|
|
return G_IO_ERROR_WOULD_BLOCK;
|
|
|
|
break;
|
|
|
|
#else
|
|
|
|
/* else: consider each of them separately. this handles both the
|
|
|
|
* case of having only one and the case where they are different values.
|
|
|
|
*/
|
|
|
|
# ifdef EAGAIN
|
|
|
|
case EAGAIN:
|
|
|
|
return G_IO_ERROR_WOULD_BLOCK;
|
|
|
|
break;
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# ifdef EWOULDBLOCK
|
2007-11-26 17:13:05 +01:00
|
|
|
case EWOULDBLOCK:
|
|
|
|
return G_IO_ERROR_WOULD_BLOCK;
|
|
|
|
break;
|
2009-01-29 16:55:11 +01:00
|
|
|
# endif
|
2007-11-26 17:13:05 +01:00
|
|
|
#endif
|
2009-01-08 02:32:15 +01:00
|
|
|
|
|
|
|
#ifdef EMFILE
|
|
|
|
case EMFILE:
|
|
|
|
return G_IO_ERROR_TOO_MANY_OPEN_FILES;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2009-05-14 15:26:37 +02:00
|
|
|
#ifdef EADDRINUSE
|
|
|
|
case EADDRINUSE:
|
|
|
|
return G_IO_ERROR_ADDRESS_IN_USE;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2010-04-28 21:39:56 +02:00
|
|
|
#ifdef EHOSTUNREACH
|
|
|
|
case EHOSTUNREACH:
|
|
|
|
return G_IO_ERROR_HOST_UNREACHABLE;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENETUNREACH
|
|
|
|
case ENETUNREACH:
|
|
|
|
return G_IO_ERROR_NETWORK_UNREACHABLE;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ECONNREFUSED
|
|
|
|
case ECONNREFUSED:
|
|
|
|
return G_IO_ERROR_CONNECTION_REFUSED;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2007-11-26 17:13:05 +01:00
|
|
|
default:
|
|
|
|
return G_IO_ERROR_FAILED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-11-28 13:39:07 +01:00
|
|
|
|
2010-04-19 10:32:05 +02:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_io_error_from_win32_error:
|
|
|
|
* @error_code: Windows error number.
|
|
|
|
*
|
|
|
|
* Converts some common error codes into GIO error codes. The
|
|
|
|
* fallback value G_IO_ERROR_FAILED is returned for error codes not
|
|
|
|
* handled.
|
|
|
|
*
|
|
|
|
* Returns: #GIOErrorEnum value for the given error number.
|
|
|
|
*
|
|
|
|
* Since: 2.26
|
|
|
|
**/
|
|
|
|
GIOErrorEnum
|
|
|
|
g_io_error_from_win32_error (gint error_code)
|
|
|
|
{
|
|
|
|
switch (error_code)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
return G_IO_ERROR_FAILED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|