[glib: 12/24] gioerror: Rely on GFileError to compute GIOErrorEnum from errno
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 12/24] gioerror: Rely on GFileError to compute GIOErrorEnum from errno
- Date: Thu, 23 Jun 2022 11:49:59 +0000 (UTC)
commit 2a05fd0cb0758ee379fde7609e54264e53867e05
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Wed Jun 22 19:51:41 2022 +0200
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.
gio/gioerror.c | 120 ++++-----------------------------------------------------
1 file changed, 8 insertions(+), 112 deletions(-)
---
diff --git a/gio/gioerror.c b/gio/gioerror.c
index bcb5e4bc1b..b4c0e70d98 100644
--- a/gio/gioerror.c
+++ b/gio/gioerror.c
@@ -73,91 +73,23 @@ G_DEFINE_QUARK (g-io-error-quark, g_io_error)
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
+ GFileError file_error;
+ GIOErrorEnum io_error;
-#ifdef ENOTDIR
- case ENOTDIR:
- return G_IO_ERROR_NOT_DIRECTORY;
- break;
-#endif
+ file_error = g_file_error_from_errno (err_no);
+ io_error = g_io_error_from_file_error (file_error);
-#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
+ if (io_error != G_IO_ERROR_FAILED)
+ return io_error;
+ switch (err_no)
+ {
#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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]