Annotation of coherent/g/usr/lib/uucp/tay104/unix/srmdir.c, revision 1.1

1.1     ! root        1: /* srmdir.c
        !             2:    Remove a directory and all its contents.
        !             3: 
        !             4:    Copyright (C) 1992 Ian Lance Taylor
        !             5: 
        !             6:    This file is part of the Taylor UUCP package.
        !             7: 
        !             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.
        !            12: 
        !            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.
        !            17: 
        !            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., 675 Mass Ave, Cambridge, MA 02139, USA.
        !            21: 
        !            22:    The author of the program may be contacted at [email protected] or
        !            23:    c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
        !            24:    */
        !            25: 
        !            26: #include "uucp.h"
        !            27: 
        !            28: #include "uudefs.h"
        !            29: #include "sysdep.h"
        !            30: #include "system.h"
        !            31: 
        !            32: #include <errno.h>
        !            33: 
        !            34: #if HAVE_FTW_H
        !            35: #include <ftw.h>
        !            36: #endif
        !            37: 
        !            38: static int isremove_dir P((const char *, const struct stat *, int));
        !            39: 
        !            40: /* Keep a list of directories to be removed.  */
        !            41: 
        !            42: struct sdirlist
        !            43: {
        !            44:   struct sdirlist *qnext;
        !            45:   char *zdir;
        !            46: };
        !            47: 
        !            48: static struct sdirlist *qSdirlist;
        !            49: 
        !            50: /* Remove a directory and all files in it.  */
        !            51: 
        !            52: boolean
        !            53: fsysdep_rmdir (zdir)
        !            54:      const char *zdir;
        !            55: {
        !            56:   boolean fret;
        !            57:   struct sdirlist *q;
        !            58: 
        !            59:   qSdirlist = NULL;
        !            60: 
        !            61:   fret = TRUE;
        !            62:   if (ftw ((char *) zdir, isremove_dir, 5) != 0)
        !            63:     {
        !            64:       ulog (LOG_ERROR, "ftw: %s", strerror (errno));
        !            65:       fret = FALSE;
        !            66:     }
        !            67: 
        !            68:   q = qSdirlist;
        !            69:   while (q != NULL)
        !            70:     {
        !            71:       struct sdirlist *qnext;
        !            72:       
        !            73:       if (rmdir (q->zdir) != 0)
        !            74:        {
        !            75:          ulog (LOG_ERROR, "rmdir (%s): %s", q->zdir, strerror (errno));
        !            76:          fret = FALSE;
        !            77:        }
        !            78:       ubuffree (q->zdir);
        !            79:       qnext = q->qnext;
        !            80:       xfree ((pointer) q);
        !            81:       q = qnext;
        !            82:     }
        !            83: 
        !            84:   return fret;
        !            85: }
        !            86: 
        !            87: /* Remove a file in a directory.  */
        !            88: 
        !            89: /*ARGSUSED*/
        !            90: static int
        !            91: isremove_dir (zfile, qstat, iflag)
        !            92:      const char *zfile;
        !            93:      const struct stat *qstat;
        !            94:      int iflag;
        !            95: {
        !            96:   if (iflag == FTW_D || iflag == FTW_DNR)
        !            97:     {
        !            98:       struct sdirlist *q;
        !            99: 
        !           100:       q = (struct sdirlist *) xmalloc (sizeof (struct sdirlist));
        !           101:       q->qnext = qSdirlist;
        !           102:       q->zdir = zbufcpy (zfile);
        !           103:       qSdirlist = q;
        !           104:     }
        !           105:   else
        !           106:     {
        !           107:       if (remove (zfile) != 0)
        !           108:        ulog (LOG_ERROR, "remove (%s): %s", zfile, strerror (errno));
        !           109:     }
        !           110: 
        !           111:   return 0;
        !           112: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.