xref: /netbsd-src/external/gpl3/gdb/dist/gdbsupport/gdb_unlinker.h (revision 5ba1f45f2a09259cc846f20c7c5501604d633c90)
18dffb485Schristos /* Unlinking class
28dffb485Schristos 
3*5ba1f45fSchristos    Copyright (C) 2016-2024 Free Software Foundation, Inc.
48dffb485Schristos 
58dffb485Schristos    This file is part of GDB.
68dffb485Schristos 
78dffb485Schristos    This program is free software; you can redistribute it and/or modify
88dffb485Schristos    it under the terms of the GNU General Public License as published by
98dffb485Schristos    the Free Software Foundation; either version 3 of the License, or
108dffb485Schristos    (at your option) any later version.
118dffb485Schristos 
128dffb485Schristos    This program is distributed in the hope that it will be useful,
138dffb485Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
148dffb485Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
158dffb485Schristos    GNU General Public License for more details.
168dffb485Schristos 
178dffb485Schristos    You should have received a copy of the GNU General Public License
188dffb485Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
198dffb485Schristos 
208dffb485Schristos #ifndef COMMON_GDB_UNLINKER_H
218dffb485Schristos #define COMMON_GDB_UNLINKER_H
228dffb485Schristos 
238dffb485Schristos namespace gdb
248dffb485Schristos {
258dffb485Schristos 
268dffb485Schristos /* An object of this class holds a filename and, when the object goes
278dffb485Schristos    of scope, the file is removed using unlink.
288dffb485Schristos 
298dffb485Schristos    A user of this class can request that the file be preserved using
308dffb485Schristos    the "keep" method.  */
318dffb485Schristos class unlinker
328dffb485Schristos {
338dffb485Schristos  public:
348dffb485Schristos 
358dffb485Schristos   unlinker (const char *filename) ATTRIBUTE_NONNULL (2)
368dffb485Schristos     : m_filename (filename)
378dffb485Schristos   {
388dffb485Schristos     gdb_assert (filename != NULL);
398dffb485Schristos   }
408dffb485Schristos 
418dffb485Schristos   ~unlinker ()
428dffb485Schristos   {
438dffb485Schristos     if (m_filename != NULL)
448dffb485Schristos       unlink (m_filename);
458dffb485Schristos   }
468dffb485Schristos 
478dffb485Schristos   /* Keep the file, rather than unlink it.  */
488dffb485Schristos   void keep ()
498dffb485Schristos   {
508dffb485Schristos     m_filename = NULL;
518dffb485Schristos   }
528dffb485Schristos 
538dffb485Schristos  private:
548dffb485Schristos 
558dffb485Schristos   const char *m_filename;
568dffb485Schristos };
578dffb485Schristos 
588dffb485Schristos }
598dffb485Schristos 
608dffb485Schristos #endif /* COMMON_GDB_UNLINKER_H */
61