1 /* 2 * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <errno.h> 8 #include <stdlib.h> 9 #include <unistd.h> 10 11 #include <errno_private.h> 12 #include <syscalls.h> 13 #include <syscall_utils.h> 14 15 16 int 17 chdir(const char *path) 18 { 19 RETURN_AND_SET_ERRNO(_kern_setcwd(AT_FDCWD, path)); 20 } 21 22 23 int 24 fchdir(int fd) 25 { 26 RETURN_AND_SET_ERRNO(_kern_setcwd(fd, NULL)); 27 } 28 29 30 char * 31 getcwd(char *buffer, size_t size) 32 { 33 bool allocated = false; 34 status_t status; 35 36 if (buffer == NULL) { 37 buffer = malloc(size = PATH_MAX); 38 if (buffer == NULL) { 39 __set_errno(B_NO_MEMORY); 40 return NULL; 41 } 42 43 allocated = true; 44 } 45 46 status = _kern_getcwd(buffer, size); 47 if (status < B_OK) { 48 if (allocated) 49 free(buffer); 50 51 __set_errno(status); 52 return NULL; 53 } 54 return buffer; 55 } 56 57 58 int 59 rmdir(const char *path) 60 { 61 RETURN_AND_SET_ERRNO(_kern_remove_dir(AT_FDCWD, path)); 62 } 63 64