1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Work around rmdir bugs.
5 Copyright (C) 1988, 1990, 1999, 2003-2006, 2009-2010 Free Software
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 #include <sys/types.h>
32 /* Remove directory DIR.
33 Return 0 if successful, -1 if not. */
36 rpl_rmdir (char const *dir)
39 /* Work around cygwin 1.5.x bug where rmdir("dir/./") succeeds. */
40 size_t len = strlen (dir);
42 while (len && ISSLASH (dir[len - 1]))
44 if (len && dir[len - 1] == '.' && (1 == len || ISSLASH (dir[len - 2])))
50 /* Work around mingw bug, where rmdir("file/") fails with EINVAL
51 instead of ENOTDIR. We've already filtered out trailing ., the
52 only reason allowed by POSIX for EINVAL. */
53 if (result == -1 && errno == EINVAL)
57 #else /* !HAVE_RMDIR */
58 /* rmdir adapted from GNU tar. FIXME: Delete this implementation in
59 2010 if no one reports a system with missing rmdir. */
64 if (stat (dir, &statbuf) != 0)
65 return -1; /* errno already set */
67 if (!S_ISDIR (statbuf.st_mode))
76 case -1: /* cannot fork */
77 return -1; /* errno already set */
79 case 0: /* child process */
80 execl ("/bin/rmdir", "rmdir", dir, (char *) 0);
83 default: /* parent process */
85 /* Wait for kid to finish. */
87 while (wait (&status) != cpid)
93 /* /bin/rmdir failed. */
100 #endif /* !HAVE_RMDIR */