VirtualBox

source: kBuild/trunk/src/gmake/kmkbuiltin/rmdir.c@ 609

最後變更 在這個檔案從609是 603,由 bird 提交於 18 年 前

typo.

檔案大小: 3.8 KB
 
1/*-
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#if 0
31#ifndef lint
32static char const copyright[] =
33"@(#) Copyright (c) 1992, 1993, 1994\n\
34 The Regents of the University of California. All rights reserved.\n";
35#endif /* not lint */
36
37#ifndef lint
38static char sccsid[] = "@(#)rmdir.c 8.3 (Berkeley) 4/2/94";
39#endif /* not lint */
40#endif
41#if 0
42#include <sys/cdefs.h>
43__FBSDID("$FreeBSD: src/bin/rmdir/rmdir.c,v 1.20 2005/01/26 06:51:28 ssouhlal Exp $");
44#endif
45
46#include "err.h"
47#include <stdio.h>
48#include <stdlib.h>
49#include <string.h>
50#ifndef _MSC_VER
51#include <unistd.h>
52#else
53#include <malloc.h>
54#include "mscfakes.h"
55#endif
56
57static int rm_path(char *);
58static int usage(void);
59
60static int pflag;
61static int vflag;
62
63int
64kmk_builtin_rmdir(int argc, char *argv[])
65{
66 int ch, errors;
67
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
82 while ((ch = getopt(argc, argv, "pv")) != -1)
83 switch(ch) {
84 case 'p':
85 pflag = 1;
86 break;
87 case 'v':
88 vflag = 1;
89 break;
90 case '?':
91 default:
92 return usage();
93 }
94 argc -= optind;
95 argv += optind;
96
97 if (argc == 0)
98 return usage();
99
100 for (errors = 0; *argv; argv++) {
101 if (rmdir(*argv) < 0) {
102 warn("%s", *argv);
103 errors = 1;
104 } else {
105 if (vflag)
106 printf("%s\n", *argv);
107 if (pflag)
108 errors |= rm_path(*argv);
109 }
110 }
111
112 return errors;
113}
114
115static int
116rm_path(char *path)
117{
118 char *p;
119 const size_t len = strlen(path);
120 p = alloca(len + 1);
121 path = memcpy(p, path, len + 1);
122
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;
132 while (--p > path && *p == '/')
133 ;
134 *++p = '\0';
135 while ((p = strrchr(path, '/')) != NULL) {
136 /* Delete trailing slashes. */
137 while (--p >= path && *p == '/')
138 ;
139 *++p = '\0';
140 if (p == path)
141 break;
142#if defined(_MSC_VER) || defined(__EMX__)
143 if (p[-1] == ':' && p - 2 == path)
144 break;
145#endif
146
147 if (rmdir(path) < 0) {
148 warn("%s", path);
149 return (1);
150 }
151 if (vflag)
152 printf("%s\n", path);
153 }
154
155 return (0);
156}
157
158static int
159usage(void)
160{
161
162 (void)fprintf(stderr, "usage: rmdir [-pv] directory ...\n");
163 return 1;
164}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette