aboutsummaryrefslogtreecommitdiff
path: root/gdb/common
diff options
context:
space:
mode:
authorGary Benson <gbenson@redhat.com>2015-04-21 12:07:54 +0100
committerGary Benson <gbenson@redhat.com>2015-04-21 12:09:24 +0100
commit819843c7029916120aa2929f80e0d7276177a7fb (patch)
treef00b335b1e3b2af0368862d09736e8e135f2da27 /gdb/common
parent43236bb2551a9783ff0de5e95bf75f905300eb06 (diff)
downloadgdb-819843c7029916120aa2929f80e0d7276177a7fb.zip
gdb-819843c7029916120aa2929f80e0d7276177a7fb.tar.gz
gdb-819843c7029916120aa2929f80e0d7276177a7fb.tar.bz2
Introduce new shared function fileio_to_host_openflags
This commit introduces a new shared function to replace identical functions in GDB and gdbserver.
Diffstat (limited to 'gdb/common')
-rw-r--r--gdb/common/fileio.c35
-rw-r--r--gdb/common/fileio.h5
2 files changed, 40 insertions, 0 deletions
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. */