Showing with 78 additions and 43 deletions.
  1. +48 −10 src/core/sys/posix/dirent.d
  2. +29 −28 src/core/sys/posix/sys/stat.d
  3. +1 −5 src/core/sys/posix/sys/types.d
58 changes: 48 additions & 10 deletions src/core/sys/posix/dirent.d
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,28 @@ else version( OSX )
DT_WHT = 14
}

align(4)
// _DARWIN_FEATURE_64_BIT_INODE dirent is default for Mac OSX >10.5 and is
// only meaningful type for other OS X/Darwin variants (e.g. iOS).
// man dir(5) has some info, man stat(2) gives details.
struct dirent
{
ino_t d_ino;
alias d_fileno = d_ino;
ulong d_seekoff;
ushort d_reclen;
ushort d_namlen;
ubyte d_type;
ubyte d_namlen;
char[256] d_name;
char[1024] d_name;
}

struct DIR
{
// Managed by OS
}

dirent* readdir(DIR*);
// OS X maintains backwards compatibility with older binaries using 32-bit
// inode functions by appending $INODE64 to newer 64-bit inode functions.
pragma(mangle, "readdir$INODE64") dirent* readdir(DIR*);
}
else version( FreeBSD )
{
Expand Down Expand Up @@ -205,10 +211,30 @@ else
static assert(false, "Unsupported platform");
}

int closedir(DIR*);
DIR* opendir(in char*);
//dirent* readdir(DIR*);
void rewinddir(DIR*);
version( OSX )
{
version( D_LP64 )
{
int closedir(DIR*);
pragma(mangle, "opendir$INODE64") DIR* opendir(in char*);
pragma(mangle, "rewinddir$INODE64") void rewinddir(DIR*);
}
else
{
// 32-bit mangles __DARWIN_UNIX03 specific functions with $UNIX2003 to
// maintain backward compatibility with binaries build pre 10.5
pragma(mangle, "closedir$UNIX2003") int closedir(DIR*);
pragma(mangle, "opendir$INODE64$UNIX2003") DIR* opendir(in char*);
pragma(mangle, "rewinddir$INODE64$UNIX2003") void rewinddir(DIR*);
}
}
else
{
int closedir(DIR*);
DIR* opendir(in char*);
//dirent* readdir(DIR*);
void rewinddir(DIR*);
}

//
// Thread-Safe Functions (TSF)
Expand All @@ -231,7 +257,7 @@ version( CRuntime_Glibc )
}
else version( OSX )
{
int readdir_r(DIR*, dirent*, dirent**);
pragma(mangle, "readdir_r$INODE64") int readdir_r(DIR*, dirent*, dirent**);
}
else version( FreeBSD )
{
Expand Down Expand Up @@ -276,8 +302,20 @@ else version( FreeBSD )
void seekdir(DIR*, c_long);
c_long telldir(DIR*);
}
else version (OSX)
else version ( OSX )
{
version ( D_LP64 )
{
pragma(mangle, "seekdir$INODE64") void seekdir(DIR*, c_long);
pragma(mangle, "telldir$INODE64") c_long telldir(DIR*);
}
else
{
// 32-bit mangles __DARWIN_UNIX03 specific functions with $UNIX2003 to
// maintain backward compatibility with binaries build pre 10.5
pragma(mangle, "seekdir$INODE64$UNIX2003") void seekdir(DIR*, c_long);
pragma(mangle, "telldir$INODE64$UNIX2003") c_long telldir(DIR*);
}
}
else version (Solaris)
{
Expand Down
57 changes: 29 additions & 28 deletions src/core/sys/posix/sys/stat.d
Original file line number Diff line number Diff line change
Expand Up @@ -632,40 +632,39 @@ version( CRuntime_Glibc )
}
else version( OSX )
{
// _DARWIN_FEATURE_64_BIT_INODE stat is default for Mac OSX >10.5 and is
// only meaningful type for other OS X/Darwin variants (e.g. iOS).
// man stat(2) gives details.
struct stat_t
{
version ( DARWIN_USE_64_BIT_INODE )
{
dev_t st_dev;
mode_t st_mode;
nlink_t st_nlink;
ino_t st_ino;
}
else
{
dev_t st_dev;
ino_t st_ino;
mode_t st_mode;
nlink_t st_nlink;
}
uid_t st_uid;
gid_t st_gid;
dev_t st_rdev;
static if( false /*!_POSIX_C_SOURCE || _DARWIN_C_SOURCE*/ )
{
timespec st_atimespec;
timespec st_mtimespec;
timespec st_ctimespec;
}
else
{
time_t st_atime;
c_long st_atimensec;
time_t st_mtime;
c_long st_mtimensec;
time_t st_ctime;
c_long st_ctimensec;
}
union
{
struct
{
timespec st_atimespec;
timespec st_mtimespec;
timespec st_ctimespec;
timespec st_birthtimespec;
}
struct
{
time_t st_atime;
c_long st_atimensec;
time_t st_mtime;
c_long st_mtimensec;
time_t st_ctime;
c_long st_ctimensec;
time_t st_birthtime;
c_long st_birthtimensec;
}
}
off_t st_size;
blkcnt_t st_blocks;
blksize_t st_blksize;
Expand Down Expand Up @@ -1095,9 +1094,11 @@ else version (Solaris)
}
else version( OSX )
{
int fstat(int, stat_t*);
int lstat(in char*, stat_t*);
int stat(in char*, stat_t*);
// OS X maintains backwards compatibility with older binaries using 32-bit
// inode functions by appending $INODE64 to newer 64-bit inode functions.
pragma(mangle, "fstat$INODE64") int fstat(int, stat_t*);
pragma(mangle, "lstat$INODE64") int lstat(in char*, stat_t*);
pragma(mangle, "stat$INODE64") int stat(in char*, stat_t*);
}
else version( FreeBSD )
{
Expand Down
6 changes: 1 addition & 5 deletions src/core/sys/posix/sys/types.d
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ else version( OSX )
alias int blksize_t;
alias int dev_t;
alias uint gid_t;
version( DARWIN_USE_64_BIT_INODE ) {
alias ulong ino_t;
} else {
alias uint ino_t;
}
alias ulong ino_t;
alias ushort mode_t;
alias ushort nlink_t;
alias long off_t;
Expand Down