Ignore:
Timestamp:
Nov 26, 2006, 1:19:19 AM (19 years ago)
Author:
bird
Message:

o Added rmdir as builtin and external command.
o Made mkdir not modify the argument strings.
o Made mkdir deal properly with DOS slashes on OS/2 and Windows.

File:
1 edited

Legend:

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

    r598 r601  
    3939#endif /* not lint */
    4040#endif
     41#if 0
    4142#include <sys/cdefs.h>
    4243__FBSDID("$FreeBSD: src/bin/rmdir/rmdir.c,v 1.20 2005/01/26 06:51:28 ssouhlal Exp $");
     44#endif
    4345
    44 #include <err.h>
     46#include "err.h"
    4547#include <stdio.h>
    4648#include <stdlib.h>
    4749#include <string.h>
     50#ifndef _MSC_VER
    4851#include <unistd.h>
     52#else
     53#include <malloc.h>
     54#include "mscfakes.h"
     55#endif
    4956
    50 static int rm_path(char *);
    51 static void usage(void);
     57static int rm_path(const char *);
     58static int usage(void);
    5259
    5360static int pflag;
     
    5562
    5663int
    57 main(int argc, char *argv[])
     64kmk_builtin_rmdir(int argc, char *argv[])
    5865{
    5966        int ch, errors;
    6067
     68        /* reinitialize globals */
     69        vflag = 0;
     70       
     71        /* kmk: reset getopt and set progname */
     72        g_progname = argv[0];
     73        opterr = 1;
     74        optarg = NULL;
     75        optopt = 0;
     76#if defined(__FreeBSD__) || defined(__EMX__) || defined(__APPLE__)
     77        optreset = 1;
     78        optind = 1;
     79#else
     80        optind = 0; /* init */
     81#endif
    6182        while ((ch = getopt(argc, argv, "pv")) != -1)
    6283                switch(ch) {
     
    6990                case '?':
    7091                default:
    71                         usage();
     92                        return usage();
    7293                }
    7394        argc -= optind;
     
    7596
    7697        if (argc == 0)
    77                 usage();
     98                return usage();
    7899
    79100        for (errors = 0; *argv; argv++) {
     
    89110        }
    90111
    91         exit(errors);
     112        return errors;
    92113}
    93114
     
    96117{
    97118        char *p;
     119        const size_t len = strlen(path);
     120        p = alloca(len + 1);
     121        path = memcpy(p, path, len + 1);
    98122
    99         p = path + strlen(path);
     123#if defined(_MSC_VER) || defined(__EMX__)
     124        p = strchr(path, '\\');
     125        while (p) {
     126                *p++ = '/';
     127                p = strchr(p, '\\');
     128        }
     129#endif
     130
     131        p = path + len;
    100132        while (--p > path && *p == '/')
    101133                ;
     
    108140                if (p == path)
    109141                        break;
     142#if defined(_MSC_VER) || defined(__EMX__)
     143                if (p[-1] == ':' && p - 2 == path)
     144                        break;
     145#endif
    110146
    111147                if (rmdir(path) < 0) {
     
    120156}
    121157
    122 static void
     158static int
    123159usage(void)
    124160{
    125161
    126162        (void)fprintf(stderr, "usage: rmdir [-pv] directory ...\n");
    127         exit(1);
     163        return 1;
    128164}
Note: See TracChangeset for help on using the changeset viewer.