This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb] guile: Simplify ioscm_make_gdb_stdio_port
- From: Simon Marchi <simark at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 26 Oct 2015 19:06:44 -0000
- Subject: [binutils-gdb] guile: Simplify ioscm_make_gdb_stdio_port
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1522597b057c321d813d3433bcd1e17c02a56557
commit 1522597b057c321d813d3433bcd1e17c02a56557
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date: Mon Oct 26 15:05:50 2015 -0400
guile: Simplify ioscm_make_gdb_stdio_port
As pointed out by Pedro, it's clearer to do it this way. We can trust
that scm_mode_bits won't try to modify our string, even though it takes
a non-const char *.
gdb/ChangeLog:
* guile/scm-ports.c (ioscm_make_gdb_stdio_port): Do not pass a
local char array to scm_mode_bits, use a cast instead.
Diff:
---
gdb/ChangeLog | 5 +++++
gdb/guile/scm-ports.c | 17 ++++++-----------
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5042001..8d08d81 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2015-10-26 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * guile/scm-ports.c (ioscm_make_gdb_stdio_port): Do not pass a
+ local char array to scm_mode_bits, use a cast instead.
+
2015-10-26 Simon Marchi <simon.marchi@ericsson.com>
* tui/tui-data.c (tui_alloc_content): Don't check xmalloc
diff --git a/gdb/guile/scm-ports.c b/gdb/guile/scm-ports.c
index 5d529b3..ffaa3fd 100644
--- a/gdb/guile/scm-ports.c
+++ b/gdb/guile/scm-ports.c
@@ -357,36 +357,31 @@ ioscm_init_stdio_buffers (SCM port, long mode_bits)
static SCM
ioscm_make_gdb_stdio_port (int fd)
{
+ int is_a_tty = isatty (fd);
const char *name;
+ const char *mode_str;
long mode_bits;
SCM port;
- char buf[3];
-
- memset (buf, 0, sizeof (buf));
switch (fd)
{
case 0:
name = input_port_name;
- buf[0] = 'r';
+ mode_str = is_a_tty ? "r0" : "r";
break;
case 1:
name = output_port_name;
- buf[0] = 'w';
+ mode_str = is_a_tty ? "w0" : "w";
break;
case 2:
name = error_port_name;
- buf[0] = 'w';
+ mode_str = is_a_tty ? "w0" : "w";
break;
default:
gdb_assert_not_reached ("bad stdio file descriptor");
}
- if (isatty (fd))
- buf[1] = '0';
-
- mode_bits = scm_mode_bits (buf);
-
+ mode_bits = scm_mode_bits ((char *) mode_str);
port = ioscm_open_port (stdio_port_desc, mode_bits);
scm_set_port_filename_x (port, gdbscm_scm_from_c_string (name));