From patchwork Mon Oct 26 03:46:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 9367 Received: (qmail 14408 invoked by alias); 26 Oct 2015 03:47:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 14316 invoked by uid 89); 26 Oct 2015 03:47:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_00, SPF_SOFTFAIL, T_FILL_THIS_FORM_SHORT autolearn=no version=3.3.2 X-HELO: smtp.electronicbox.net Received: from smtp.electronicbox.net (HELO smtp.electronicbox.net) (96.127.255.83) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 26 Oct 2015 03:47:07 +0000 Received: from simark.lan. (cable-192.222.137.139.electronicbox.net [192.222.137.139]) by smtp.electronicbox.net (Postfix) with ESMTP id 7A343440E81; Sun, 25 Oct 2015 23:47:05 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH c++ 06/12] Fix constness problem in ioscm_make_gdb_stdio_port Date: Sun, 25 Oct 2015 23:46:38 -0400 Message-Id: <1445831204-16588-6-git-send-email-simon.marchi@polymtl.ca> In-Reply-To: <1445831204-16588-1-git-send-email-simon.marchi@polymtl.ca> References: <1445831204-16588-1-git-send-email-simon.marchi@polymtl.ca> ioscm_make_gdb_stdio_port passes const char pointers (literal strings) to scm_mode_bits, which takes a non-const char pointer. Ideally, we would change scm_mode_bits to take a const char pointer, but it's not part of an API we control. Instead, it's easy enough to build the string to pass to scm_mode_bits in a (non-const) char array and pass that. gdb/ChangeLog: * guile/scm-ports.c (ioscm_make_gdb_stdio_port): Pass non-const char pointer to scm_mode_bits. --- gdb/guile/scm-ports.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/gdb/guile/scm-ports.c b/gdb/guile/scm-ports.c index 925f3b2..49e4fd6 100644 --- a/gdb/guile/scm-ports.c +++ b/gdb/guile/scm-ports.c @@ -357,29 +357,38 @@ 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; long mode_bits; SCM port; + char buf[3]; + + memset (buf, 0, sizeof (buf)); switch (fd) { case 0: name = input_port_name; - mode_bits = scm_mode_bits (is_a_tty ? "r0" : "r"); + buf[0] = 'r'; break; case 1: name = output_port_name; - mode_bits = scm_mode_bits (is_a_tty ? "w0" : "w"); + buf[0] = 'w'; break; case 2: name = error_port_name; - mode_bits = scm_mode_bits (is_a_tty ? "w0" : "w"); + buf[0] = 'w'; break; default: gdb_assert_not_reached ("bad stdio file descriptor"); } + if (isatty (fd)) + { + buf[1] = '0'; + } + + mode_bits = scm_mode_bits (buf); + port = ioscm_open_port (stdio_port_desc, mode_bits); scm_set_port_filename_x (port, gdbscm_scm_from_c_string (name));