blob: af285073369b27debd4197a9d5aca4732adf851c [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* 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/* SUSv3 states:
14 * If path does not name a directory, remove(path) shall be equivalent
15 * to unlink(path). If path names a directory, remove(path) shall be
16 * equivalent to rmdir(path).
17 */
18
19int remove(register const char *filename)
20{
21 int saved_errno = errno;
22 int rv;
23
24 rv = rmdir(filename);
25 if ((rv < 0) && (errno == ENOTDIR)) {
26 __set_errno(saved_errno); /* Need to restore errno. */
27 rv = unlink(filename);
28 }
29 return rv;
30}
31libc_hidden_def(remove)