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