diff options
author | Eric Blake <ebb9@byu.net> | 2009-09-14 16:57:55 -0600 |
---|---|---|
committer | Eric Blake <ebb9@byu.net> | 2009-09-19 13:34:23 -0600 |
commit | 6ca71ffe395184749d849f5bba4771d6b2fbb7d6 (patch) | |
tree | 60b98e8958fdb4f5954cb9b0c14370b4e7a6ee77 /lib/remove.c | |
parent | 4a60ba548bf42233384fa86fd97cf0091514c553 (diff) | |
download | gnulib-6ca71ffe395184749d849f5bba4771d6b2fbb7d6.tar.gz |
remove: new module, for mingw and Solaris 9 bugs
Mingw obeys C89, but not POSIX, by not handling directories.
Solaris remove("file/") mistakenly succeeded.
* modules/remove: New file.
* lib/remove.c: Likewise.
* m4/remove.m4 (gl_FUNC_REMOVE): Likewise.
* m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Add witnesses.
* modules/stdio (Makefile.am): Use them.
* lib/stdio.in.h (remove): Declare replacement.
* MODULES.html.sh (systems lacking POSIX:2008): Mention module.
* doc/posix-functions/remove.texi (remove): Likewise.
* modules/remove-tests: New test.
* tests/test-remove.c: Likewise.
Signed-off-by: Eric Blake <ebb9@byu.net>
Diffstat (limited to 'lib/remove.c')
-rw-r--r-- | lib/remove.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/remove.c b/lib/remove.c new file mode 100644 index 0000000000..49863e52e0 --- /dev/null +++ b/lib/remove.c @@ -0,0 +1,43 @@ +/* Remove a file or directory. + Copyright (C) 2009 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* written by Eric Blake */ + +#include <config.h> + +#include <stdio.h> + +#include <errno.h> +#include <unistd.h> + +#undef remove + +/* Remove NAME from the file system. This works around C89 platforms + that don't handle directories like POSIX requires; it also works + around Solaris 9 bugs with trailing slash. */ +int +rpl_remove (char const *name) +{ + /* It is faster to just try rmdir, and fall back on unlink, than it + is to use lstat to see what we are about to remove. Technically, + it is more likely that we want unlink, not rmdir, but we cannot + guarantee the safety of unlink on directories. Trailing slash + bugs are handled by our rmdir and unlink wrappers. */ + int result = rmdir (name); + if (result && errno == ENOTDIR) + result = unlink (name); + return result; +} |