headers/bsd: Add sys/queue.h.
[haiku.git] / src / system / libroot / posix / unistd / directory.c
blob57d5e5f7eb9d91f8005a34eaef91e30ab21641e5
1 /*
2 * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <errno.h>
8 #include <stdlib.h>
9 #include <unistd.h>
11 #include <errno_private.h>
12 #include <syscalls.h>
13 #include <syscall_utils.h>
16 int
17 chdir(const char *path)
19 RETURN_AND_SET_ERRNO(_kern_setcwd(-1, path));
23 int
24 fchdir(int fd)
26 RETURN_AND_SET_ERRNO(_kern_setcwd(fd, NULL));
30 char *
31 getcwd(char *buffer, size_t size)
33 bool allocated = false;
34 status_t status;
36 if (buffer == NULL) {
37 buffer = malloc(size = PATH_MAX);
38 if (buffer == NULL) {
39 __set_errno(B_NO_MEMORY);
40 return NULL;
43 allocated = true;
46 status = _kern_getcwd(buffer, size);
47 if (status < B_OK) {
48 if (allocated)
49 free(buffer);
51 __set_errno(status);
52 return NULL;
54 return buffer;
58 int
59 rmdir(const char *path)
61 RETURN_AND_SET_ERRNO(_kern_remove_dir(-1, path));