This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Introduce new shared function fileio_to_host_openflags


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

commit 819843c7029916120aa2929f80e0d7276177a7fb
Author: Gary Benson <gbenson@redhat.com>
Date:   Tue Apr 21 12:07:54 2015 +0100

    Introduce new shared function fileio_to_host_openflags
    
    This commit introduces a new shared function to replace identical
    functions in GDB and gdbserver.

Diff:
---
 gdb/ChangeLog           |  8 ++++++++
 gdb/common/fileio.c     | 35 +++++++++++++++++++++++++++++++++++
 gdb/common/fileio.h     |  5 +++++
 gdb/gdbserver/ChangeLog |  6 ++++++
 gdb/gdbserver/hostio.c  | 34 +---------------------------------
 gdb/inf-child.c         | 37 +------------------------------------
 6 files changed, 56 insertions(+), 69 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index de21098..f5ef884 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2015-04-21  Gary Benson <gbenson@redhat.com>
+
+	* common/fileio.h (fileio_to_host_openflags): New declaration.
+	* common/fileio.c (fcntl.h): New include.
+	(fileio_to_host_openflags): New function, factored out from...
+	* inf-child.c (inf_child_fileio_open_flags_to_host): ...here.
+	Single use updated.
+
 2015-04-21  Kevin Buettner  <kevinb@redhat.com>
 
 	* rl78-tdep.c (RL78_SP_ADDR): Define.
diff --git a/gdb/common/fileio.c b/gdb/common/fileio.c
index 5d3e6ae..28335ec 100644
--- a/gdb/common/fileio.c
+++ b/gdb/common/fileio.c
@@ -20,6 +20,7 @@
 #include "common-defs.h"
 #include "fileio.h"
 #include <sys/stat.h>
+#include <fcntl.h>
 
 /* See fileio.h.  */
 
@@ -74,6 +75,40 @@ host_to_fileio_error (int error)
   return FILEIO_EUNKNOWN;
 }
 
+/* See fileio.h.  */
+
+int
+fileio_to_host_openflags (int fileio_open_flags, int *open_flags_p)
+{
+  int open_flags = 0;
+
+  if (fileio_open_flags & ~FILEIO_O_SUPPORTED)
+    return -1;
+
+  if (fileio_open_flags & FILEIO_O_CREAT)
+    open_flags |= O_CREAT;
+  if (fileio_open_flags & FILEIO_O_EXCL)
+    open_flags |= O_EXCL;
+  if (fileio_open_flags & FILEIO_O_TRUNC)
+    open_flags |= O_TRUNC;
+  if (fileio_open_flags & FILEIO_O_APPEND)
+    open_flags |= O_APPEND;
+  if (fileio_open_flags & FILEIO_O_RDONLY)
+    open_flags |= O_RDONLY;
+  if (fileio_open_flags & FILEIO_O_WRONLY)
+    open_flags |= O_WRONLY;
+  if (fileio_open_flags & FILEIO_O_RDWR)
+    open_flags |= O_RDWR;
+  /* On systems supporting binary and text mode, always open files
+     in binary mode. */
+#ifdef O_BINARY
+  open_flags |= O_BINARY;
+#endif
+
+  *open_flags_p = open_flags;
+  return 0;
+}
+
 /* Convert a host-format mode_t into a bitmask of File-I/O flags.  */
 
 static LONGEST
diff --git a/gdb/common/fileio.h b/gdb/common/fileio.h
index 69a735f..b0f27ab 100644
--- a/gdb/common/fileio.h
+++ b/gdb/common/fileio.h
@@ -27,6 +27,11 @@
 
 extern int 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.  */
+
+extern int fileio_to_host_openflags (int fflags, int *flags);
+
 /* Pack a host-format integer into a byte buffer in big-endian
    format.  BYTES specifies the size of the integer to pack in
    bytes.  */
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 9483450..10d01c1 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,3 +1,9 @@
+2015-04-21  Gary Benson <gbenson@redhat.com>
+
+	* hostio.c (fileio_open_flags_to_host): Factored out to
+	fileio_to_host_openflags in common/fileio.c.  Single use
+	updated.
+
 2015-04-17  Max Filippov  <jcmvbkbc@gmail.com>
 
 	* linux-xtensa-low.c (xtensa_fill_gregset)
diff --git a/gdb/gdbserver/hostio.c b/gdb/gdbserver/hostio.c
index b03b5ad..9e858d9 100644
--- a/gdb/gdbserver/hostio.c
+++ b/gdb/gdbserver/hostio.c
@@ -243,38 +243,6 @@ hostio_reply_with_data (char *own_buf, char *buffer, int len,
   return input_index;
 }
 
-static int
-fileio_open_flags_to_host (int fileio_open_flags, int *open_flags_p)
-{
-  int open_flags = 0;
-
-  if (fileio_open_flags & ~FILEIO_O_SUPPORTED)
-    return -1;
-
-  if (fileio_open_flags & FILEIO_O_CREAT)
-    open_flags |= O_CREAT;
-  if (fileio_open_flags & FILEIO_O_EXCL)
-    open_flags |= O_EXCL;
-  if (fileio_open_flags & FILEIO_O_TRUNC)
-    open_flags |= O_TRUNC;
-  if (fileio_open_flags & FILEIO_O_APPEND)
-    open_flags |= O_APPEND;
-  if (fileio_open_flags & FILEIO_O_RDONLY)
-    open_flags |= O_RDONLY;
-  if (fileio_open_flags & FILEIO_O_WRONLY)
-    open_flags |= O_WRONLY;
-  if (fileio_open_flags & FILEIO_O_RDWR)
-    open_flags |= O_RDWR;
-/* On systems supporting binary and text mode, always open files in
-   binary mode. */
-#ifdef O_BINARY
-  open_flags |= O_BINARY;
-#endif
-
-  *open_flags_p = open_flags;
-  return 0;
-}
-
 static void
 handle_open (char *own_buf)
 {
@@ -291,7 +259,7 @@ handle_open (char *own_buf)
       || require_comma (&p)
       || require_int (&p, &mode)
       || require_end (p)
-      || fileio_open_flags_to_host (fileio_flags, &flags))
+      || fileio_to_host_openflags (fileio_flags, &flags))
     {
       hostio_packet_error (own_buf);
       return;
diff --git a/gdb/inf-child.c b/gdb/inf-child.c
index 713c9d4..084dfa1 100644
--- a/gdb/inf-child.c
+++ b/gdb/inf-child.c
@@ -204,41 +204,6 @@ inf_child_pid_to_exec_file (struct target_ops *self, int pid)
   return NULL;
 }
 
-
-/* Target file operations.  */
-
-static int
-inf_child_fileio_open_flags_to_host (int fileio_open_flags, int *open_flags_p)
-{
-  int open_flags = 0;
-
-  if (fileio_open_flags & ~FILEIO_O_SUPPORTED)
-    return -1;
-
-  if (fileio_open_flags & FILEIO_O_CREAT)
-    open_flags |= O_CREAT;
-  if (fileio_open_flags & FILEIO_O_EXCL)
-    open_flags |= O_EXCL;
-  if (fileio_open_flags & FILEIO_O_TRUNC)
-    open_flags |= O_TRUNC;
-  if (fileio_open_flags & FILEIO_O_APPEND)
-    open_flags |= O_APPEND;
-  if (fileio_open_flags & FILEIO_O_RDONLY)
-    open_flags |= O_RDONLY;
-  if (fileio_open_flags & FILEIO_O_WRONLY)
-    open_flags |= O_WRONLY;
-  if (fileio_open_flags & FILEIO_O_RDWR)
-    open_flags |= O_RDWR;
-/* On systems supporting binary and text mode, always open files in
-   binary mode. */
-#ifdef O_BINARY
-  open_flags |= O_BINARY;
-#endif
-
-  *open_flags_p = open_flags;
-  return 0;
-}
-
 /* Open FILENAME on the target, using FLAGS and MODE.  Return a
    target file descriptor, or -1 if an error occurs (and set
    *TARGET_ERRNO).  */
@@ -250,7 +215,7 @@ inf_child_fileio_open (struct target_ops *self,
   int nat_flags;
   int fd;
 
-  if (inf_child_fileio_open_flags_to_host (flags, &nat_flags) == -1)
+  if (fileio_to_host_openflags (flags, &nat_flags) == -1)
     {
       *target_errno = FILEIO_EINVAL;
       return -1;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]