aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2022-08-26 15:38:26 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2022-09-21 14:11:03 -0400
commitb872057a63c53106e4bf6033a52d53b988f30dfd (patch)
tree0178e5e9ae12af553f15c2e13cac0eb61e1cdafc /gdbsupport
parent198f946ffe9fbfeeb187531e57cab6c3fd9d8b3d (diff)
downloadgdb-b872057a63c53106e4bf6033a52d53b988f30dfd.zip
gdb-b872057a63c53106e4bf6033a52d53b988f30dfd.tar.gz
gdb-b872057a63c53106e4bf6033a52d53b988f30dfd.tar.bz2
gdbsupport: convert FILEIO_* macros to an enum
Converting from free-form macros to an enum gives a bit of type-safety. This caught places where we would assign host error numbers to what should contain a target fileio error number, for instance in target_fileio_pread. I added the FILEIO_SUCCESS enumerator, because remote.c:remote_hostio_parse_result initializes the remote_errno output variable to 0. It seems better to have an explicit enumerator than to assign a value for which there is no enumerator. I considered initializing this variable to FILEIO_EUNKNOWN instead, such that if the remote side replies with an error and omits the errno value, we'll get an errno that represents an error instead of 0 (which reprensents no error). But it's not clear what the consequences of that change would be, so I prefer to err on the side of caution and just keep the existing behavior (there is no intended change in behavior with this patch). Note that remote_hostio_parse_resul still reads blindly what the remote side sends as a target errno into this variable, so we can still end up with a nonsensical value here. It's not good, but out of the scope of this patch. Convert host_to_fileio_error and fileio_errno_to_host to return / accept a fileio_error instead of an int, and cascade the change in the whole chain that uses that. Change-Id: I454b0e3fcf0732447bc872252fa8e57d138b0e03
Diffstat (limited to 'gdbsupport')
-rw-r--r--gdbsupport/fileio.cc2
-rw-r--r--gdbsupport/fileio.h50
2 files changed, 28 insertions, 24 deletions
diff --git a/gdbsupport/fileio.cc b/gdbsupport/fileio.cc
index b4feb85..db7c1a7 100644
--- a/gdbsupport/fileio.cc
+++ b/gdbsupport/fileio.cc
@@ -24,7 +24,7 @@
/* See fileio.h. */
-int
+fileio_error
host_to_fileio_error (int error)
{
switch (error)
diff --git a/gdbsupport/fileio.h b/gdbsupport/fileio.h
index 9809c16..6a5297c 100644
--- a/gdbsupport/fileio.h
+++ b/gdbsupport/fileio.h
@@ -67,28 +67,32 @@
#define FILEIO_SEEK_END 2
/* errno values */
-#define FILEIO_EPERM 1
-#define FILEIO_ENOENT 2
-#define FILEIO_EINTR 4
-#define FILEIO_EIO 5
-#define FILEIO_EBADF 9
-#define FILEIO_EACCES 13
-#define FILEIO_EFAULT 14
-#define FILEIO_EBUSY 16
-#define FILEIO_EEXIST 17
-#define FILEIO_ENODEV 19
-#define FILEIO_ENOTDIR 20
-#define FILEIO_EISDIR 21
-#define FILEIO_EINVAL 22
-#define FILEIO_ENFILE 23
-#define FILEIO_EMFILE 24
-#define FILEIO_EFBIG 27
-#define FILEIO_ENOSPC 28
-#define FILEIO_ESPIPE 29
-#define FILEIO_EROFS 30
-#define FILEIO_ENOSYS 88
-#define FILEIO_ENAMETOOLONG 91
-#define FILEIO_EUNKNOWN 9999
+enum fileio_error
+{
+ FILEIO_SUCCESS = 0,
+ FILEIO_EPERM = 1,
+ FILEIO_ENOENT = 2,
+ FILEIO_EINTR = 4,
+ FILEIO_EIO = 5,
+ FILEIO_EBADF = 9,
+ FILEIO_EACCES = 13,
+ FILEIO_EFAULT = 14,
+ FILEIO_EBUSY = 16,
+ FILEIO_EEXIST = 17,
+ FILEIO_ENODEV = 19,
+ FILEIO_ENOTDIR = 20,
+ FILEIO_EISDIR = 21,
+ FILEIO_EINVAL = 22,
+ FILEIO_ENFILE = 23,
+ FILEIO_EMFILE = 24,
+ FILEIO_EFBIG = 27,
+ FILEIO_ENOSPC = 28,
+ FILEIO_ESPIPE = 29,
+ FILEIO_EROFS = 30,
+ FILEIO_ENOSYS = 88,
+ FILEIO_ENAMETOOLONG = 91,
+ FILEIO_EUNKNOWN = 9999,
+};
#define FIO_INT_LEN 4
#define FIO_UINT_LEN 4
@@ -133,7 +137,7 @@ struct fio_timeval
/* Convert a host-format errno value to a File-I/O error number. */
-extern int host_to_fileio_error (int error);
+extern fileio_error host_to_fileio_error (int error);
/* Convert File-I/O open flags FFLAGS to host format, storing
the result in *FLAGS. Return 0 on success, -1 on error. */