Sat Aug 19 05:23:16 2017 UTC ()
Pull up following revision(s) (requested by ginsbach in ticket #1488):
	bin/rmdir/rmdir.c: revision 1.27
PR/48182: Fix rmdir -p handling of top-level (root) directory.


(snj)
diff -r1.26 -r1.26.22.1 src/bin/rmdir/rmdir.c

cvs diff -r1.26 -r1.26.22.1 src/bin/rmdir/rmdir.c (expand / switch to unified diff)

--- src/bin/rmdir/rmdir.c 2011/08/29 14:49:38 1.26
+++ src/bin/rmdir/rmdir.c 2017/08/19 05:23:16 1.26.22.1
@@ -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
40static char sccsid[] = "@(#)rmdir.c 8.3 (Berkeley) 4/2/94"; 40static 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
55static int rm_path(char *); 55static 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
95static int 95static int
96rm_path(char *path) 96rm_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
115static void 119static void
116usage(void) 120usage(void)
117{ 121{
118 (void)fprintf(stderr, "usage: %s [-p] directory ...\n", getprogname()); 122 (void)fprintf(stderr, "usage: %s [-p] directory ...\n", getprogname());