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

Commit

Permalink
OpenBSD: Additions for core.posix.* modules, part 1
Browse files Browse the repository at this point in the history
Add OpenBSD definitions to the core.posix.* modules.
  • Loading branch information
redstar committed Jul 10, 2016
1 parent 4787ad5 commit 59b46b7
Show file tree
Hide file tree
Showing 10 changed files with 310 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mak/COPY
Expand Up @@ -100,6 +100,8 @@ COPY=\
$(IMPDIR)\core\sys\linux\sys\sysinfo.d \
$(IMPDIR)\core\sys\linux\sys\xattr.d \
\
$(IMPDIR)\core\sys\openbsd\dlfcn.d \
\
$(IMPDIR)\core\sys\osx\execinfo.d \
$(IMPDIR)\core\sys\osx\pthread.d \
\
Expand Down
30 changes: 30 additions & 0 deletions src/core/sys/openbsd/dlfcn.d
@@ -0,0 +1,30 @@
/**
* D header file for OpenBSD.
*
* $(LINK2 http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/include/link_elf.h?rev=1.6&content-type=text/x-cvsweb-markup, dlfcn.h)
*/
module core.sys.openbsd.dlfcn;

public import core.sys.posix.dlfcn;

version (OpenBSD):
extern (C):
nothrow:

static assert(RTLD_LAZY == 1);
static assert(RTLD_NOW == 2);
static assert(RTLD_GLOBAL == 0x100);
static assert(RTLD_LOCAL == 0);
enum RTLD_TRACE = 0x200;

enum RTLD_NEXT = cast(void *)-1;
enum RTLD_DEFAULT = cast(void *)-2;
enum RTLD_SELF = cast(void *)-3;

enum DL_GETERRNO = 1;
enum DL_SETTHREADLCK = 2;
enum DL_SETBINDLCK = 3;

enum DL_LAZY = RTLD_LAZY;

int dlctl(void *, int, void *);
39 changes: 39 additions & 0 deletions src/core/sys/posix/dirent.d
Expand Up @@ -162,6 +162,36 @@ else version( FreeBSD )

dirent* readdir(DIR*);
}
else version( OpenBSD )
{
enum
{
DT_UNKNOWN = 0,
DT_FIFO = 1,
DT_CHR = 2,
DT_DIR = 4,
DT_BLK = 6,
DT_REG = 8,
DT_LNK = 10,
DT_SOCK = 12,
}

align(4)
struct dirent
{
ino_t d_fileno;
off_t d_off;
ushort d_reclen;
ubyte d_type;
ubyte d_namlen;
ubyte[4] __d_padding;
char[256] d_name;
}

alias void* DIR;

dirent* readdir(DIR*);
}
else version (Solaris)
{
struct dirent
Expand Down Expand Up @@ -291,6 +321,10 @@ else version( FreeBSD )
{
int readdir_r(DIR*, dirent*, dirent**);
}
else version( OpenBSD )
{
int readdir_r(DIR*, dirent*, dirent**);
}
else version (Solaris)
{
static if (__USE_LARGEFILE64)
Expand Down Expand Up @@ -330,6 +364,11 @@ else version( FreeBSD )
void seekdir(DIR*, c_long);
c_long telldir(DIR*);
}
else version( OpenBSD )
{
void seekdir(DIR*, c_long);
c_long telldir(DIR*);
}
else version (Darwin)
{
version( OSX )
Expand Down
21 changes: 21 additions & 0 deletions src/core/sys/posix/dlfcn.d
Expand Up @@ -174,6 +174,27 @@ else version( FreeBSD )
void* dli_saddr;
}
}
else version( OpenBSD )
{
enum RTLD_LAZY = 1;
enum RTLD_NOW = 2;
enum RTLD_GLOBAL = 0x100;
enum RTLD_LOCAL = 0;

int dlclose(void*);
char* dlerror();
void* dlopen(in char*, int);
void* dlsym(void*, in char*);
int dladdr(const(void)* addr, Dl_info* info);

struct Dl_info
{
const(char)* dli_fname;
void* dli_fbase;
const(char)* dli_sname;
void* dli_saddr;
}
}
else version( Solaris )
{
enum RTLD_LAZY = 1;
Expand Down
69 changes: 69 additions & 0 deletions src/core/sys/posix/fcntl.d
Expand Up @@ -382,6 +382,75 @@ else version( FreeBSD )
enum AT_SYMLINK_NOFOLLOW = 0x200;
enum AT_FDCWD = -100;
}
else version( OpenBSD )
{
enum F_DUPFD = 0;
enum F_GETFD = 1;
enum F_SETFD = 2;
enum F_GETFL = 3;
enum F_SETFL = 4;
enum F_GETOWN = 5;
enum F_SETOWN = 6;
enum F_GETLK = 7;
enum F_SETLK = 8;
enum F_SETLKW = 9;
enum F_DUPFD_CLOEXEC= 10;
enum F_ISATTY = 11;

enum FD_CLOEXEC = 1;

enum F_RDLCK = 1;
enum F_UNLCK = 2;
enum F_WRLCK = 3;

enum O_CREAT = 0x0200;
enum O_EXCL = 0x0800;
enum O_NOCTTY = 0x8000;
enum O_TRUNC = 0x0400;

enum O_RDONLY = 0x0000;
enum O_WRONLY = 0x0001;
enum O_RDWR = 0x0002;
enum O_ACCMODE = 0x0003;
enum O_SHLOCK = 0x0010;
enum O_EXLOCK = 0x0020;
enum O_ASYNC = 0x0040;
enum O_FSYNC = 0x0080;
enum O_NOFOLLOW = 0x0100;

enum O_NONBLOCK = 0x0004;
enum O_APPEND = 0x0008;
enum O_SYNC = 0x0080;
enum O_DSYNC = O_SYNC;
enum O_RSYNC = O_SYNC;

enum O_CLOEXEC = 0x10000;
enum O_DIRECTORY = 0x20000;

enum LOCK_SH = 0x01;
enum LOCK_EX = 0x02;
enum LOCK_NB = 0x04;
enum LOCK_UN = 0x08;

struct flock
{
off_t l_start;
off_t l_len;
pid_t l_pid;
short l_type;
short l_whence;
}

int creat(in char*, mode_t);
int open(in char*, int, ...);

enum AT_FDCWD = -100;

enum AT_EACCESS = 0x01;
enum AT_SYMLINK_NOFOLLOW = 0x02;
enum AT_SYMLINK_FOLLOW = 0x04;
enum AT_REMOVEDIR = 0x08;
}
else version (Solaris)
{
enum F_DUPFD = 0;
Expand Down
21 changes: 21 additions & 0 deletions src/core/sys/posix/grp.d
Expand Up @@ -77,6 +77,16 @@ else version( FreeBSD )
char** gr_mem;
}
}
else version( OpenBSD )
{
struct group
{
char* gr_name;
char* gr_passwd;
gid_t gr_gid;
char** gr_mem;
}
}
else version( Solaris )
{
struct group
Expand Down Expand Up @@ -128,6 +138,11 @@ else version( FreeBSD )
int getgrnam_r(in char*, group*, char*, size_t, group**);
int getgrgid_r(gid_t, group*, char*, size_t, group**);
}
else version( OpenBSD )
{
int getgrnam_r(in char*, group*, char*, size_t, group**);
int getgrgid_r(gid_t, group*, char*, size_t, group**);
}
else version( Solaris )
{
int getgrnam_r(in char*, group*, char*, int, group**);
Expand Down Expand Up @@ -168,6 +183,12 @@ else version( FreeBSD )
@trusted void endgrent();
@trusted void setgrent();
}
else version( OpenBSD )
{
group* getgrent();
@trusted void endgrent();
@trusted void setgrent();
}
else version( Solaris )
{
group* getgrent();
Expand Down
91 changes: 91 additions & 0 deletions src/core/sys/posix/netdb.d
Expand Up @@ -396,6 +396,97 @@ else version( FreeBSD )
enum EAI_SYSTEM = 11;
enum EAI_OVERFLOW = 14;
}
else version( OpenBSD )
{
struct hostent
{
char* h_name;
char** h_aliases;
int h_addrtype;
int h_length;
char** h_addr_list;
extern (D) char* h_addr() @property { return h_addr_list[0]; } // non-standard
}

struct netent
{
char* n_name;
char** n_aliases;
int n_addrtype;
in_addr_t n_net;
}

struct protoent
{
char* p_name;
char** p_aliases;
int p_proto;
}

struct servent
{
char* s_name;
char** s_aliases;
int s_port;
char* s_proto;
}

enum IPPORT_RESERVED = 1024;

//h_errno

enum NETDB_INTERNAL = -1;
enum NETDB_SUCCESS = 0;
enum HOST_NOT_FOUND = 1;
enum NO_DATA = 4;
enum NO_RECOVERY = 3;
enum TRY_AGAIN = 2;

struct addrinfo
{
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
socklen_t ai_addrlen;
char* ai_canonname;
sockaddr* ai_addr;
addrinfo* ai_next;
}

enum AI_PASSIVE = 0x1;
enum AI_CANONNAME = 0x2;
enum AI_NUMERICHOST = 0x4;
enum AI_EXT = 0x8;
enum AI_NUMERICSERV = 0x10;
enum AI_FQDN = 0x20;
enum AI_ADDRCONFIG = 0x40;
enum AI_MASK = AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | AI_FQDN | AI_ADDRCONFIG;

enum NI_NUMERICHOST = 1;
enum NI_NUMERICSERV = 2;
enum NI_NOFQDN = 4;
enum NI_NAMEREQD = 8;
enum NI_DGRAM = 16;
//enum NI_NUMERICSCOPE = 32;
enum NI_MAXHOST = 256; // non-standard
enum NI_MAXSERV = 32; // non-standard

enum EAI_NONAME = -1;
enum EAI_BADFLAGS = -2;
enum EAI_AGAIN = -3;
enum EAI_FAIL = -4;
enum EAI_NODATA = -5;
enum EAI_FAMILY = -6;
enum EAI_SOCKTYPE = -7;
enum EAI_SERVICE = -8;
enum EAI_ADDRFAMILY = -9;
enum EAI_MEMORY = -10;
enum EAI_SYSTEM = -11;
enum EAI_BADHINTS = -12;
enum EAI_PROTOCOL = -13;
enum EAI_OVERFLOW = -14;
}
else version (Solaris)
{
struct hostent
Expand Down
31 changes: 31 additions & 0 deletions src/core/sys/posix/poll.d
Expand Up @@ -152,6 +152,37 @@ else version( FreeBSD )

int poll(pollfd*, nfds_t, int);
}
else version( OpenBSD )
{
alias uint nfds_t;

struct pollfd
{
int fd;
short events;
short revents;
};

enum
{
POLLIN = 0x0001,
POLLPRI = 0x0002,
POLLOUT = 0x0004,
POLLRDNORM = 0x0040,
POLLNORM = POLLRDNORM,
POLLWRNORM = POLLOUT,
POLLRDBAND = 0x0080,
POLLWRBAND = 0x0100,
POLLERR = 0x0008,
POLLHUP = 0x0010,
POLLNVAL = 0x0020,

POLLSTANDARD = (POLLIN|POLLPRI|POLLOUT|POLLRDNORM|POLLRDBAND|
POLLWRBAND|POLLERR|POLLHUP|POLLNVAL)
}

int poll(pollfd*, nfds_t, int);
}
else version( Solaris )
{
alias c_ulong nfds_t;
Expand Down
3 changes: 3 additions & 0 deletions win32.mak
Expand Up @@ -485,6 +485,9 @@ $(IMPDIR)\core\sys\linux\sys\sysinfo.d : src\core\sys\linux\sys\sysinfo.d
$(IMPDIR)\core\sys\linux\sys\xattr.d : src\core\sys\linux\sys\xattr.d
copy $** $@

$(IMPDIR)\core\sys\openbsd\dlfcn.d : src\core\sys\openbsd\dlfcn.d
copy $** $@

$(IMPDIR)\core\sys\osx\execinfo.d : src\core\sys\osx\execinfo.d
copy $** $@

Expand Down

0 comments on commit 59b46b7

Please sign in to comment.