From patchwork Tue Mar 17 21:02:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Gaisler X-Patchwork-Id: 5666 Received: (qmail 40230 invoked by alias); 17 Mar 2015 21:03:09 -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 39907 invoked by uid 89); 17 Mar 2015 21:03:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-HELO: bin-vsp-out-03.atm.binero.net Received: from vsp-authed01.binero.net (HELO bin-vsp-out-03.atm.binero.net) (195.74.38.224) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 17 Mar 2015 21:03:02 +0000 X-Halon-ID: fc213158-cce8-11e4-9958-0050569116f7 Authorized-sender: jiri@gaisler.se Received: from localhost.localdomain (unknown [46.246.62.93]) by bin-vsp-out-03.atm.binero.net (Halon Mail Gateway) with ESMTPSA; Tue, 17 Mar 2015 22:02:56 +0100 (CET) From: Jiri Gaisler To: gdb-patches@sourceware.org Cc: Jiri Gaisler Subject: [PATCH v4 02/13] sim/erc32: Removed type mismatch compiler warnings Date: Tue, 17 Mar 2015 22:02:39 +0100 Message-Id: <1426626170-21401-3-git-send-email-jiri@gaisler.se> In-Reply-To: <1426626170-21401-1-git-send-email-jiri@gaisler.se> References: <1426626170-21401-1-git-send-email-jiri@gaisler.se> X-IsSubscribed: yes * func.c (exec_cmd) : silence compiler warnings when calling system(). (batch) : replace fgets() with getline(). --- sim/erc32/func.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/sim/erc32/func.c b/sim/erc32/func.c index 260ceff..e42b0ec 100644 --- a/sim/erc32/func.c +++ b/sim/erc32/func.c @@ -80,20 +80,24 @@ batch(sregs, fname) char *fname; { FILE *fp; - char lbuf[1024]; + char *lbuf = NULL; + size_t len = 0; + ssize_t tmp; + size_t slen; if ((fp = fopen(fname, "r")) == NULL) { fprintf(stderr, "couldn't open batch file %s\n", fname); return (0); } - while (!feof(fp)) { - lbuf[0] = 0; - fgets(lbuf, 1023, fp); - if ((strlen(lbuf) > 0) && (lbuf[strlen(lbuf) - 1] == '\n')) - lbuf[strlen(lbuf) - 1] = 0; - printf("sis> %s\n", lbuf); - exec_cmd(sregs, lbuf); + while (getline(&lbuf, &len, fp) > -1) { + slen = strlen(lbuf); + if (slen && (lbuf[slen - 1] == '\n')) { + lbuf[slen - 1] = 0; + printf("sis> %s\n", lbuf); + exec_cmd(sregs, lbuf); + } } + free(lbuf); fclose(fp); return (1); } @@ -554,7 +558,9 @@ exec_cmd(sregs, cmd) sim_halt(); } else if (strncmp(cmd1, "shell", clen) == 0) { if ((cmd1 = strtok(NULL, " \t\n\r")) != NULL) { - system(&cmdsave[clen]); + if (system(&cmdsave[clen])) { + /* Silence unused return value warning. */ + } } } else if (strncmp(cmd1, "step", clen) == 0) { stat = run_sim(sregs, 1, 1);