Permalink
Browse files

Fix opendir/readdir/closedir

For symbols with $INODE64, we should return the dirent with the new layout.
  • Loading branch information...
1 parent 578be2b commit 630a39e2c594ef52ccea5c427218607899ad86ce Shinichiro Hamaji committed Dec 12, 2011
Showing with 54 additions and 3 deletions.
  1. +30 −2 libmac/mac.c
  2. +22 −0 mach/dirent.c
  3. +2 −1 rename.tab
View
@@ -146,16 +146,43 @@ int __darwin_lstat(const char* path, struct __darwin_stat64* mac) {
}
// From /usr/include/sys/dirent.h
+#define __DARWIN_MAXPATHLEN 1024
+struct __darwin_dirent64 {
+ uint64_t d_ino;
+ uint64_t d_seekoff;
+ uint16_t d_reclen;
+ uint16_t d_namlen;
+ uint8_t d_type;
+ char d_name[__DARWIN_MAXPATHLEN];
+};
+
#define __DARWIN_MAXNAMLEN 255
struct __darwin_dirent {
- __darwin_ino64_t d_ino;
+ uint32_t d_ino;
uint16_t d_reclen;
uint8_t d_type;
uint8_t d_namlen;
char d_name[__DARWIN_MAXNAMLEN + 1];
};
-struct __darwin_dirent* readdir$INODE64(DIR* dirp) {
+struct __darwin_dirent64* __darwin_readdir64(DIR* dirp) {
+ static struct __darwin_dirent64 mac;
+ struct dirent* linux_buf = readdir(dirp);
+ if (!linux_buf) {
+ return NULL;
+ }
+ mac.d_ino = linux_buf->d_ino;
+ mac.d_reclen = linux_buf->d_reclen;
+ mac.d_type = linux_buf->d_type;
+ mac.d_namlen = strlen(linux_buf->d_name);
+ // TODO(hamaji): I hope this won't be used.
+ mac.d_seekoff = 0;
+ strcpy(mac.d_name, linux_buf->d_name);
+ LOGF("readdir64: %s\n", mac.d_name);
+ return &mac;
+}
+
+struct __darwin_dirent* __darwin_readdir(DIR* dirp) {
static struct __darwin_dirent mac;
struct dirent* linux_buf = readdir(dirp);
if (!linux_buf) {
@@ -166,6 +193,7 @@ struct __darwin_dirent* readdir$INODE64(DIR* dirp) {
mac.d_type = linux_buf->d_type;
mac.d_namlen = strlen(linux_buf->d_name);
strcpy(mac.d_name, linux_buf->d_name);
+ LOGF("readdir: %s\n", mac.d_name);
return &mac;
}
View
@@ -0,0 +1,22 @@
+#include <dirent.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+
+int main() {
+ DIR* dir = opendir("/tmp");
+ if (!dir)
+ abort();
+ int found = 0;
+ struct dirent* ent;
+ while ((ent = readdir(dir)) != NULL) {
+ printf("%s\n", ent->d_name);
+ if (!strcmp(ent->d_name, "."))
+ found = 1;
+ }
+ closedir(dir);
+ if (!found)
+ abort();
+ return 0;
+}
View
@@ -69,7 +69,8 @@ RENAME(__toupper, toupper)
RENAME(__tolower, tolower)
RENAME(opendir$INODE64, opendir)
-RENAME(readdir$INODE64, readdir)
+RENAME(readdir$INODE64, __darwin_readdir64)
+WRAP(readdir)
WRAP(stat)
WRAP(fstat)

0 comments on commit 630a39e

Please sign in to comment.