1 /* 2 * Copyright 2002-2006, 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 // R5 compatibility 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