diff options
author | Mike Frysinger <vapier@gentoo.org> | 2021-05-07 00:08:43 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2021-05-07 00:34:03 -0400 |
commit | a5884035977f95b09c28d4bb2276ac4869930e96 (patch) | |
tree | e0effd688b93b263dd881924a635357344c31a23 | |
parent | 8e78e9b9950a899a3c10f48e4f23ea4fd9bafe9b (diff) | |
download | gdb-a5884035977f95b09c28d4bb2276ac4869930e96.zip gdb-a5884035977f95b09c28d4bb2276ac4869930e96.tar.gz gdb-a5884035977f95b09c28d4bb2276ac4869930e96.tar.bz2 |
sim: m32c: switch from custom fgets to getline
No need to implement this ourselves when POSIX has a nice API.
-rw-r--r-- | sim/m32c/ChangeLog | 7 | ||||
-rw-r--r-- | sim/m32c/Makefile.in | 7 | ||||
-rw-r--r-- | sim/m32c/opc2c.c | 12 | ||||
-rw-r--r-- | sim/m32c/safe-fgets.c | 69 | ||||
-rw-r--r-- | sim/m32c/safe-fgets.h | 27 |
5 files changed, 17 insertions, 105 deletions
diff --git a/sim/m32c/ChangeLog b/sim/m32c/ChangeLog index b60faf5..ad2bece 100644 --- a/sim/m32c/ChangeLog +++ b/sim/m32c/ChangeLog @@ -1,3 +1,10 @@ +2021-05-07 Mike Frysinger <vapier@gentoo.org> + + * Makefile.in: Delete safe-fgets. + * opc2c.c: Delete safe-fgets.h include. + (main): Replace safe_fgets with getline. + * safe-fgets.c, safe-fgets.h: Removed. + 2021-05-05 Mike Frysinger <vapier@gentoo.org> * gdb-if.c: Include libiberty.h. diff --git a/sim/m32c/Makefile.in b/sim/m32c/Makefile.in index 05aa753..0c101a8 100644 --- a/sim/m32c/Makefile.in +++ b/sim/m32c/Makefile.in @@ -56,14 +56,11 @@ m32c.c : m32c.opc opc2c $(OPC2C) -l m32c.out $(srcdir)/m32c.opc > m32c.c.tmp mv m32c.c.tmp m32c.c -opc2c : opc2c.o safe-fgets.o +opc2c : opc2c.o $(LINK_FOR_BUILD) $^ encodings: grep '/\* [01]' $(srcdir)/r8c.opc | sort -opc2c.o : opc2c.c safe-fgets.h +opc2c.o : opc2c.c $(COMPILE_FOR_BUILD) -c $(srcdir)/opc2c.c - -safe-fgets.o : safe-fgets.c safe-fgets.h - $(COMPILE_FOR_BUILD) -c $(srcdir)/safe-fgets.c diff --git a/sim/m32c/opc2c.c b/sim/m32c/opc2c.c index 6487427..4c97644 100644 --- a/sim/m32c/opc2c.c +++ b/sim/m32c/opc2c.c @@ -24,8 +24,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <ctype.h> #include <stdlib.h> -#include "safe-fgets.h" - static int errors = 0; #define MAX_BYTES 10 @@ -504,10 +502,11 @@ log_indirect (Indirect * ind, int byte) int main (int argc, char **argv) { - char *line; + char *linebuf; FILE *in; int lineno = 0; int i; + size_t len; if (argc > 2 && strcmp (argv[1], "-l") == 0) { @@ -536,8 +535,12 @@ main (int argc, char **argv) opcodes = (opcode **) malloc (sizeof (opcode *)); op = &prefix_text; op->lineno = 1; - while ((line = safe_fgets (in)) != 0) + linebuf = NULL; + len = 0; + while (getline (&linebuf, &len, in) >= 0) { + char *line = linebuf; + lineno++; if (strncmp (line, " /** ", 6) == 0 && (isdigit (line[6]) || memcmp (line + 6, "VARY", 4) == 0)) @@ -629,6 +632,7 @@ main (int argc, char **argv) op->lines[op->nlines - 1] = strdup (line); } } + free (linebuf); { int i, j; diff --git a/sim/m32c/safe-fgets.c b/sim/m32c/safe-fgets.c deleted file mode 100644 index 3516fa8..0000000 --- a/sim/m32c/safe-fgets.c +++ /dev/null @@ -1,69 +0,0 @@ -/* safe-fgets.c --- like fgets, but allocates its own static buffer. - -Copyright (C) 2005-2021 Free Software Foundation, Inc. -Contributed by Red Hat, Inc. - -This file is part of the GNU simulators. - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. */ - - -#include <stdio.h> -#include <stdlib.h> - -#include "safe-fgets.h" - -static char *line_buf = 0; -static int line_buf_size = 0; - -#define LBUFINCR 100 - -char * -safe_fgets (FILE * f) -{ - char *line_ptr; - - if (line_buf == 0) - { - line_buf = (char *) malloc (LBUFINCR); - line_buf_size = LBUFINCR; - } - - /* points to last byte */ - line_ptr = line_buf + line_buf_size - 1; - - /* so we can see if fgets put a 0 there */ - *line_ptr = 1; - if (fgets (line_buf, line_buf_size, f) == 0) - return 0; - - /* we filled the buffer? */ - while (line_ptr[0] == 0 && line_ptr[-1] != '\n') - { - /* Make the buffer bigger and read more of the line */ - line_buf_size += LBUFINCR; - line_buf = (char *) realloc (line_buf, line_buf_size); - - /* points to last byte again */ - line_ptr = line_buf + line_buf_size - 1; - /* so we can see if fgets put a 0 there */ - *line_ptr = 1; - - if (fgets (line_buf + line_buf_size - LBUFINCR - 1, LBUFINCR + 1, f) == - 0) - return 0; - } - - return line_buf; -} diff --git a/sim/m32c/safe-fgets.h b/sim/m32c/safe-fgets.h deleted file mode 100644 index 7c03f27..0000000 --- a/sim/m32c/safe-fgets.h +++ /dev/null @@ -1,27 +0,0 @@ -/* safe-fgets.h --- interface to safe version of fgets. - -Copyright (C) 2005-2021 Free Software Foundation, Inc. -Contributed by Red Hat, Inc. - -This file is part of the GNU simulators. - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. */ - - -#ifndef _safe_gets_h_ -#define _safe_gets_h_ - -char *safe_fgets (FILE * f); - -#endif |