Ignore:
Timestamp:
Dec 8, 2006, 4:45:35 AM (19 years ago)
Author:
bird
Message:

Added --ignore-fail-on-non-empty similar as described in the GNU coreutils manpage.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmake/kmkbuiltin/rmdir.c

    r603 r684  
    4848#include <stdlib.h>
    4949#include <string.h>
     50#include <errno.h>
    5051#ifndef _MSC_VER
    5152#include <unistd.h>
     
    6061static int pflag;
    6162static int vflag;
     63static int ignore_fail_on_non_empty;
     64
     65static struct option long_options[] =
     66{
     67    { "ignore-fail-on-non-empty",   no_argument, 0, 260 },
     68    { "parents",                    no_argument, 0, 'p' },
     69    { "verbose",                    no_argument, 0, 'v' },
     70    { 0, 0,     0, 0 },
     71};
     72
    6273
    6374int
     
    6778
    6879        /* reinitialize globals */
    69         vflag = 0;
     80        ignore_fail_on_non_empty = vflag = pflag = 0;
    7081       
    7182        /* kmk: reset getopt and set progname */
     
    8091        optind = 0; /* init */
    8192#endif
    82         while ((ch = getopt(argc, argv, "pv")) != -1)
     93        while ((ch = getopt_long(argc, argv, "pv", long_options, NULL)) != -1)
    8394                switch(ch) {
    8495                case 'p':
     
    8798                case 'v':
    8899                        vflag = 1;
     100                        break;
     101                case 260:
     102                        ignore_fail_on_non_empty = 1;
    89103                        break;
    90104                case '?':
     
    100114        for (errors = 0; *argv; argv++) {
    101115                if (rmdir(*argv) < 0) {
    102                         warn("%s", *argv);
    103                         errors = 1;
     116                        if (!ignore_fail_on_non_empty || errno != ENOTEMPTY) {
     117                                warn("%s", *argv);
     118                                errors = 1;
     119                        }
    104120                } else {
    105121                        if (vflag)
     
    146162
    147163                if (rmdir(path) < 0) {
     164                        if (ignore_fail_on_non_empty && errno != ENOTEMPTY)
     165                                break;
    148166                        warn("%s", path);
    149167                        return (1);
Note: See TracChangeset for help on using the changeset viewer.