add ext4,vfat and tar.bz2
[u-tools.git] / u-tools / apps / tar / gnu / rmdir.c
blobb4aa63574fe27ef1b1c04d3ad8bcbec52fe17f2a
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-2011 Free Software
6 Foundation, Inc.
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/>. */
21 #include <config.h>
23 #include <unistd.h>
25 #include <errno.h>
26 #include <string.h>
28 #include "dosname.h"
30 #undef rmdir
32 /* Remove directory DIR.
33 Return 0 if successful, -1 if not. */
35 int
36 rpl_rmdir (char const *dir)
38 /* Work around cygwin 1.5.x bug where rmdir("dir/./") succeeds. */
39 size_t len = strlen (dir);
40 int result;
41 while (len && ISSLASH (dir[len - 1]))
42 len--;
43 if (len && dir[len - 1] == '.' && (1 == len || ISSLASH (dir[len - 2])))
45 errno = EINVAL;
46 return -1;
48 result = rmdir (dir);
49 /* Work around mingw bug, where rmdir("file/") fails with EINVAL
50 instead of ENOTDIR. We've already filtered out trailing ., the
51 only reason allowed by POSIX for EINVAL. */
52 if (result == -1 && errno == EINVAL)
53 errno = ENOTDIR;
54 return result;