3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <lib_internal/util.h>
26 #include <ensc_vector/vector.h>
45 static struct Undo undo_data = {
52 struct FuncData const * ptr;
54 if (undo_data.pid_ != getpid())
55 return; // skip 'exit()' from forked processes
57 for (ptr=Vector_end(&undo_data.funcs);
58 ptr!=Vector_begin(&undo_data.funcs);
60 (ptr[-1].fn)(ptr[-1].args);
66 if (undo_data.pid_!=-1) {
67 WRITE_MSG(2, "Undo already initialized; internal error...\n");
71 undo_data.pid_ = getpid();
72 Vector_init(&undo_data.funcs, sizeof(struct FuncData));
74 atexit(&atexitHandler);
78 Undo_addTask(ExitFunction fn, void const *args)
80 struct FuncData *tmp = Vector_pushback(&undo_data.funcs);
81 assert(tmp!=0); // Vector_pushback never returns a null-pointer
90 Vector_free(&undo_data.funcs);