This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: RFA: ensure binary objects opened in binary mode
Daniel Jacobowitz wrote:
On Wed, Feb 22, 2006 at 08:34:54PM +0200, Eli Zaretskii wrote:
(1) for every file that #includes both defs.h AND <fcntl.h>, remove the
<fcntl.h> inclusion.
[snip]
So I'd prefer if you committed the 1st and the 3rd patch. but not the
second. However, before you actually do that, let's wait and hear
what others think.
Fine by me.
+/* In case this is not defined in fcntl.h */
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
I'd change the comment to explain that O_BINARY has a meaning on
non-Posix platforms, while on Posix platforms it should be a no-op.
That is the _real_ reason we define O_BINARY.
Ditto.
Alrighty then -- here's the next iteration. Both parts have changed a
bit: the first patch no longer removes #include <fcntl.h> from solib.c,
while the second patch ONLY addresses the #ifndef O_BINARY clutter and
no longer removes <fcntl.h> from the 48 files.
Patch 1:
defs.h | 12 ++++++++++++
solib.c | 12 ++++++------
2 files changed, 18 insertions(+), 6 deletions(-)
2006-02-24 Charles Wilson <cygwin@...>
* gdb/defs.h: unconditionally include <fcntl.h>, and
ensure that O_BINARY is defined.
* gdb/solib.c(solib_open): ensure solib files are opened in
binary mode.
Patch 2:
corelow.c | 3 ---
exec.c | 3 ---
remote-rdp.c | 3 ---
source.c | 3 ---
symfile.c | 3 ---
5 files changed, 15 deletions(-)
2006-02-24 Charles Wilson <cygwin@...>
* gdb/corelow.c: Remove O_BINARY macro definition.
* gdb/exec.c: Remove O_BINARY macro definition
* gdb/remote-rdp.c: Remove O_BINARY macro definition
* gdb/source.c: Remove O_BINARY macro definition
* gdb/symfile.c: Remove O_BINARY macro definition
Per cgf's earlier message, I can go ahead and check this in myself
assuming everybody's happy with it at this point?
--
Chuck
Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.190
diff -u -r1.190 defs.h
--- defs.h 17 Dec 2005 22:33:59 -0000 1.190
+++ defs.h 22 Feb 2006 20:37:34 -0000
@@ -39,6 +39,8 @@
#include <unistd.h>
#endif
+#include <fcntl.h>
+
/* First include ansidecl.h so we can use the various macro definitions
here and in all subsequent file inclusions. */
@@ -58,6 +60,16 @@
#define SEEK_CUR 1
#endif
+/* The O_BINARY flag is defined in fcntl.h on some non-Posix platforms.
+ It is used as an access modifier in calls to open(), where it acts
+ similarly to the "b" character in fopen()'s MODE argument. On Posix
+ platforms it should be a no-op, so it is defined as 0 here. This
+ ensures that the symbol may be used freely elsewhere in gdb. */
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
#include <stdarg.h> /* For va_list. */
#include "libiberty.h"
Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.83
diff -u -r1.83 solib.c
--- solib.c 21 Jan 2006 22:23:27 -0000 1.83
+++ solib.c 22 Feb 2006 20:37:34 -0000
@@ -171,7 +171,7 @@
}
/* Now see if we can open it. */
- found_file = open (temp_pathname, O_RDONLY, 0);
+ found_file = open (temp_pathname, O_RDONLY | O_BINARY, 0);
}
/* If the search in solib_absolute_prefix failed, and the path name is
@@ -192,32 +192,32 @@
/* If not found, search the solib_search_path (if any). */
if (found_file < 0 && solib_search_path != NULL)
found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
- in_pathname, O_RDONLY, 0, &temp_pathname);
+ in_pathname, O_RDONLY | O_BINARY, 0, &temp_pathname);
/* If not found, next search the solib_search_path (if any) for the basename
only (ignoring the path). This is to allow reading solibs from a path
that differs from the opened path. */
if (found_file < 0 && solib_search_path != NULL)
found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
- lbasename (in_pathname), O_RDONLY, 0,
+ lbasename (in_pathname), O_RDONLY | O_BINARY, 0,
&temp_pathname);
/* If not found, try to use target supplied solib search method */
if (found_file < 0 && ops->find_and_open_solib)
- found_file = ops->find_and_open_solib (in_pathname, O_RDONLY,
+ found_file = ops->find_and_open_solib (in_pathname, O_RDONLY | O_BINARY,
&temp_pathname);
/* If not found, next search the inferior's $PATH environment variable. */
if (found_file < 0 && solib_absolute_prefix == NULL)
found_file = openp (get_in_environ (inferior_environ, "PATH"),
- OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY, 0,
+ OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY, 0,
&temp_pathname);
/* If not found, next search the inferior's $LD_LIBRARY_PATH
environment variable. */
if (found_file < 0 && solib_absolute_prefix == NULL)
found_file = openp (get_in_environ (inferior_environ, "LD_LIBRARY_PATH"),
- OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY, 0,
+ OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY, 0,
&temp_pathname);
/* Done. If not found, tough luck. Return found_file and
Index: corelow.c
===================================================================
RCS file: /cvs/src/src/gdb/corelow.c,v
retrieving revision 1.54
diff -u -r1.54 corelow.c
--- corelow.c 24 Jan 2006 22:34:34 -0000 1.54
+++ corelow.c 22 Feb 2006 20:29:45 -0000
@@ -47,9 +47,6 @@
#include "exceptions.h"
#include "solib.h"
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
#ifndef O_LARGEFILE
#define O_LARGEFILE 0
Index: exec.c
===================================================================
RCS file: /cvs/src/src/gdb/exec.c,v
retrieving revision 1.59
diff -u -r1.59 exec.c
--- exec.c 17 Dec 2005 22:33:59 -0000 1.59
+++ exec.c 22 Feb 2006 20:29:45 -0000
@@ -42,9 +42,6 @@
#include <ctype.h>
#include "gdb_stat.h"
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
#include "xcoffsolib.h"
Index: remote-rdp.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-rdp.c,v
retrieving revision 1.47
diff -u -r1.47 remote-rdp.c
--- remote-rdp.c 24 Jan 2006 22:09:28 -0000 1.47
+++ remote-rdp.c 22 Feb 2006 20:29:45 -0000
@@ -791,9 +791,6 @@
#define SWI_GenerateError 0x71
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
static int translate_open_mode[] =
{
Index: source.c
===================================================================
RCS file: /cvs/src/src/gdb/source.c,v
retrieving revision 1.72
diff -u -r1.72 source.c
--- source.c 15 Jan 2006 19:09:30 -0000 1.72
+++ source.c 22 Feb 2006 20:29:45 -0000
@@ -46,9 +46,6 @@
#include "ui-out.h"
#include "readline/readline.h"
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
#define OPEN_MODE (O_RDONLY | O_BINARY)
#define FDOPEN_MODE FOPEN_RB
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.165
diff -u -r1.165 symfile.c
--- symfile.c 15 Jan 2006 19:50:03 -0000 1.165
+++ symfile.c 22 Feb 2006 20:29:45 -0000
@@ -60,9 +60,6 @@
#include <time.h>
#include <sys/time.h>
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
int (*deprecated_ui_load_progress_hook) (const char *section, unsigned long num);
void (*deprecated_show_load_progress) (const char *section,