From 0cfab8d6e47c165ee02d027c11b9a11c726516fa Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 4 May 2017 12:07:54 +0200 Subject: Open files in O_BINARY If O_BINARY is not defined, define it to 0, so that the change has no effect then. Some systems have separate binary and text modes for files, and we don't want the text mode to be used. Change-Id: If7efb5bd448c2a1c7d1eb5dab276849b1b15a3ce Reviewed-by: Christian Kandeler --- libdwfl/linux-pid-attach.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libdwfl/linux-pid-attach.c') diff --git a/libdwfl/linux-pid-attach.c b/libdwfl/linux-pid-attach.c index e6a5c419..1def7f16 100644 --- a/libdwfl/linux-pid-attach.c +++ b/libdwfl/linux-pid-attach.c @@ -52,7 +52,7 @@ linux_proc_pid_is_stopped (pid_t pid) bool retval, have_state; snprintf (buffer, sizeof (buffer), "/proc/%ld/status", (long) pid); - procfile = fopen (buffer, "r"); + procfile = fopen (buffer, "rb"); if (procfile == NULL) return false; @@ -302,7 +302,7 @@ dwfl_linux_proc_attach (Dwfl *dwfl, pid_t pid, bool assume_ptrace_stopped) /* Make sure to report the actual PID (thread group leader) to dwfl_attach_state. */ snprintf (buffer, sizeof (buffer), "/proc/%ld/status", (long) pid); - procfile = fopen (buffer, "r"); + procfile = fopen (buffer, "rb"); if (procfile == NULL) { err = errno; @@ -352,7 +352,7 @@ dwfl_linux_proc_attach (Dwfl *dwfl, pid_t pid, bool assume_ptrace_stopped) Elf *elf; i = snprintf (name, sizeof (name), "/proc/%ld/exe", (long) pid); assert (i > 0 && i < (ssize_t) sizeof (name) - 1); - int elf_fd = open (name, O_RDONLY); + int elf_fd = open (name, O_RDONLY | O_BINARY); if (elf_fd >= 0) { elf = elf_begin (elf_fd, ELF_C_READ_MMAP, NULL); -- cgit v1.2.3