extern(C) {

const int NFDBITS = 32;
const int __FD_SET_SIZEOF = 8;
const int FD_SETSIZE = 64;
alias uint mode_t;
alias int pid_t;
alias ushort uid_t;
alias ushort gid_t;
alias int ssize_t;

enum {
  O_RDONLY = 0,
  O_WRONLY = 1,
  O_RDWR = 2,
  O_NONBLOCK = 16384,
  O_CREAT = 512,
  O_EXCL = 2048,
  O_TRUNC = 1024,
  O_APPEND = 8,
}

enum {
  F_DUPFD = 0,
  F_GETFD = 1,
  F_SETFD = 2,
  F_GETFL = 3,
  F_SETFL = 4,
}

enum {
  F_OK = 0,
  R_OK = 4,
  W_OK = 2,
  X_OK = 1,
}

alias int time_t;
struct timespec {
    int tv_sec;
    int tv_nsec;
}

static assert(timespec.tv_sec.offsetof == 0);
static assert(timespec.tv_nsec.offsetof == 4);
static assert(timespec.sizeof == 8);


struct timeval {
    int tv_sec;
    int tv_usec;
}

static assert(timeval.tv_sec.offsetof == 0);
static assert(timeval.tv_usec.offsetof == 4);
static assert(timeval.sizeof == 8);


struct timezone {
    int tz_minuteswest;
    int tz_dsttime;
}

static assert(timezone.tz_minuteswest.offsetof == 0);
static assert(timezone.tz_dsttime.offsetof == 4);
static assert(timezone.sizeof == 8);


struct tm {
    int tm_sec;
    int tm_min;
    int tm_hour;
    int tm_mday;
    int tm_mon;
    int tm_year;
    int tm_wday;
    int tm_yday;
    int tm_isdst;
    int tm_gmtoff;
}

static assert(tm.tm_sec.offsetof == 0);
static assert(tm.tm_min.offsetof == 4);
static assert(tm.tm_hour.offsetof == 8);
static assert(tm.tm_mday.offsetof == 12);
static assert(tm.tm_mon.offsetof == 16);
static assert(tm.tm_year.offsetof == 20);
static assert(tm.tm_wday.offsetof == 24);
static assert(tm.tm_yday.offsetof == 28);
static assert(tm.tm_isdst.offsetof == 32);
static assert(tm.sizeof == 40);


enum {
  S_IFIFO = 4096,
  S_IFCHR = 8192,
  S_IFDIR = 16384,
  S_IFBLK = 24576,
  S_IFREG = 32768,
  S_IFLNK = 40960,
  S_IFSOCK = 49152,
  S_IFMT = 61440,
  S_IRUSR = 256,
  S_IWUSR = 128,
  S_IXUSR = 64,
  S_IRGRP = 32,
  S_IWGRP = 16,
  S_IXGRP = 8,
  S_IROTH = 4,
  S_IWOTH = 2,
  S_IXOTH = 1,
  S_IRWXG = 56,
  S_IRWXO = 7,
}

struct struct_stat {
    uint st_dev;
   ubyte[4] ___pad1;
    ulong st_ino;
    uint st_mode;
    ushort st_nlink;
    ushort st_uid;
    ushort st_gid;
   ubyte[2] ___pad2;
    uint st_rdev;
    long st_size;
    int st_atime;
   ubyte[4] ___pad3;
    int st_mtime;
   ubyte[4] ___pad4;
    int st_ctime;
   ubyte[4] ___pad5;
    int st_blksize;
    int st_blocks;
   ubyte[16] ___pad6;
}

static assert(struct_stat.st_dev.offsetof == 0);
static assert(struct_stat.st_ino.offsetof == 8);
static assert(struct_stat.st_mode.offsetof == 16);
static assert(struct_stat.st_nlink.offsetof == 20);
static assert(struct_stat.st_uid.offsetof == 22);
static assert(struct_stat.st_gid.offsetof == 24);
static assert(struct_stat.st_rdev.offsetof == 28);
static assert(struct_stat.st_size.offsetof == 32);
static assert(struct_stat.st_atime.offsetof == 40);
static assert(struct_stat.st_mtime.offsetof == 48);
static assert(struct_stat.st_ctime.offsetof == 56);
static assert(struct_stat.st_blksize.offsetof == 64);
static assert(struct_stat.st_blocks.offsetof == 68);
static assert(struct_stat.sizeof == 88);


// from <sys/signal.h>
enum {
  SIGHUP = 1,
  SIGINT = 2,
  SIGQUIT = 3,
  SIGILL = 4,
  SIGABRT = 6,
  SIGIOT = 0,
  SIGBUS = 10,
  SIGFPE = 8,
  SIGKILL = 9,
  SIGUSR1 = 30,
  SIGSEGV = 11,
  SIGUSR2 = 31,
  SIGPIPE = 13,
  SIGALRM = 14,
  SIGTERM = 15,
  SIGSTKFLT = 0,
  SIGCHLD = 20,
  SIGCONT = 19,
  SIGSTOP = 17,
  SIGTSTP = 18,
  SIGTTIN = 21,
  SIGTTOU = 22,
  SIGIO = 23,
  SIGPOLL = 23,
  SIGPROF = 27,
  SIGWINCH = 28,
  SIGURG = 16,
  SIGXCPU = 24,
  SIGXFSZ = 25,
  SIGVTALRM = 26,
  SIGTRAP = 5,
  SIGPWR = 0,
  SIGSYS = 12,
}
enum {
  SA_NOCLDSTOP = 1,
  SA_NOCLDWAIT = 0,
  SA_SIGINFO = 0,
  SA_ONSTACK = 134217728,
  SA_RESTART = 268435456,
  SA_NODEFER = 1073741824,
  SA_RESETHAND = -2147483648,
}

struct sigset_t { ubyte[4] opaque; }
alias  void function(int) __sighandler_t;
const __sighandler_t SIG_DFL = cast(__sighandler_t) 0;
const __sighandler_t SIG_IGN = cast(__sighandler_t) 1;
const __sighandler_t SIG_ERR = cast(__sighandler_t) -1;

struct siginfo_t;
struct sigaction_t {
    void function(int) sa_handler;
    sigset_t sa_mask;
    int sa_flags;
}

static assert(sigaction_t.sa_flags.offsetof == 8);
static assert(sigaction_t.sizeof == 12);


// from <sys/mman.h>
extern(D) const void * MAP_FAILED = cast(void *) -1;
enum { PROT_NONE = 0, PROT_READ = 1, PROT_WRITE = 2, PROT_EXEC = 4 }
enum { MAP_SHARED = 0x1, MAP_PRIVATE = 0x2, MAP_ANON = 0x20,       MAP_ANONYMOUS = 0x20,  MAP_TYPE = 15,
  MAP_FIXED = 16,
  MAP_FILE = 0,
}

enum {
  MS_ASYNC = 1,
  MS_INVALIDATE = 4,
  MS_SYNC = 2,
}

enum {
  MCL_CURRENT = 0,
  MCL_FUTURE = 0,
}

enum {
  MADV_NORMAL = 0,
  MADV_RANDOM = 0,
  MADV_SEQUENTIAL = 0,
  MADV_WILLNEED = 0,
  MADV_DONTNEED = 0,
}


enum {
  EPERM = 1,
  ENOENT = 2,
  ESRCH = 3,
  EINTR = 4,
  ENXIO = 6,
  E2BIG = 7,
  ENOEXEC = 8,
  EBADF = 9,
  ECHILD = 10,
  EINPROGRESS = 119,
  EWOULDBLOCK = 11,
  EAGAIN = 11,
}

struct sem_t { ubyte[0] opaque; }
alias uint pthread_t;
struct pthread_attr_t { ubyte[28] opaque; }
struct pthread_cond_t { ubyte[20] opaque; }
struct pthread_condattr_t { ubyte[4] opaque; }
struct pthread_mutex_t { ubyte[16] opaque; }
struct pthread_mutexattr_t { ubyte[8] opaque; }

enum : int {
  PTHREAD_CANCEL_ENABLE = 0,
  PTHREAD_CANCEL_DISABLE = 1,
  PTHREAD_CANCEL_DEFERRED = 0,
  PTHREAD_CANCEL_ASYNCHRONOUS = 1,
}

alias uint socklen_t;
// from <sys/socket.h>
const int SOL_SOCKET = 1

;enum : int {
  SO_DEBUG = 1,
  SO_REUSEADDR = 2,
  SO_KEEPALIVE = 9,
  SO_DONTROUTE = 5,
  SO_BROADCAST = 6,
  SO_LINGER = 13,
  SO_OOBINLINE = 10,
  SO_BSDCOMPAT = 14,
  SO_SNDBUF = 7,
  SO_RCVBUF = 8,
  SO_SNDLOWAT = 19,
  SO_RCVLOWAT = 18,
  SO_SNDTIMEO = 21,
  SO_RCVTIMEO = 20,
  SO_ERROR = 4,
  SO_TYPE = 3,
}

struct linger {
    int l_onoff;
    int l_linger;
}

static assert(linger.l_onoff.offsetof == 0);
static assert(linger.l_linger.offsetof == 4);
static assert(linger.sizeof == 8);



enum : int {
  SOCK_STREAM = 0,
  SOCK_DGRAM = 1,
  SOCK_RAW = 2,
  SOCK_RDM = 3,
  SOCK_SEQPACKET = 4,
}

enum : int {
  MSG_OOB = 1,
  MSG_PEEK = 2,
  MSG_DONTROUTE = 4,
}

enum : int {
  AF_UNSPEC = 255,
  AF_UNIX = 1,
  AF_INET = 0,
  AF_IPX = 255,
  AF_APPLETALK = 16,
  AF_INET6 = 23,
  AF_BOGOSITY = 255,
}

enum : int {
  PF_UNSPEC = 255,
  PF_UNIX = 1,
  PF_INET = 0,
  PF_IPX = 255,
  PF_APPLETALK = 16,
}

// from <netinet/in.h>
enum : int {
  IPPROTO_IP = 0,
  IPPROTO_ICMP = 1,
  IPPROTO_IGMP = 2,
  IPPROTO_GGP = -1,
  IPPROTO_TCP = 6,
  IPPROTO_PUP = 12,
  IPPROTO_UDP = 17,
  IPPROTO_IDP = 22,
  IPPROTO_IPV6 = -1,
}

enum : uint {
  INADDR_ANY = 0x0,
  INADDR_LOOPBACK = 0x7f000001,
  INADDR_BROADCAST = 0xffffffff,
  INADDR_NONE = 0xffffffff,
  ADDR_ANY = 0,
}
// from <netinet/tcp.h>
enum : int {
  TCP_NODELAY = 1,
}

// from <netinet6/in6.h>
enum : int {
  IPV6_UNICAST_HOPS = -1,
  IPV6_MULTICAST_IF = -1,
  IPV6_MULTICAST_HOPS = -1,
  IPV6_MULTICAST_LOOP = -1,
  IPV6_JOIN_GROUP = -1,
  IPV6_LEAVE_GROUP = -1,
}

// from <netdb.h>
struct protoent {
    char * p_name;
    char ** p_aliases;
    short p_proto;
   ubyte[2] ___pad1;
}

static assert(protoent.p_proto.offsetof == 8);
static assert(protoent.sizeof == 12);


struct servent {
    char * s_name;
    char ** s_aliases;
    short s_port;
   ubyte[2] ___pad1;
    char * s_proto;
}

static assert(servent.s_port.offsetof == 8);
static assert(servent.sizeof == 16);


struct hostent {
    char * h_name;
    char ** h_aliases;
    short h_addrtype;
    short h_length;
    char ** h_addr_list;
char* h_addr()
{
	return h_addr_list[0];
}
}

static assert(hostent.h_addrtype.offsetof == 8);
static assert(hostent.h_length.offsetof == 10);
static assert(hostent.sizeof == 16);


struct addrinfo { }
struct passwd {
    char * pw_name;
    char * pw_passwd;
    int pw_uid;
    int pw_gid;
   ubyte[4] ___pad1;
    char * pw_gecos;
    char * pw_dir;
    char * pw_shell;
}

static assert(passwd.pw_uid.offsetof == 8);
static assert(passwd.pw_gid.offsetof == 12);
static assert(passwd.sizeof == 32);


}

