X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fgioerror.c;h=0faff254d35b312a41b47b1059bce79424acdfed;hb=a3d86afa81ff34ce797a3928fd619ead219a37af;hp=bbd51d9d1dfab1233a847f7e8ef858eb670ad170;hpb=20f4d1820b8d4d0fc4447188e33efffd6d4a88d8;p=platform%2Fupstream%2Fglib.git diff --git a/gio/gioerror.c b/gio/gioerror.c index bbd51d9..0faff25 100644 --- a/gio/gioerror.c +++ b/gio/gioerror.c @@ -22,6 +22,9 @@ #include #include "gioerror.h" +#ifdef G_OS_WIN32 +#include +#endif /** * SECTION:gioerror @@ -44,7 +47,10 @@ G_DEFINE_QUARK (g-io-error-quark, g_io_error) * g_io_error_from_errno: * @err_no: Error number as defined in errno.h. * - * Converts errno.h error codes into GIO error codes. + * Converts errno.h error codes into GIO error codes. The fallback + * value %G_IO_ERROR_FAILED is returned for error codes not currently + * handled (but note that future GLib releases may return a more + * specific value instead). * * Returns: #GIOErrorEnum value for the given errno.h error number. **/ @@ -131,7 +137,8 @@ g_io_error_from_errno (gint err_no) break; #endif -#if defined(ENOTEMPTY) && (!defined (EEXIST) || (ENOTEMPTY != EEXIST)) + /* ENOTEMPTY == EEXIST on AIX for backward compatibility reasons */ +#if defined (ENOTEMPTY) && (!defined (EEXIST) || (ENOTEMPTY != EEXIST)) case ENOTEMPTY: return G_IO_ERROR_NOT_EMPTY; break; @@ -143,6 +150,37 @@ g_io_error_from_errno (gint err_no) break; #endif + /* EOPNOTSUPP == ENOTSUP on Linux, but POSIX considers them distinct */ +#if defined (EOPNOTSUPP) && (!defined (ENOTSUP) || (EOPNOTSUPP != ENOTSUP)) + case EOPNOTSUPP: + return G_IO_ERROR_NOT_SUPPORTED; + break; +#endif + +#ifdef EPROTONOSUPPORT + case EPROTONOSUPPORT: + return G_IO_ERROR_NOT_SUPPORTED; + break; +#endif + +#ifdef ESOCKTNOSUPPORT + case ESOCKTNOSUPPORT: + return G_IO_ERROR_NOT_SUPPORTED; + break; +#endif + +#ifdef EPFNOSUPPORT + case EPFNOSUPPORT: + return G_IO_ERROR_NOT_SUPPORTED; + break; +#endif + +#ifdef EAFNOSUPPORT + case EAFNOSUPPORT: + return G_IO_ERROR_NOT_SUPPORTED; + break; +#endif + #ifdef ETIMEDOUT case ETIMEDOUT: return G_IO_ERROR_TIMED_OUT; @@ -155,30 +193,17 @@ g_io_error_from_errno (gint err_no) break; #endif -/* 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: +#ifdef EWOULDBLOCK + case EWOULDBLOCK: return G_IO_ERROR_WOULD_BLOCK; break; -# endif +#endif -# ifdef EWOULDBLOCK - case EWOULDBLOCK: + /* EWOULDBLOCK == EAGAIN on most systems, but POSIX considers them distinct */ +#if defined (EAGAIN) && (!defined (EWOULDBLOCK) || (EWOULDBLOCK != EAGAIN)) + case EAGAIN: return G_IO_ERROR_WOULD_BLOCK; break; -# endif #endif #ifdef EMFILE @@ -217,6 +242,18 @@ g_io_error_from_errno (gint err_no) break; #endif +#ifdef ECONNRESET + case ECONNRESET: + return G_IO_ERROR_CONNECTION_CLOSED; + break; +#endif + +#ifdef ENOTCONN + case ENOTCONN: + return G_IO_ERROR_NOT_CONNECTED; + break; +#endif + default: return G_IO_ERROR_FAILED; break; @@ -229,9 +266,15 @@ g_io_error_from_errno (gint err_no) * 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. + * Converts some common error codes (as returned from GetLastError() + * or WSAGetLastError()) into GIO error codes. The fallback value + * %G_IO_ERROR_FAILED is returned for error codes not currently + * handled (but note that future GLib releases may return a more + * specific value instead). + * + * You can use g_win32_error_message() to get a localized string + * corresponding to @error_code. (But note that unlike g_strerror(), + * g_win32_error_message() returns a string that must be freed.) * * Returns: #GIOErrorEnum value for the given error number. * @@ -240,11 +283,48 @@ g_io_error_from_errno (gint err_no) GIOErrorEnum g_io_error_from_win32_error (gint error_code) { + /* Note: Winsock errors are a subset of Win32 error codes as a + * whole. (The fact that the Winsock API makes them look like they + * aren't is just because the API predates Win32.) + */ + switch (error_code) { + case WSAEADDRINUSE: + return G_IO_ERROR_ADDRESS_IN_USE; + + case WSAEWOULDBLOCK: + return G_IO_ERROR_WOULD_BLOCK; + + case WSAEACCES: + return G_IO_ERROR_PERMISSION_DENIED; + + case WSA_INVALID_HANDLE: + case WSA_INVALID_PARAMETER: + case WSAEBADF: + case WSAENOTSOCK: + return G_IO_ERROR_INVALID_ARGUMENT; + + case WSAEPROTONOSUPPORT: + return G_IO_ERROR_NOT_SUPPORTED; + + case WSAECANCELLED: + return G_IO_ERROR_CANCELLED; + + case WSAESOCKTNOSUPPORT: + case WSAEOPNOTSUPP: + case WSAEPFNOSUPPORT: + case WSAEAFNOSUPPORT: + return G_IO_ERROR_NOT_SUPPORTED; + + case WSAECONNRESET: + return G_IO_ERROR_CONNECTION_CLOSED; + + case ERROR_PIPE_LISTENING: + return G_IO_ERROR_NOT_CONNECTED; + default: return G_IO_ERROR_FAILED; - break; } }