* cli/cli-script.c (do_fclose_cleanup): Remove.
authorTom Tromey <tromey@redhat.com>
Tue, 28 Oct 2008 15:22:13 +0000 (15:22 +0000)
committerTom Tromey <tromey@redhat.com>
Tue, 28 Oct 2008 15:22:13 +0000 (15:22 +0000)
(script_from_file): Use make_cleanup_fclose.
* xml-tdesc.c (do_cleanup_fclose): Remove.
(fetch_xml_from_file): Use make_cleanup_fclose.
* tracepoint.c (tracepoint_save_command): Use
make_cleanup_fclose.  Always free pathname.
* source.c (print_source_lines_base): Use make_cleanup_fclose.
* remote.c (fclose_cleanup): Remove.
(remote_file_put): Use make_cleanup_fclose.
(remote_file_get): Likewise.
* linux-nat.c (linux_nat_find_memory_regions): Use
make_cleanup_fclose.
(linux_nat_info_proc_cmd): Likewise.
(linux_proc_pending_signals): Likewise.
* fbsd-nat.c (fbsd_find_memory_regions): Use make_cleanup_fclose.
Free file name.
* cli/cli-dump.c (do_fclose_cleanup): Remove.
(make_cleanup_fclose): Remove.
* defs.h (make_cleanup_fclose): Declare.
* utils.c (do_fclose_cleanup): New function.
(make_cleanup_fclose): Likewise.

gdb/ChangeLog
gdb/cli/cli-dump.c
gdb/cli/cli-script.c
gdb/defs.h
gdb/fbsd-nat.c
gdb/linux-nat.c
gdb/remote.c
gdb/source.c
gdb/tracepoint.c
gdb/utils.c
gdb/xml-tdesc.c

index 48d67814f48034e8afc540cdc792d426eec8567a..973772142a5b3f32d53ea35818b7e30eed5b7956 100644 (file)
@@ -1,3 +1,27 @@
+2008-10-28  Tom Tromey  <tromey@redhat.com>
+
+       * cli/cli-script.c (do_fclose_cleanup): Remove.
+       (script_from_file): Use make_cleanup_fclose.
+       * xml-tdesc.c (do_cleanup_fclose): Remove.
+       (fetch_xml_from_file): Use make_cleanup_fclose.
+       * tracepoint.c (tracepoint_save_command): Use
+       make_cleanup_fclose.  Always free pathname.
+       * source.c (print_source_lines_base): Use make_cleanup_fclose.
+       * remote.c (fclose_cleanup): Remove.
+       (remote_file_put): Use make_cleanup_fclose.
+       (remote_file_get): Likewise.
+       * linux-nat.c (linux_nat_find_memory_regions): Use
+       make_cleanup_fclose.
+       (linux_nat_info_proc_cmd): Likewise.
+       (linux_proc_pending_signals): Likewise.
+       * fbsd-nat.c (fbsd_find_memory_regions): Use make_cleanup_fclose.
+       Free file name.
+       * cli/cli-dump.c (do_fclose_cleanup): Remove.
+       (make_cleanup_fclose): Remove.
+       * defs.h (make_cleanup_fclose): Declare.
+       * utils.c (do_fclose_cleanup): New function.
+       (make_cleanup_fclose): Likewise.
+
 2008-10-27  Pedro Alves  <pedro@codesourcery.com>
 
        * inflow.c (kill_command): If the target claims there is still
index 67a9fc53dd2b0cc2134d3658f01d17a52c02a916..d5dbc972df939328fc045b1d17343bf47f4aa9f3 100644 (file)
@@ -67,19 +67,6 @@ scan_expression_with_cleanup (char **cmd, const char *def)
 }
 
 
-static void
-do_fclose_cleanup (void *arg)
-{
-  FILE *file = arg;
-  fclose (arg);
-}
-
-static struct cleanup *
-make_cleanup_fclose (FILE *file)
-{
-  return make_cleanup (do_fclose_cleanup, file);
-}
-
 char *
 scan_filename_with_cleanup (char **cmd, const char *defname)
 {
index 6bfff4046b22a7d1eb618fb855be498f6182d878..e65c29e74aa95329217c12079506886302830912 100644 (file)
@@ -1446,12 +1446,6 @@ source_cleanup_lines (void *args)
   source_file_name = p->old_file;
 }
 
-static void
-do_fclose_cleanup (void *stream)
-{
-  fclose (stream);
-}
-
 struct wrapped_read_command_file_args
 {
   FILE *stream;
@@ -1476,7 +1470,7 @@ script_from_file (FILE *stream, char *file)
   if (stream == NULL)
     internal_error (__FILE__, __LINE__, _("called with NULL file pointer!"));
 
-  old_cleanups = make_cleanup (do_fclose_cleanup, stream);
+  old_cleanups = make_cleanup_fclose (stream);
 
   old_lines.old_line = source_line_number;
   old_lines.old_file = source_file_name;
index 42dd821a607e40fd995404abb8ebe593331ae69f..8d50f8a824b85cbeb535187e1512b354aa7813bd 100644 (file)
@@ -362,6 +362,8 @@ extern struct cleanup *(make_cleanup_free_section_addr_info
 
 extern struct cleanup *make_cleanup_close (int fd);
 
+extern struct cleanup *make_cleanup_fclose (FILE *file);
+
 extern struct cleanup *make_cleanup_bfd_close (bfd *abfd);
 
 extern struct cleanup *make_cleanup_restore_integer (int *variable);
index 215d2a78f61b7e1c08466b96b2073c33b0266546..9fed5bfde881cc3eab63b508c02af47542cb558c 100644 (file)
@@ -101,11 +101,14 @@ fbsd_find_memory_regions (int (*func) (CORE_ADDR, unsigned long,
   unsigned long start, end, size;
   char protection[4];
   int read, write, exec;
+  struct cleanup *cleanup;
 
   mapfilename = xstrprintf ("/proc/%ld/map", (long) pid);
+  cleanup = make_cleanup (xfree, mapfilename);
   mapfile = fopen (mapfilename, "r");
   if (mapfile == NULL)
     error (_("Couldn't open %s."), mapfilename);
+  make_cleanup_fclose (mapfile);
 
   if (info_verbose)
     fprintf_filtered (gdb_stdout, 
@@ -134,7 +137,7 @@ fbsd_find_memory_regions (int (*func) (CORE_ADDR, unsigned long,
       func (start, size, read, write, exec, obfd);
     }
 
-  fclose (mapfile);
+  do_cleanups (cleanup);
   return 0;
 }
 
index d2116e12cd01b5ec4de698fdb0f9f90cef9bd053..56ec9cb28992028a47569b9d7084e237e2de44e2 100644 (file)
@@ -3334,11 +3334,13 @@ linux_nat_find_memory_regions (int (*func) (CORE_ADDR,
   char permissions[8], device[8], filename[MAXPATHLEN];
   int read, write, exec;
   int ret;
+  struct cleanup *cleanup;
 
   /* Compose the filename for the /proc memory map, and open it.  */
   sprintf (mapsfilename, "/proc/%lld/maps", pid);
   if ((mapsfile = fopen (mapsfilename, "r")) == NULL)
     error (_("Could not open %s."), mapsfilename);
+  cleanup = make_cleanup_fclose (mapsfile);
 
   if (info_verbose)
     fprintf_filtered (gdb_stdout,
@@ -3371,7 +3373,7 @@ linux_nat_find_memory_regions (int (*func) (CORE_ADDR,
         segment.  */
       func (addr, size, read, write, exec, obfd);
     }
-  fclose (mapsfile);
+  do_cleanups (cleanup);
   return 0;
 }
 
@@ -3662,9 +3664,10 @@ linux_nat_info_proc_cmd (char *args, int from_tty)
       sprintf (fname1, "/proc/%lld/cmdline", pid);
       if ((procfile = fopen (fname1, "r")) != NULL)
        {
+         struct cleanup *cleanup = make_cleanup_fclose (procfile);
          fgets (buffer, sizeof (buffer), procfile);
          printf_filtered ("cmdline = '%s'\n", buffer);
-         fclose (procfile);
+         do_cleanups (cleanup);
        }
       else
        warning (_("unable to open /proc file '%s'"), fname1);
@@ -3694,7 +3697,9 @@ linux_nat_info_proc_cmd (char *args, int from_tty)
        {
          long long addr, endaddr, size, offset, inode;
          char permissions[8], device[8], filename[MAXPATHLEN];
+         struct cleanup *cleanup;
 
+         cleanup = make_cleanup_fclose (procfile);
          printf_filtered (_("Mapped address spaces:\n\n"));
          if (gdbarch_addr_bit (current_gdbarch) == 32)
            {
@@ -3742,7 +3747,7 @@ linux_nat_info_proc_cmd (char *args, int from_tty)
                }
            }
 
-         fclose (procfile);
+         do_cleanups (cleanup);
        }
       else
        warning (_("unable to open /proc file '%s'"), fname1);
@@ -3752,9 +3757,10 @@ linux_nat_info_proc_cmd (char *args, int from_tty)
       sprintf (fname1, "/proc/%lld/status", pid);
       if ((procfile = fopen (fname1, "r")) != NULL)
        {
+         struct cleanup *cleanup = make_cleanup_fclose (procfile);
          while (fgets (buffer, sizeof (buffer), procfile) != NULL)
            puts_filtered (buffer);
-         fclose (procfile);
+         do_cleanups (cleanup);
        }
       else
        warning (_("unable to open /proc file '%s'"), fname1);
@@ -3767,6 +3773,7 @@ linux_nat_info_proc_cmd (char *args, int from_tty)
          int itmp;
          char ctmp;
          long ltmp;
+         struct cleanup *cleanup = make_cleanup_fclose (procfile);
 
          if (fscanf (procfile, "%d ", &itmp) > 0)
            printf_filtered (_("Process: %d\n"), itmp);
@@ -3850,7 +3857,7 @@ linux_nat_info_proc_cmd (char *args, int from_tty)
          if (fscanf (procfile, "%lu ", &ltmp) > 0)     /* FIXME arch? */
            printf_filtered (_("wchan (system call): 0x%lx\n"), ltmp);
 #endif
-         fclose (procfile);
+         do_cleanups (cleanup);
        }
       else
        warning (_("unable to open /proc file '%s'"), fname1);
@@ -3952,6 +3959,7 @@ linux_proc_pending_signals (int pid, sigset_t *pending, sigset_t *blocked, sigse
   FILE *procfile;
   char buffer[MAXPATHLEN], fname[MAXPATHLEN];
   int signum;
+  struct cleanup *cleanup;
 
   sigemptyset (pending);
   sigemptyset (blocked);
@@ -3960,6 +3968,7 @@ linux_proc_pending_signals (int pid, sigset_t *pending, sigset_t *blocked, sigse
   procfile = fopen (fname, "r");
   if (procfile == NULL)
     error (_("Could not open %s"), fname);
+  cleanup = make_cleanup_fclose (procfile);
 
   while (fgets (buffer, MAXPATHLEN, procfile) != NULL)
     {
@@ -3981,7 +3990,7 @@ linux_proc_pending_signals (int pid, sigset_t *pending, sigset_t *blocked, sigse
        add_line_to_sigset (buffer + 8, ignored);
     }
 
-  fclose (procfile);
+  do_cleanups (cleanup);
 }
 
 static LONGEST
index 6af826783737be3082f01df9522bcf9bd6fa2b13..9f10c2ac919e4b05b820eddd2054797cc88bd0db 100644 (file)
@@ -8212,12 +8212,6 @@ remote_hostio_error (int errnum)
     error (_("Remote I/O error: %s"), safe_strerror (host_error));
 }
 
-static void
-fclose_cleanup (void *file)
-{
-  fclose (file);
-}
-
 static void
 remote_hostio_close_cleanup (void *opaque)
 {
@@ -8335,7 +8329,7 @@ remote_file_put (const char *local_file, const char *remote_file, int from_tty)
   file = fopen (local_file, "rb");
   if (file == NULL)
     perror_with_name (local_file);
-  back_to = make_cleanup (fclose_cleanup, file);
+  back_to = make_cleanup_fclose (file);
 
   fd = remote_hostio_open (remote_file, (FILEIO_O_WRONLY | FILEIO_O_CREAT
                                         | FILEIO_O_TRUNC),
@@ -8425,7 +8419,7 @@ remote_file_get (const char *remote_file, const char *local_file, int from_tty)
   file = fopen (local_file, "wb");
   if (file == NULL)
     perror_with_name (local_file);
-  back_to = make_cleanup (fclose_cleanup, file);
+  back_to = make_cleanup_fclose (file);
 
   /* Send up to this many bytes at once.  They won't all fit in the
      remote packet limit, so we'll transfer slightly fewer.  */
index a5f434f9e2f9a0f444125523469d13d5f5a07279..3ef557c6690e99507a010a84573eb692b744f6fe 100644 (file)
@@ -1312,6 +1312,7 @@ print_source_lines_base (struct symtab *s, int line, int stopline, int noerror)
   int desc;
   FILE *stream;
   int nlines = stopline - line;
+  struct cleanup *cleanup;
 
   /* Regardless of whether we can open the file, set current_source_symtab. */
   current_source_symtab = s;
@@ -1378,6 +1379,7 @@ print_source_lines_base (struct symtab *s, int line, int stopline, int noerror)
 
   stream = fdopen (desc, FDOPEN_MODE);
   clearerr (stream);
+  cleanup = make_cleanup_fclose (stream);
 
   while (nlines-- > 0)
     {
@@ -1417,7 +1419,7 @@ print_source_lines_base (struct symtab *s, int line, int stopline, int noerror)
       while (c != '\n' && (c = fgetc (stream)) >= 0);
     }
 
-  fclose (stream);
+  do_cleanups (cleanup);
 }
 \f
 /* Show source lines from the file of symtab S, starting with line
index 4f5c56a66a48fe8d6f512174cd8f54c7a969bcf4..2d2c3bdffb45c9aa8d6e62143d09c5d79a14bd5b 100644 (file)
@@ -2292,6 +2292,7 @@ tracepoint_save_command (char *args, int from_tty)
   char *i1 = "    ", *i2 = "      ";
   char *indent, *actionline, *pathname;
   char tmp[40];
+  struct cleanup *cleanup;
 
   if (args == 0 || *args == 0)
     error (_("Argument required (file name in which to save tracepoints)"));
@@ -2303,10 +2304,11 @@ tracepoint_save_command (char *args, int from_tty)
     }
 
   pathname = tilde_expand (args);
+  cleanup = make_cleanup (xfree, pathname);
   if (!(fp = fopen (pathname, "w")))
     error (_("Unable to open file '%s' for saving tracepoints (%s)"),
           args, safe_strerror (errno));
-  xfree (pathname);
+  make_cleanup_fclose (fp);
   
   ALL_TRACEPOINTS (tp)
   {
@@ -2348,7 +2350,7 @@ tracepoint_save_command (char *args, int from_tty)
          }
       }
   }
-  fclose (fp);
+  do_cleanups (cleanup);
   if (from_tty)
     printf_filtered ("Tracepoints saved to file '%s'.\n", args);
   return;
index 3d3539021125390f7a15d0b2f78f17847d2829ca..f9a5f19fded899c9092e72614c8ff00b18ac7e53 100644 (file)
@@ -255,6 +255,23 @@ make_cleanup_close (int fd)
   return make_cleanup (do_close_cleanup, saved_fd);
 }
 
+/* Helper function which does the work for make_cleanup_fclose.  */
+
+static void
+do_fclose_cleanup (void *arg)
+{
+  FILE *file = arg;
+  fclose (arg);
+}
+
+/* Return a new cleanup that closes FILE.  */
+
+struct cleanup *
+make_cleanup_fclose (FILE *file)
+{
+  return make_cleanup (do_fclose_cleanup, file);
+}
+
 static void
 do_ui_file_delete (void *arg)
 {
index 42bc4a03416beb715b5130d5e239121f776e3176..2e8c1f537815c5c7d01245efb695679b3c96f76a 100644 (file)
@@ -421,14 +421,6 @@ tdesc_parse_xml (const char *document, xml_fetch_another fetcher,
 #endif /* HAVE_LIBEXPAT */
 \f
 
-/* Close FILE.  */
-
-static void
-do_cleanup_fclose (void *file)
-{
-  fclose (file);
-}
-
 /* Open FILENAME, read all its text into memory, close it, and return
    the text.  If something goes wrong, return NULL and warn.  */
 
@@ -455,7 +447,7 @@ fetch_xml_from_file (const char *filename, void *baton)
   if (file == NULL)
     return NULL;
 
-  back_to = make_cleanup (do_cleanup_fclose, file);
+  back_to = make_cleanup_fclose (file);
 
   /* Read in the whole file, one chunk at a time.  */
   len = 4096;
This page took 0.036018 seconds and 4 git commands to generate.