1 /* 2 * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <syscalls.h> 8 9 #include <sys/stat.h> 10 #include <errno.h> 11 12 13 #define RETURN_AND_SET_ERRNO(err) \ 14 if (err < 0) { \ 15 errno = err; \ 16 return -1; \ 17 } \ 18 return err; 19 20 21 // BeOS compatibility 22 #define BEOS_STAT_SIZE 60 23 24 25 int 26 stat(const char *path, struct stat *stat) 27 { 28 int status = _kern_read_stat(-1, path, true, stat, BEOS_STAT_SIZE/*sizeof(struct stat)*/); 29 30 RETURN_AND_SET_ERRNO(status); 31 } 32 33 34 int 35 fstat(int fd, struct stat *stat) 36 { 37 int status = _kern_read_stat(fd, NULL, false, stat, BEOS_STAT_SIZE/*sizeof(struct stat)*/); 38 39 RETURN_AND_SET_ERRNO(status); 40 } 41 42 43 int 44 lstat(const char *path, struct stat *stat) 45 { 46 int status = _kern_read_stat(-1, path, false, stat, BEOS_STAT_SIZE/*sizeof(struct stat)*/); 47 48 RETURN_AND_SET_ERRNO(status); 49 } 50 51 52 // #pragma mark - BeOS compatibility 53 54 55 #ifndef _KERNEL_MODE 56 57 int __be_stat(const char *path, struct stat *stat); 58 int __be_fstat(int fd, struct stat *stat); 59 int __be_lstat(const char *path, struct stat *stat); 60 61 62 int 63 __be_stat(const char *path, struct stat *stat) 64 { 65 int status = _kern_read_stat(-1, path, true, stat, BEOS_STAT_SIZE); 66 67 RETURN_AND_SET_ERRNO(status); 68 } 69 70 71 int 72 __be_fstat(int fd, struct stat *stat) 73 { 74 int status = _kern_read_stat(fd, NULL, false, stat, BEOS_STAT_SIZE); 75 76 RETURN_AND_SET_ERRNO(status); 77 } 78 79 80 int 81 __be_lstat(const char *path, struct stat *stat) 82 { 83 int status = _kern_read_stat(-1, path, false, stat, BEOS_STAT_SIZE); 84 85 RETURN_AND_SET_ERRNO(status); 86 } 87 88 #endif // !_KERNEL_MODE 89