From: Simon Marchi Date: Mon, 29 Aug 2022 16:19:40 +0000 (-0400) Subject: gdbsupport: move fileio_errno_to_host to fileio.{h,cc} and rename X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=517a63c2c48e5aaabe57de079e2d7f0bea09429b;p=binutils-gdb.git gdbsupport: move fileio_errno_to_host to fileio.{h,cc} and rename gdb_bfd.c and remote.c contain identical implementations of a fileio_error -> errno function. Factor that out to gdbsupport/fileio.{h,cc}. Rename it fileio_error_to_host, for symmetry with host_to_fileio_error. Change-Id: Ib9b8807683de2f809c94a5303e708acc2251a0df --- diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 14388159c52..7e743891aed 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -303,59 +303,6 @@ gdb_bfd_open_from_target_memory (CORE_ADDR addr, ULONGEST size, mem_bfd_iovec_stat); } -/* Return the system error number corresponding to ERRNUM. */ - -static int -fileio_errno_to_host (fileio_error errnum) -{ - switch (errnum) - { - case FILEIO_EPERM: - return EPERM; - case FILEIO_ENOENT: - return ENOENT; - case FILEIO_EINTR: - return EINTR; - case FILEIO_EIO: - return EIO; - case FILEIO_EBADF: - return EBADF; - case FILEIO_EACCES: - return EACCES; - case FILEIO_EFAULT: - return EFAULT; - case FILEIO_EBUSY: - return EBUSY; - case FILEIO_EEXIST: - return EEXIST; - case FILEIO_ENODEV: - return ENODEV; - case FILEIO_ENOTDIR: - return ENOTDIR; - case FILEIO_EISDIR: - return EISDIR; - case FILEIO_EINVAL: - return EINVAL; - case FILEIO_ENFILE: - return ENFILE; - case FILEIO_EMFILE: - return EMFILE; - case FILEIO_EFBIG: - return EFBIG; - case FILEIO_ENOSPC: - return ENOSPC; - case FILEIO_ESPIPE: - return ESPIPE; - case FILEIO_EROFS: - return EROFS; - case FILEIO_ENOSYS: - return ENOSYS; - case FILEIO_ENAMETOOLONG: - return ENAMETOOLONG; - } - return -1; -} - /* bfd_openr_iovec OPEN_CLOSURE data for gdb_bfd_open. */ struct gdb_bfd_open_closure { @@ -383,7 +330,7 @@ gdb_bfd_iovec_fileio_open (struct bfd *abfd, void *open_closure) &target_errno); if (fd == -1) { - errno = fileio_errno_to_host (target_errno); + errno = fileio_error_to_host (target_errno); bfd_set_error (bfd_error_system_call); return NULL; } @@ -417,7 +364,7 @@ gdb_bfd_iovec_fileio_pread (struct bfd *abfd, void *stream, void *buf, break; if (bytes == -1) { - errno = fileio_errno_to_host (target_errno); + errno = fileio_error_to_host (target_errno); bfd_set_error (bfd_error_system_call); return -1; } @@ -479,7 +426,7 @@ gdb_bfd_iovec_fileio_fstat (struct bfd *abfd, void *stream, result = target_fileio_fstat (fd, sb, &target_errno); if (result == -1) { - errno = fileio_errno_to_host (target_errno); + errno = fileio_error_to_host (target_errno); bfd_set_error (bfd_error_system_call); } diff --git a/gdb/remote.c b/gdb/remote.c index b57d26a70ed..2f6cb2d01ee 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -12715,61 +12715,10 @@ remote_target::filesystem_is_local () return false; } -static int -remote_fileio_errno_to_host (fileio_error errnum) -{ - switch (errnum) - { - case FILEIO_EPERM: - return EPERM; - case FILEIO_ENOENT: - return ENOENT; - case FILEIO_EINTR: - return EINTR; - case FILEIO_EIO: - return EIO; - case FILEIO_EBADF: - return EBADF; - case FILEIO_EACCES: - return EACCES; - case FILEIO_EFAULT: - return EFAULT; - case FILEIO_EBUSY: - return EBUSY; - case FILEIO_EEXIST: - return EEXIST; - case FILEIO_ENODEV: - return ENODEV; - case FILEIO_ENOTDIR: - return ENOTDIR; - case FILEIO_EISDIR: - return EISDIR; - case FILEIO_EINVAL: - return EINVAL; - case FILEIO_ENFILE: - return ENFILE; - case FILEIO_EMFILE: - return EMFILE; - case FILEIO_EFBIG: - return EFBIG; - case FILEIO_ENOSPC: - return ENOSPC; - case FILEIO_ESPIPE: - return ESPIPE; - case FILEIO_EROFS: - return EROFS; - case FILEIO_ENOSYS: - return ENOSYS; - case FILEIO_ENAMETOOLONG: - return ENAMETOOLONG; - } - return -1; -} - static char * remote_hostio_error (fileio_error errnum) { - int host_error = remote_fileio_errno_to_host (errnum); + int host_error = fileio_error_to_host (errnum); if (host_error == -1) error (_("Unknown remote I/O error %d"), errnum); diff --git a/gdbsupport/fileio.cc b/gdbsupport/fileio.cc index db7c1a7c488..60a08f64977 100644 --- a/gdbsupport/fileio.cc +++ b/gdbsupport/fileio.cc @@ -77,6 +77,59 @@ host_to_fileio_error (int error) /* See fileio.h. */ +int +fileio_error_to_host (fileio_error errnum) +{ + switch (errnum) + { + case FILEIO_EPERM: + return EPERM; + case FILEIO_ENOENT: + return ENOENT; + case FILEIO_EINTR: + return EINTR; + case FILEIO_EIO: + return EIO; + case FILEIO_EBADF: + return EBADF; + case FILEIO_EACCES: + return EACCES; + case FILEIO_EFAULT: + return EFAULT; + case FILEIO_EBUSY: + return EBUSY; + case FILEIO_EEXIST: + return EEXIST; + case FILEIO_ENODEV: + return ENODEV; + case FILEIO_ENOTDIR: + return ENOTDIR; + case FILEIO_EISDIR: + return EISDIR; + case FILEIO_EINVAL: + return EINVAL; + case FILEIO_ENFILE: + return ENFILE; + case FILEIO_EMFILE: + return EMFILE; + case FILEIO_EFBIG: + return EFBIG; + case FILEIO_ENOSPC: + return ENOSPC; + case FILEIO_ESPIPE: + return ESPIPE; + case FILEIO_EROFS: + return EROFS; + case FILEIO_ENOSYS: + return ENOSYS; + case FILEIO_ENAMETOOLONG: + return ENAMETOOLONG; + } + return -1; +} + +/* See fileio.h. */ + int fileio_to_host_openflags (int fileio_open_flags, int *open_flags_p) { diff --git a/gdbsupport/fileio.h b/gdbsupport/fileio.h index 6a5297c6433..203e671f3e7 100644 --- a/gdbsupport/fileio.h +++ b/gdbsupport/fileio.h @@ -139,6 +139,10 @@ struct fio_timeval extern fileio_error host_to_fileio_error (int error); +/* Convert a File-I/O error number to a host-format errno value. */ + +extern int fileio_error_to_host (fileio_error errnum); + /* Convert File-I/O open flags FFLAGS to host format, storing the result in *FLAGS. Return 0 on success, -1 on error. */