xref: /haiku/src/system/libroot/posix/stdio/remove.c (revision fc7456e9b1ec38c941134ed6d01c438cf289381e)
1 /*
2  * Copyright 2004-2009, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <stdio.h>
8 
9 #include <errno.h>
10 
11 #include <errno_private.h>
12 #include <syscalls.h>
13 
14 
15 int
16 remove(const char* path)
17 {
18 	// TODO: find a better way that does not require two syscalls for directories
19 	int status = _kern_unlink(AT_FDCWD, path);
20 	if (status == B_IS_A_DIRECTORY)
21 		status = _kern_remove_dir(AT_FDCWD, path);
22 
23 	if (status != B_OK) {
24 		__set_errno(status);
25 		return -1;
26 	}
27 
28 	return status;
29 }
30