gdb_unlinker.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Unlinking class
  2. Copyright (C) 2016-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef COMMON_GDB_UNLINKER_H
  15. #define COMMON_GDB_UNLINKER_H
  16. namespace gdb
  17. {
  18. /* An object of this class holds a filename and, when the object goes
  19. of scope, the file is removed using unlink.
  20. A user of this class can request that the file be preserved using
  21. the "keep" method. */
  22. class unlinker
  23. {
  24. public:
  25. unlinker (const char *filename) ATTRIBUTE_NONNULL (2)
  26. : m_filename (filename)
  27. {
  28. gdb_assert (filename != NULL);
  29. }
  30. ~unlinker ()
  31. {
  32. if (m_filename != NULL)
  33. unlink (m_filename);
  34. }
  35. /* Keep the file, rather than unlink it. */
  36. void keep ()
  37. {
  38. m_filename = NULL;
  39. }
  40. private:
  41. const char *m_filename;
  42. };
  43. }
  44. #endif /* COMMON_GDB_UNLINKER_H */