summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/remove.c
blob: 25bbd3bd25f6dab4a372d96240707c719932ab94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "asm/unistd_64.h" // for __NR_unlinkat
#include "errno.h"	   // for EISDIR, errno

#include <fcntl.h>   // for AT_FDCWD, AT_REMOVEDIR
#include <stdio.h>   // for remove
#include <syscall.h> // for __syscall_3, syscall

int remove(const char *path)
{
	if (syscall(unlinkat, AT_FDCWD, path, 0) < 0) {
		if (errno == EISDIR) {
			return syscall(unlinkat, AT_FDCWD, path, AT_REMOVEDIR);
		} else {
			return -1;
		}
	}

	return 0;
}