John Criswell | 1981c2e | 2005-11-28 15:49:15 +0000 | [diff] [blame] | 1 | //===-- remove.c - The remove function for the LLVM libc Library --*- C -*-===// |
| 2 | // |
| 3 | // A lot of this code is ripped gratuitously from glibc and libiberty. |
| 4 | // |
| 5 | //===----------------------------------------------------------------------===// |
| 6 | |
| 7 | /* ANSI C `remove' function to delete a file or directory. POSIX.1 version. |
| 8 | Copyright (C) 1995,96,97,2002 Free Software Foundation, Inc. |
| 9 | This file is part of the GNU C Library. |
| 10 | |
| 11 | The GNU C Library is free software; you can redistribute it and/or |
| 12 | modify it under the terms of the GNU Lesser General Public |
| 13 | License as published by the Free Software Foundation; either |
| 14 | version 2.1 of the License, or (at your option) any later version. |
| 15 | |
| 16 | The GNU C Library is distributed in the hope that it will be useful, |
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | Lesser General Public License for more details. |
| 20 | |
| 21 | You should have received a copy of the GNU Lesser General Public |
| 22 | License along with the GNU C Library; if not, write to the Free |
| 23 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 24 | 02111-1307 USA. */ |
| 25 | |
| 26 | #include <errno.h> |
| 27 | #include <stdio.h> |
| 28 | #include <unistd.h> |
| 29 | |
| 30 | int |
| 31 | remove (const char * file) |
| 32 | { |
| 33 | int save; |
| 34 | |
| 35 | save = errno; |
| 36 | if (rmdir (file) == 0) |
| 37 | return 0; |
| 38 | else if (errno == ENOTDIR && unlink (file) == 0) |
| 39 | { |
| 40 | errno = (save); |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | return -1; |
| 45 | } |
| 46 | |