| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: rmdir.c,v 1.26 2011/08/29 14:49:38 joerg Exp $ */ | | 1 | /* $NetBSD: rmdir.c,v 1.26.22.1 2017/08/19 05:23:16 snj Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1992, 1993, 1994 | | 4 | * Copyright (c) 1992, 1993, 1994 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -29,27 +29,27 @@ | | | @@ -29,27 +29,27 @@ |
29 | * SUCH DAMAGE. | | 29 | * SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | #ifndef lint | | 33 | #ifndef lint |
34 | __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\ | | 34 | __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\ |
35 | The Regents of the University of California. All rights reserved."); | | 35 | The Regents of the University of California. All rights reserved."); |
36 | #endif /* not lint */ | | 36 | #endif /* not lint */ |
37 | | | 37 | |
38 | #ifndef lint | | 38 | #ifndef lint |
39 | #if 0 | | 39 | #if 0 |
40 | static char sccsid[] = "@(#)rmdir.c 8.3 (Berkeley) 4/2/94"; | | 40 | static char sccsid[] = "@(#)rmdir.c 8.3 (Berkeley) 4/2/94"; |
41 | #else | | 41 | #else |
42 | __RCSID("$NetBSD: rmdir.c,v 1.26 2011/08/29 14:49:38 joerg Exp $"); | | 42 | __RCSID("$NetBSD: rmdir.c,v 1.26.22.1 2017/08/19 05:23:16 snj Exp $"); |
43 | #endif | | 43 | #endif |
44 | #endif /* not lint */ | | 44 | #endif /* not lint */ |
45 | | | 45 | |
46 | #include <sys/param.h> | | 46 | #include <sys/param.h> |
47 | | | 47 | |
48 | #include <err.h> | | 48 | #include <err.h> |
49 | #include <locale.h> | | 49 | #include <locale.h> |
50 | #include <stdio.h> | | 50 | #include <stdio.h> |
51 | #include <stdlib.h> | | 51 | #include <stdlib.h> |
52 | #include <string.h> | | 52 | #include <string.h> |
53 | #include <unistd.h> | | 53 | #include <unistd.h> |
54 | | | 54 | |
55 | static int rm_path(char *); | | 55 | static int rm_path(char *); |
| @@ -93,26 +93,30 @@ main(int argc, char *argv[]) | | | @@ -93,26 +93,30 @@ main(int argc, char *argv[]) |
93 | } | | 93 | } |
94 | | | 94 | |
95 | static int | | 95 | static int |
96 | rm_path(char *path) | | 96 | rm_path(char *path) |
97 | { | | 97 | { |
98 | char *p; | | 98 | char *p; |
99 | | | 99 | |
100 | while ((p = strrchr(path, '/')) != NULL) { | | 100 | while ((p = strrchr(path, '/')) != NULL) { |
101 | *p = 0; | | 101 | *p = 0; |
102 | if (p[1] == 0) | | 102 | if (p[1] == 0) |
103 | /* Ignore trailing '/' on deleted name */ | | 103 | /* Ignore trailing '/' on deleted name */ |
104 | continue; | | 104 | continue; |
105 | | | 105 | |
| | | 106 | if (*path == 0) |
| | | 107 | /* At top level (root) directory */ |
| | | 108 | break; |
| | | 109 | |
106 | if (rmdir(path) < 0) { | | 110 | if (rmdir(path) < 0) { |
107 | warn("%s", path); | | 111 | warn("%s", path); |
108 | return (1); | | 112 | return (1); |
109 | } | | 113 | } |
110 | } | | 114 | } |
111 | | | 115 | |
112 | return (0); | | 116 | return (0); |
113 | } | | 117 | } |
114 | | | 118 | |
115 | static void | | 119 | static void |
116 | usage(void) | | 120 | usage(void) |
117 | { | | 121 | { |
118 | (void)fprintf(stderr, "usage: %s [-p] directory ...\n", getprogname()); | | 122 | (void)fprintf(stderr, "usage: %s [-p] directory ...\n", getprogname()); |