Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 15a2274

Browse files
committed
Merge pull request #1435 from smolt/osx-64bit-inode
OS X - Use 64-bit inode stat and dirent functions
2 parents f7604ef + 79f3042 commit 15a2274

File tree

3 files changed

+78
-43
lines changed

3 files changed

+78
-43
lines changed

src/core/sys/posix/dirent.d

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,28 @@ else version( OSX )
9696
DT_WHT = 14
9797
}
9898

99-
align(4)
99+
// _DARWIN_FEATURE_64_BIT_INODE dirent is default for Mac OSX >10.5 and is
100+
// only meaningful type for other OS X/Darwin variants (e.g. iOS).
101+
// man dir(5) has some info, man stat(2) gives details.
100102
struct dirent
101103
{
102104
ino_t d_ino;
105+
alias d_fileno = d_ino;
106+
ulong d_seekoff;
103107
ushort d_reclen;
108+
ushort d_namlen;
104109
ubyte d_type;
105-
ubyte d_namlen;
106-
char[256] d_name;
110+
char[1024] d_name;
107111
}
108112

109113
struct DIR
110114
{
111115
// Managed by OS
112116
}
113117

114-
dirent* readdir(DIR*);
118+
// OS X maintains backwards compatibility with older binaries using 32-bit
119+
// inode functions by appending $INODE64 to newer 64-bit inode functions.
120+
pragma(mangle, "readdir$INODE64") dirent* readdir(DIR*);
115121
}
116122
else version( FreeBSD )
117123
{
@@ -205,10 +211,30 @@ else
205211
static assert(false, "Unsupported platform");
206212
}
207213

208-
int closedir(DIR*);
209-
DIR* opendir(in char*);
210-
//dirent* readdir(DIR*);
211-
void rewinddir(DIR*);
214+
version( OSX )
215+
{
216+
version( D_LP64 )
217+
{
218+
int closedir(DIR*);
219+
pragma(mangle, "opendir$INODE64") DIR* opendir(in char*);
220+
pragma(mangle, "rewinddir$INODE64") void rewinddir(DIR*);
221+
}
222+
else
223+
{
224+
// 32-bit mangles __DARWIN_UNIX03 specific functions with $UNIX2003 to
225+
// maintain backward compatibility with binaries build pre 10.5
226+
pragma(mangle, "closedir$UNIX2003") int closedir(DIR*);
227+
pragma(mangle, "opendir$INODE64$UNIX2003") DIR* opendir(in char*);
228+
pragma(mangle, "rewinddir$INODE64$UNIX2003") void rewinddir(DIR*);
229+
}
230+
}
231+
else
232+
{
233+
int closedir(DIR*);
234+
DIR* opendir(in char*);
235+
//dirent* readdir(DIR*);
236+
void rewinddir(DIR*);
237+
}
212238

213239
//
214240
// Thread-Safe Functions (TSF)
@@ -231,7 +257,7 @@ version( CRuntime_Glibc )
231257
}
232258
else version( OSX )
233259
{
234-
int readdir_r(DIR*, dirent*, dirent**);
260+
pragma(mangle, "readdir_r$INODE64") int readdir_r(DIR*, dirent*, dirent**);
235261
}
236262
else version( FreeBSD )
237263
{
@@ -276,8 +302,20 @@ else version( FreeBSD )
276302
void seekdir(DIR*, c_long);
277303
c_long telldir(DIR*);
278304
}
279-
else version (OSX)
305+
else version ( OSX )
280306
{
307+
version ( D_LP64 )
308+
{
309+
pragma(mangle, "seekdir$INODE64") void seekdir(DIR*, c_long);
310+
pragma(mangle, "telldir$INODE64") c_long telldir(DIR*);
311+
}
312+
else
313+
{
314+
// 32-bit mangles __DARWIN_UNIX03 specific functions with $UNIX2003 to
315+
// maintain backward compatibility with binaries build pre 10.5
316+
pragma(mangle, "seekdir$INODE64$UNIX2003") void seekdir(DIR*, c_long);
317+
pragma(mangle, "telldir$INODE64$UNIX2003") c_long telldir(DIR*);
318+
}
281319
}
282320
else version (Solaris)
283321
{

src/core/sys/posix/sys/stat.d

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -632,40 +632,39 @@ version( CRuntime_Glibc )
632632
}
633633
else version( OSX )
634634
{
635+
// _DARWIN_FEATURE_64_BIT_INODE stat is default for Mac OSX >10.5 and is
636+
// only meaningful type for other OS X/Darwin variants (e.g. iOS).
637+
// man stat(2) gives details.
635638
struct stat_t
636639
{
637-
version ( DARWIN_USE_64_BIT_INODE )
638-
{
639640
dev_t st_dev;
640641
mode_t st_mode;
641642
nlink_t st_nlink;
642643
ino_t st_ino;
643-
}
644-
else
645-
{
646-
dev_t st_dev;
647-
ino_t st_ino;
648-
mode_t st_mode;
649-
nlink_t st_nlink;
650-
}
651644
uid_t st_uid;
652645
gid_t st_gid;
653646
dev_t st_rdev;
654-
static if( false /*!_POSIX_C_SOURCE || _DARWIN_C_SOURCE*/ )
655-
{
656-
timespec st_atimespec;
657-
timespec st_mtimespec;
658-
timespec st_ctimespec;
659-
}
660-
else
661-
{
662-
time_t st_atime;
663-
c_long st_atimensec;
664-
time_t st_mtime;
665-
c_long st_mtimensec;
666-
time_t st_ctime;
667-
c_long st_ctimensec;
668-
}
647+
union
648+
{
649+
struct
650+
{
651+
timespec st_atimespec;
652+
timespec st_mtimespec;
653+
timespec st_ctimespec;
654+
timespec st_birthtimespec;
655+
}
656+
struct
657+
{
658+
time_t st_atime;
659+
c_long st_atimensec;
660+
time_t st_mtime;
661+
c_long st_mtimensec;
662+
time_t st_ctime;
663+
c_long st_ctimensec;
664+
time_t st_birthtime;
665+
c_long st_birthtimensec;
666+
}
667+
}
669668
off_t st_size;
670669
blkcnt_t st_blocks;
671670
blksize_t st_blksize;
@@ -1095,9 +1094,11 @@ else version (Solaris)
10951094
}
10961095
else version( OSX )
10971096
{
1098-
int fstat(int, stat_t*);
1099-
int lstat(in char*, stat_t*);
1100-
int stat(in char*, stat_t*);
1097+
// OS X maintains backwards compatibility with older binaries using 32-bit
1098+
// inode functions by appending $INODE64 to newer 64-bit inode functions.
1099+
pragma(mangle, "fstat$INODE64") int fstat(int, stat_t*);
1100+
pragma(mangle, "lstat$INODE64") int lstat(in char*, stat_t*);
1101+
pragma(mangle, "stat$INODE64") int stat(in char*, stat_t*);
11011102
}
11021103
else version( FreeBSD )
11031104
{

src/core/sys/posix/sys/types.d

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,7 @@ else version( OSX )
107107
alias int blksize_t;
108108
alias int dev_t;
109109
alias uint gid_t;
110-
version( DARWIN_USE_64_BIT_INODE ) {
111-
alias ulong ino_t;
112-
} else {
113-
alias uint ino_t;
114-
}
110+
alias ulong ino_t;
115111
alias ushort mode_t;
116112
alias ushort nlink_t;
117113
alias long off_t;

0 commit comments

Comments
 (0)