gioerror: Rely on GFileError to compute GIOErrorEnum from errno

Avoid re defining cases for GIoErrorEnum when we already handle them
through GFileError, so remove code duplication and just rely on
g_file_error_from_errno() to compute the file error and then use
g_io_error_from_file_error() to get the possible IOError.

In case it's something not handled as GFileError, we can use the same
logic as before.

This is now a safe change to do as we have covered all the supported
cases in tests.
This commit is contained in:
Marco Trevisan (Treviño) 2022-06-22 19:51:41 +02:00
parent b64fd312da
commit 2a05fd0cb0

View File

@ -73,91 +73,23 @@ G_DEFINE_QUARK (g-io-error-quark, g_io_error)
GIOErrorEnum GIOErrorEnum
g_io_error_from_errno (gint err_no) g_io_error_from_errno (gint err_no)
{ {
GFileError file_error;
GIOErrorEnum io_error;
file_error = g_file_error_from_errno (err_no);
io_error = g_io_error_from_file_error (file_error);
if (io_error != G_IO_ERROR_FAILED)
return io_error;
switch (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 ENXIO
case ENXIO:
return G_IO_ERROR_NOT_REGULAR_FILE;
break;
#endif
#ifdef ENODEV
case ENODEV:
return G_IO_ERROR_NO_SUCH_DEVICE;
#endif
#ifdef EROFS
case EROFS:
return G_IO_ERROR_READ_ONLY;
break;
#endif
#ifdef EMLINK #ifdef EMLINK
case EMLINK: case EMLINK:
return G_IO_ERROR_TOO_MANY_LINKS; return G_IO_ERROR_TOO_MANY_LINKS;
break; break;
#endif #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 ENOMSG #ifdef ENOMSG
case ENOMSG: case ENOMSG:
return G_IO_ERROR_INVALID_DATA; return G_IO_ERROR_INVALID_DATA;
@ -176,12 +108,6 @@ g_io_error_from_errno (gint err_no)
break; break;
#endif #endif
#ifdef EPERM
case EPERM:
return G_IO_ERROR_PERMISSION_DENIED;
break;
#endif
#ifdef ECANCELED #ifdef ECANCELED
case ECANCELED: case ECANCELED:
return G_IO_ERROR_CANCELLED; return G_IO_ERROR_CANCELLED;
@ -232,12 +158,6 @@ g_io_error_from_errno (gint err_no)
break; break;
#endif #endif
#ifdef ENOSYS
case ENOSYS:
return G_IO_ERROR_NOT_SUPPORTED;
break;
#endif
#ifdef ETIMEDOUT #ifdef ETIMEDOUT
case ETIMEDOUT: case ETIMEDOUT:
return G_IO_ERROR_TIMED_OUT; return G_IO_ERROR_TIMED_OUT;
@ -250,12 +170,6 @@ g_io_error_from_errno (gint err_no)
break; break;
#endif #endif
#ifdef ETXTBSY
case ETXTBSY:
return G_IO_ERROR_BUSY;
break;
#endif
#ifdef EWOULDBLOCK #ifdef EWOULDBLOCK
case EWOULDBLOCK: case EWOULDBLOCK:
return G_IO_ERROR_WOULD_BLOCK; return G_IO_ERROR_WOULD_BLOCK;
@ -269,18 +183,6 @@ g_io_error_from_errno (gint err_no)
break; break;
#endif #endif
#ifdef EMFILE
case EMFILE:
return G_IO_ERROR_TOO_MANY_OPEN_FILES;
break;
#endif
#ifdef ENFILE
case ENFILE:
return G_IO_ERROR_TOO_MANY_OPEN_FILES;
break;
#endif
#ifdef EADDRINUSE #ifdef EADDRINUSE
case EADDRINUSE: case EADDRINUSE:
return G_IO_ERROR_ADDRESS_IN_USE; return G_IO_ERROR_ADDRESS_IN_USE;
@ -311,12 +213,6 @@ g_io_error_from_errno (gint err_no)
break; break;
#endif #endif
#ifdef EPIPE
case EPIPE:
return G_IO_ERROR_BROKEN_PIPE;
break;
#endif
#ifdef ECONNRESET #ifdef ECONNRESET
case ECONNRESET: case ECONNRESET:
return G_IO_ERROR_CONNECTION_CLOSED; return G_IO_ERROR_CONNECTION_CLOSED;