public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Simon Marchi <simark@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] gdbsupport: move fileio_errno_to_host to fileio.{h,cc} and rename
Date: Wed, 21 Sep 2022 18:13:27 +0000 (GMT)	[thread overview]
Message-ID: <20220921181327.2CA913858418@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=517a63c2c48e5aaabe57de079e2d7f0bea09429b

commit 517a63c2c48e5aaabe57de079e2d7f0bea09429b
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date:   Mon Aug 29 12:19:40 2022 -0400

    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:
---
 gdb/gdb_bfd.c        | 59 +++-------------------------------------------------
 gdb/remote.c         | 53 +---------------------------------------------
 gdbsupport/fileio.cc | 53 ++++++++++++++++++++++++++++++++++++++++++++++
 gdbsupport/fileio.h  |  4 ++++
 4 files changed, 61 insertions(+), 108 deletions(-)

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.  */

                 reply	other threads:[~2022-09-21 18:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220921181327.2CA913858418@sourceware.org \
    --to=simark@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).