aboutsummaryrefslogtreecommitdiff
path: root/gdb/compile
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2024-02-23 13:10:28 -0700
committerTom Tromey <tromey@adacore.com>2024-02-27 10:30:29 -0700
commit1eae7be116ddabb13b34d2c2e8e0dc13fbae2a0d (patch)
treedc0770a269e741138de98fda6ea6cb4c8c179ce1 /gdb/compile
parentcfe51255b892962c25166cc0afd8911caf9e1e56 (diff)
downloadbinutils-1eae7be116ddabb13b34d2c2e8e0dc13fbae2a0d.zip
binutils-1eae7be116ddabb13b34d2c2e8e0dc13fbae2a0d.tar.gz
binutils-1eae7be116ddabb13b34d2c2e8e0dc13fbae2a0d.tar.bz2
Rewrite final cleanups
This patch rewrites final cleanups to use std::function and otherwise be more C++-ish.
Diffstat (limited to 'gdb/compile')
-rw-r--r--gdb/compile/compile.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 8cb2e8ac..27cff25 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -427,23 +427,6 @@ compile_print_command (const char *arg, int from_tty)
}
}
-/* A cleanup function to remove a directory and all its contents. */
-
-static void
-do_rmdir (void *arg)
-{
- const char *dir = (const char *) arg;
- char *zap;
- int wstat;
-
- gdb_assert (startswith (dir, TMP_PREFIX));
- zap = concat ("rm -rf ", dir, (char *) NULL);
- wstat = system (zap);
- if (wstat == -1 || !WIFEXITED (wstat) || WEXITSTATUS (wstat) != 0)
- warning (_("Could not remove temporary directory %s"), dir);
- XDELETEVEC (zap);
-}
-
/* Return the name of the temporary directory to use for .o files, and
arrange for the directory to be removed at shutdown. */
@@ -465,7 +448,18 @@ get_compile_file_tempdir (void)
perror_with_name (_("Could not make temporary directory"));
tempdir_name = xstrdup (tempdir_name);
- make_final_cleanup (do_rmdir, tempdir_name);
+ add_final_cleanup ([] ()
+ {
+ char *zap;
+ int wstat;
+
+ gdb_assert (startswith (tempdir_name, TMP_PREFIX));
+ zap = concat ("rm -rf ", tempdir_name, (char *) NULL);
+ wstat = system (zap);
+ if (wstat == -1 || !WIFEXITED (wstat) || WEXITSTATUS (wstat) != 0)
+ warning (_("Could not remove temporary directory %s"), tempdir_name);
+ XDELETEVEC (zap);
+ });
return tempdir_name;
}