2 Remove a directory and all its contents.
4 Copyright (C) 1992 Ian Lance Taylor
6 This file is part of the Taylor UUCP package.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 The author of the program may be contacted at ian@airs.com or
23 c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
38 static int isremove_dir P((const char *, struct stat *, int));
40 /* Keep a list of directories to be removed. */
44 struct sdirlist *qnext;
48 static struct sdirlist *qSdirlist;
50 /* Remove a directory and all files in it. */
62 if (ftw ((char *) zdir, isremove_dir, 5) != 0)
64 ulog (LOG_ERROR, "ftw: %s", strerror (errno));
71 struct sdirlist *qnext;
73 if (rmdir (q->zdir) != 0)
75 ulog (LOG_ERROR, "rmdir (%s): %s", q->zdir, strerror (errno));
87 /* Remove a file in a directory. */
91 isremove_dir (zfile, qstat, iflag)
96 if (iflag == FTW_D || iflag == FTW_DNR)
100 q = (struct sdirlist *) xmalloc (sizeof (struct sdirlist));
101 q->qnext = qSdirlist;
102 q->zdir = zbufcpy (zfile);
107 if (remove (zfile) != 0)
108 ulog (LOG_ERROR, "remove (%s): %s", zfile, strerror (errno));