OSDN Git Service

hidden_def/hidden_proto: convert all users (I hope) termios split, add some missing...
[uclinux-h8/uClibc.git] / libc / stdio / remove.c
1 /* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
2  *
3  * GNU Library General Public License (LGPL) version 2 or later.
4  *
5  * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
6  */
7
8 #include "_stdio.h"
9
10 #include <unistd.h>
11 #include <errno.h>
12
13 libc_hidden_proto(rmdir)
14 libc_hidden_proto(unlink)
15
16 /* SUSv3 states:
17  *   If path does not name a directory, remove(path) shall be equivalent
18  *   to unlink(path).  If path names a directory, remove(path) shall be
19  *   equivalent to rmdir(path). 
20  */
21
22 int remove(register const char *filename)
23 {
24         int saved_errno = errno;
25         int rv;
26
27         if (((rv = rmdir(filename)) < 0) && (errno == ENOTDIR)) {
28                 __set_errno(saved_errno); /* Need to restore errno. */
29                 rv = unlink(filename);
30         }
31         return rv;
32 }
33 libc_hidden_proto(remove)
34 libc_hidden_def(remove)