(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-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
}
-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)
{
source_file_name = p->old_file;
}
-static void
-do_fclose_cleanup (void *stream)
-{
- fclose (stream);
-}
-
struct wrapped_read_command_file_args
{
FILE *stream;
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;
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);
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,
func (start, size, read, write, exec, obfd);
}
- fclose (mapfile);
+ do_cleanups (cleanup);
return 0;
}
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,
segment. */
func (addr, size, read, write, exec, obfd);
}
- fclose (mapsfile);
+ do_cleanups (cleanup);
return 0;
}
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);
{
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)
{
}
}
- fclose (procfile);
+ do_cleanups (cleanup);
}
else
warning (_("unable to open /proc file '%s'"), fname1);
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);
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);
if (fscanf (procfile, "%lu ", <mp) > 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);
FILE *procfile;
char buffer[MAXPATHLEN], fname[MAXPATHLEN];
int signum;
+ struct cleanup *cleanup;
sigemptyset (pending);
sigemptyset (blocked);
procfile = fopen (fname, "r");
if (procfile == NULL)
error (_("Could not open %s"), fname);
+ cleanup = make_cleanup_fclose (procfile);
while (fgets (buffer, MAXPATHLEN, procfile) != NULL)
{
add_line_to_sigset (buffer + 8, ignored);
}
- fclose (procfile);
+ do_cleanups (cleanup);
}
static LONGEST
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)
{
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),
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. */
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;
stream = fdopen (desc, FDOPEN_MODE);
clearerr (stream);
+ cleanup = make_cleanup_fclose (stream);
while (nlines-- > 0)
{
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
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)"));
}
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)
{
}
}
}
- fclose (fp);
+ do_cleanups (cleanup);
if (from_tty)
printf_filtered ("Tracepoints saved to file '%s'.\n", args);
return;
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)
{
#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. */
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;