Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handle classic (<10.5) stat

  • Loading branch information...
commit 299d40771431cbcecb89b40a1c34a468ab0faba8 1 parent 630a39e
Shinichiro Hamaji authored
Showing with 85 additions and 9 deletions.
  1. +71 −6 libmac/mac.c
  2. +11 −0 mach/stat_type.c
  3. +3 −3 rename.tab
View
77 libmac/mac.c
@@ -79,7 +79,7 @@ typedef uint32_t __darwin_uid_t;
typedef uint32_t __darwin_gid_t;
// From /usr/include/sys/stat.h
-typedef struct __darwin_stat64 {
+struct __darwin_stat64 {
__darwin_dev_t st_dev;
__darwin_mode_t st_mode;
__darwin_nlink_t st_nlink;
@@ -99,10 +99,50 @@ typedef struct __darwin_stat64 {
__uint32_t st_gen;
__int32_t st_lspare;
__int64_t st_qspare[2];
-} __darwin_stat64;
+};
+
+struct __darwin_stat {
+ __darwin_dev_t st_dev;
+ uint32_t st_ino;
+ __darwin_mode_t st_mode;
+ __darwin_nlink_t st_nlink;
+ __darwin_uid_t st_uid;
+ __darwin_gid_t st_gid;
+ __darwin_dev_t st_rdev;
+ struct __darwin_timespec st_atimespec;
+ struct __darwin_timespec st_mtimespec;
+ struct __darwin_timespec st_ctimespec;
+ off_t st_size;
+ // TODO(hamaji): the size is not checked after this field.
+ blkcnt_t st_blocks;
+ blksize_t st_blksize;
+ __uint32_t st_flags;
+ __uint32_t st_gen;
+ __int32_t st_lspare;
+ __int64_t st_qspare[2];
+};
+
+static void __translate_stat64(struct stat64* linux_buf,
+ struct __darwin_stat64* mac) {
+ // TODO(hamaji): this memset seems to cause overflow... why?
+ //memset(mac, 0, sizeof(*mac));
+ mac->st_dev = linux_buf->st_dev;
+ mac->st_mode = linux_buf->st_mode;
+ mac->st_nlink = linux_buf->st_nlink;
+ mac->st_ino = linux_buf->st_ino;
+ mac->st_uid = linux_buf->st_uid;
+ mac->st_gid = linux_buf->st_gid;
+ mac->st_rdev = linux_buf->st_rdev;
+ mac->st_size = linux_buf->st_size;
+ mac->st_blksize = linux_buf->st_blksize;
+ mac->st_blocks = linux_buf->st_blocks;
+ mac->st_atimespec.tv_sec = linux_buf->st_atime;
+ mac->st_mtimespec.tv_sec = linux_buf->st_mtime;
+ mac->st_ctimespec.tv_sec = linux_buf->st_ctime;
+}
static void __translate_stat(struct stat64* linux_buf,
- struct __darwin_stat64* mac) {
+ struct __darwin_stat* mac) {
// TODO(hamaji): this memset seems to cause overflow... why?
//memset(mac, 0, sizeof(*mac));
mac->st_dev = linux_buf->st_dev;
@@ -120,7 +160,32 @@ static void __translate_stat(struct stat64* linux_buf,
mac->st_ctimespec.tv_sec = linux_buf->st_ctime;
}
-int __darwin_stat(const char* path, struct __darwin_stat64* mac) {
+int __darwin_stat64(const char* path, struct __darwin_stat64* mac) {
+ LOGF("stat64: path=%s buf=%p\n", path, mac);
+ struct stat64 linux_buf;
+ int ret = stat64(path, &linux_buf);
+ __translate_stat64(&linux_buf, mac);
+ return ret;
+}
+
+int __darwin_fstat64(int fd, struct __darwin_stat64* mac) {
+ LOGF("fstat64: fd=%d buf=%p\n", fd, mac);
+ LOGF("fstat: size_offset=%d\n", (int)((char*)&mac->st_size - (char*)mac));
+ struct stat64 linux_buf;
+ int ret = fstat64(fd, &linux_buf);
+ __translate_stat64(&linux_buf, mac);
+ return ret;
+}
+
+int __darwin_lstat64(const char* path, struct __darwin_stat64* mac) {
+ LOGF("lstat64: path=%s buf=%p\n", path, mac);
+ struct stat64 linux_buf;
+ int ret = lstat64(path, &linux_buf);
+ __translate_stat64(&linux_buf, mac);
+ return ret;
+}
+
+int __darwin_stat(const char* path, struct __darwin_stat* mac) {
LOGF("stat: path=%s buf=%p\n", path, mac);
struct stat64 linux_buf;
int ret = stat64(path, &linux_buf);
@@ -128,7 +193,7 @@ int __darwin_stat(const char* path, struct __darwin_stat64* mac) {
return ret;
}
-int __darwin_fstat(int fd, struct __darwin_stat64* mac) {
+int __darwin_fstat(int fd, struct __darwin_stat* mac) {
LOGF("fstat: fd=%d buf=%p\n", fd, mac);
LOGF("fstat: size_offset=%d\n", (int)((char*)&mac->st_size - (char*)mac));
struct stat64 linux_buf;
@@ -137,7 +202,7 @@ int __darwin_fstat(int fd, struct __darwin_stat64* mac) {
return ret;
}
-int __darwin_lstat(const char* path, struct __darwin_stat64* mac) {
+int __darwin_lstat(const char* path, struct __darwin_stat* mac) {
LOGF("lstat: path=%s buf=%p\n", path, mac);
struct stat64 linux_buf;
int ret = lstat64(path, &linux_buf);
View
11 mach/stat_type.c
@@ -0,0 +1,11 @@
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/stat.h>
+
+int main(int argc, char* argv[]) {
+ struct stat buf;
+ int ret = stat("/tmp", &buf);
+ if (!S_ISDIR(buf.st_mode))
+ abort();
+ return 0;
+}
View
6 rename.tab
@@ -75,9 +75,9 @@ WRAP(readdir)
WRAP(stat)
WRAP(fstat)
WRAP(lstat)
-RENAME(stat$INODE64, __darwin_stat)
-RENAME(fstat$INODE64, __darwin_fstat)
-RENAME(lstat$INODE64, __darwin_lstat)
+RENAME(stat$INODE64, __darwin_stat64)
+RENAME(fstat$INODE64, __darwin_fstat64)
+RENAME(lstat$INODE64, __darwin_lstat64)
WRAP(open)
Please sign in to comment.
Something went wrong with that request. Please try again.