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
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)
{
#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
case EMLINK:
return G_IO_ERROR_TOO_MANY_LINKS;
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 ENOMSG
case ENOMSG:
return G_IO_ERROR_INVALID_DATA;
@ -176,12 +108,6 @@ g_io_error_from_errno (gint err_no)
break;
#endif
#ifdef EPERM
case EPERM:
return G_IO_ERROR_PERMISSION_DENIED;
break;
#endif
#ifdef ECANCELED
case ECANCELED:
return G_IO_ERROR_CANCELLED;
@ -232,12 +158,6 @@ g_io_error_from_errno (gint err_no)
break;
#endif
#ifdef ENOSYS
case ENOSYS:
return G_IO_ERROR_NOT_SUPPORTED;
break;
#endif
#ifdef ETIMEDOUT
case ETIMEDOUT:
return G_IO_ERROR_TIMED_OUT;
@ -250,12 +170,6 @@ g_io_error_from_errno (gint err_no)
break;
#endif
#ifdef ETXTBSY
case ETXTBSY:
return G_IO_ERROR_BUSY;
break;
#endif
#ifdef EWOULDBLOCK
case EWOULDBLOCK:
return G_IO_ERROR_WOULD_BLOCK;
@ -269,18 +183,6 @@ g_io_error_from_errno (gint err_no)
break;
#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
case EADDRINUSE:
return G_IO_ERROR_ADDRESS_IN_USE;
@ -311,12 +213,6 @@ g_io_error_from_errno (gint err_no)
break;
#endif
#ifdef EPIPE
case EPIPE:
return G_IO_ERROR_BROKEN_PIPE;
break;
#endif
#ifdef ECONNRESET
case ECONNRESET:
return G_IO_ERROR_CONNECTION_CLOSED;