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

Commit

Permalink
Issue 17596: Version bindings so that they work for both FreeBSD 11 a…
Browse files Browse the repository at this point in the history
…nd 12.
  • Loading branch information
ibuclaw committed Nov 13, 2020
1 parent 3348475 commit c6c3d90
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 43 deletions.
32 changes: 25 additions & 7 deletions src/core/sys/freebsd/sys/event.d
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,33 @@ extern(D) void EV_SET(kevent_t* kevp, typeof(kevent_t.tupleof) args)
*kevp = kevent_t(args);
}

struct kevent_t
version (FreeBSD_12)
{
uintptr_t ident; /* identifier for this event */
short filter; /* filter for event */
ushort flags;
uint fflags;
intptr_t data;
void *udata; /* opaque user data identifier */
struct kevent_t
{
uintptr_t ident;
short filter;
ushort flags;
uint fflags;
long data;
void* udata;
ulong[4] ext;
}
}
else version (FreeBSD_11)
{
struct kevent_t
{
uintptr_t ident; /* identifier for this event */
short filter; /* filter for event */
ushort flags;
uint fflags;
intptr_t data;
void *udata; /* opaque user data identifier */
}
}
else
static assert(0, "Unsupported version of FreeBSD");

enum
{
Expand Down
15 changes: 13 additions & 2 deletions src/core/sys/freebsd/sys/mount.d
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,19 @@ struct fid
}

enum MFSNAMELEN = 16;
enum MNAMELEN = 88;
enum STATFS_VERSION = 0x20030518;

version (FreeBSD_12)
{
enum MNAMELEN = 1024;
enum STATFS_VERSION = 0x20140518;
}
else version (FreeBSD_11)
{
enum MNAMELEN = 88;
enum STATFS_VERSION = 0x20030518;
}
else
static assert(0, "Unsupported version of FreeBSD");

struct statfs_t
{
Expand Down
32 changes: 25 additions & 7 deletions src/core/sys/posix/dirent.d
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,33 @@ else version (FreeBSD)
DT_WHT = 14
}

align(4)
struct dirent
version (FreeBSD_12)
{
uint d_fileno;
ushort d_reclen;
ubyte d_type;
ubyte d_namlen;
char[256] d_name = 0;
struct dirent
{
ino_t d_fileno;
off_t d_off;
ushort d_reclen;
ubyte d_type;
ushort d_namlen;
ushort d_pad1;
char[256] d_name = 0;
}
}
else version (FreeBSD_11)
{
align(4)
struct dirent
{
uint d_fileno;
ushort d_reclen;
ubyte d_type;
ubyte d_namlen;
char[256] d_name = 0;
}
}
else
static assert(0, "Unsupported version of FreeBSD");

alias void* DIR;

Expand Down
93 changes: 70 additions & 23 deletions src/core/sys/posix/sys/stat.d
Original file line number Diff line number Diff line change
Expand Up @@ -1080,35 +1080,82 @@ else version (FreeBSD)
{
// https://github.com/freebsd/freebsd/blob/master/sys/sys/stat.h

struct stat_t
version (FreeBSD_12)
{
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;
struct stat_t
{
dev_t st_dev;
ino_t st_ino;
nlink_t st_nlink;
mode_t st_mode;
short st_padding0;
uid_t st_uid;
gid_t st_gid;
int st_padding1;
dev_t st_rdev;

version (X86) int st_atim_ext;

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_atime;
c_long __st_atimensec;

off_t st_size;
blkcnt_t st_blocks;
blksize_t st_blksize;
fflags_t st_flags;
uint st_gen;
int st_lspare;
version (X86) int st_mtim_ext;

time_t st_mtime;
c_long __st_mtimensec;

version (X86) int st_ctim_ext;

time_t st_ctime;
c_long __st_ctimensec;

version (X86) int st_btim_ext;

time_t st_birthtime;
c_long st_birthtimensec;
time_t st_birthtime;
c_long st_birthtimensec;

ubyte[16 - timespec.sizeof] padding;
off_t st_size;
blkcnt_t st_blocks;
blksize_t st_blksize;
fflags_t st_flags;
ulong st_gen;
ulong[10] st_spare;
}
}
else version (FreeBSD_11)
{
struct stat_t
{
uint st_dev;
uint st_ino;
mode_t st_mode;
ushort st_nlink;
uid_t st_uid;
gid_t st_gid;
uint st_rdev;

time_t st_atime;
c_long __st_atimensec;
time_t st_mtime;
c_long __st_mtimensec;
time_t st_ctime;
c_long __st_ctimensec;

off_t st_size;
blkcnt_t st_blocks;
blksize_t st_blksize;
fflags_t st_flags;
uint st_gen;
int st_lspare;

time_t st_birthtime;
c_long st_birthtimensec;

ubyte[16 - timespec.sizeof] padding;
}
}
else
static assert(0, "Unsupported version of FreeBSD");

enum S_IRUSR = 0x100; // octal 0000400
enum S_IWUSR = 0x080; // octal 0000200
Expand Down
22 changes: 18 additions & 4 deletions src/core/sys/posix/sys/types.d
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,26 @@ else version (FreeBSD)
{
// https://github.com/freebsd/freebsd/blob/master/sys/sys/_types.h
alias long blkcnt_t;
alias uint blksize_t;
alias uint dev_t;

version (FreeBSD_12)
{
alias ulong blksize_t;
alias ulong dev_t;
alias ulong ino_t;
alias ulong nlink_t;
}
else version (FreeBSD_11)
{
alias uint blksize_t;
alias uint dev_t;
alias uint ino_t;
alias ushort nlink_t;
}
else
static assert(0, "Unsupported version of FreeBSD");

alias uint gid_t;
alias uint ino_t;
alias ushort mode_t;
alias ushort nlink_t;
alias long off_t;
alias int pid_t;
//size_t (defined in core.stdc.stddef)
Expand Down

0 comments on commit c6c3d90

Please sign in to comment.