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