PageRenderTime 91ms CodeModel.GetById 18ms app.highlight 65ms RepoModel.GetById 1ms app.codeStats 1ms

/platform/unix/common.d

http://github.com/wilkie/djehuty
D | 1141 lines | 876 code | 155 blank | 110 comment | 14 complexity | 7c6b7259bfd4c4f2996cde33c57600c1 MD5 | raw file
   1/*
   2 * common.d
   3 *
   4 * This file gives the external references for libraries and native APIs.
   5 * For the UNIX environment, this is largely the C standard library. Some
   6 * magic goes into hinting to the runtime in place.
   7 *
   8 * Author: Dave Wilkinson
   9 *
  10 */
  11
  12module platform.unix.common;
  13
  14public import X = binding.x.Xlib;
  15
  16public import Cairo = binding.cairo.cairo;
  17public import CairoX = binding.cairo.xlib;
  18
  19public import Pango = binding.pango.pango;
  20
  21public import binding.c;
  22public import Curses = binding.ncurses.ncurses;
  23
  24extern(C):
  25
  26size_t readlink(char* path, char* buf, size_t len);
  27
  28int getpid();
  29char* getenv(char*);
  30
  31// Directory Streams
  32
  33struct __direntry;
  34alias __direntry DIR;
  35
  36static int _IONBF = 0x2;
  37
  38struct dirent
  39{
  40	version(darwin) {
  41		uint d_ino;
  42		ushort d_reclen;
  43		ubyte d_type;
  44		ubyte d_namlen;
  45		char d_name[256];
  46	}
  47	else {
  48		Culong_t d_ino;
  49		Culong_t d_off;
  50
  51		ushort d_reclen;
  52		ubyte d_type;
  53		char d_name[256];
  54	}
  55}
  56
  57struct dirent64
  58{
  59	Culong_t d_ino;
  60	Culong_t d_off;
  61
  62	ushort d_reclen;
  63	ubyte d_type;
  64	char d_name[256];
  65}
  66
  67DIR* opendir(char* name);
  68int closedir(DIR* dp);
  69dirent* readdir(DIR* dp);
  70dirent64* readdir64(DIR* dp);
  71void rewinddir(DIR* dp);
  72void seekdir(DIR* dp, Clong_t pos);
  73Clong_t telldir(DIR* dp);
  74
  75// Network
  76
  77alias uint mode_t;
  78alias int pid_t;
  79alias uint uid_t;
  80alias uint gid_t;
  81alias Clong_t off_t;
  82alias Clong_t ssize_t;
  83
  84struct hostent
  85{
  86	char* h_name;
  87	char** h_aliases;
  88	int h_addrtype;
  89	int h_length;
  90	char** h_addr_list;
  91
  92	char* h_addr()
  93	{
  94		return h_addr_list[0];
  95	}
  96
  97}
  98
  99struct addrinfo { }
 100struct passwd
 101{
 102	char* pw_name;
 103	char* pw_passwd;
 104	uint pw_uid;
 105	uint pw_gid;
 106	char* pw_gecos;
 107	char* pw_dir;
 108	char* pw_shell;
 109}
 110
 111struct in_addr
 112{
 113	uint s_addr;
 114}
 115
 116struct timespec
 117{
 118	Clong_t tv_sec;
 119	Clong_t tv_nsec;
 120}
 121
 122struct timeval
 123{
 124	Clong_t tv_sec;
 125	Clong_t tv_usec;
 126}
 127
 128struct timezone
 129{
 130	int tz_minuteswest;
 131	int tz_dsttime;
 132}
 133
 134struct sem_t
 135{
 136	byte[32] __opaque;
 137}
 138
 139alias ulong pthread_t;
 140struct pthread_attr_t
 141{
 142	byte[56] __opaque;
 143}
 144
 145struct pthread_cond_t
 146{
 147	byte[48] __opaque;
 148}
 149
 150struct pthread_condattr_t
 151{
 152	byte[4] __opaque;
 153}
 154
 155struct pthread_mutex_t
 156{
 157	byte[40] __opaque;
 158}
 159
 160struct pthread_mutexattr_t
 161{
 162	byte[4] __opaque;
 163}
 164
 165struct sched_param
 166{
 167	int sched_priority;
 168}
 169
 170struct pthread_barrier_t
 171{
 172	byte[32] __opaque;
 173}
 174
 175struct pthread_barrierattr_t
 176{
 177	byte[4] __opaque;
 178}
 179
 180struct pthread_rwlock_t
 181{
 182	byte[56] __opaque;
 183}
 184
 185struct pthread_rwlockattr_t
 186{
 187	byte[8] __opaque;
 188}
 189
 190alias int pthread_spinlock_t;
 191enum
 192{
 193	PTHREAD_CANCEL_DEFERRED = 0,
 194	PTHREAD_CANCEL_ASYNCHRONOUS = 1,
 195	PTHREAD_CANCEL_ENABLE = 0,
 196	PTHREAD_CANCEL_DISABLE = 1,
 197}
 198
 199//alias int clockid_t;
 200struct utimbuf
 201{
 202	long actime;
 203	long modtime;
 204}
 205
 206align(2) struct struct_stat
 207{
 208	version(darwin) {
 209		uint st_dev;
 210		uint st_ino;
 211		ushort st_mode;
 212		ushort st_nlink;
 213		uint st_uid;
 214		uint st_gid;
 215		uint st_rdev;
 216		ulong[64] fuck;
 217	}
 218	else version(linux) {
 219		ulong st_dev;
 220
 221		version(X86) {
 222			ubyte[4] __pad1;
 223			uint __st_ino;
 224			uint st_mode;
 225			uint st_nlink;
 226		} else version(X86_64) {
 227			ulong st_ino;
 228			ulong st_nlink;
 229			uint st_mode;
 230		} else {
 231			static assert(false); // Unsupported architecture.
 232		}
 233
 234		uint st_uid;
 235		uint st_gid;
 236
 237		version(X86_64)
 238			ubyte[4] __pad0;
 239
 240		ulong st_rdev;
 241
 242		version(X86)
 243			ubyte[4] __pad2;
 244
 245		long st_size;
 246		Clong_t st_blksize;
 247		long st_blocks;
 248		timespec st_atim;
 249		timespec st_mtim;
 250		timespec st_ctim;
 251
 252		version(X86) {
 253			ulong st_ino;
 254		} else version (X86_64){
 255			ubyte[24] __unused;
 256		}
 257	}
 258	else {
 259		static assert(false); // Unsupported OS.
 260	}
 261}
 262
 263const auto S_IFMT	= 0170000;
 264const auto S_IFSOCK	= 0140000;
 265const auto S_IFLNK	= 0120000;
 266const auto S_IFREG	= 0100000;
 267const auto S_IFBLK	= 0060000;
 268const auto S_IFDIR	= 0040000;
 269const auto S_IFCHR	= 0020000;
 270const auto S_IFIFO	= 0010000;
 271const auto S_ISUID	= 0004000;
 272const auto S_ISGID	= 0002000;
 273const auto S_ISVTX	= 0001000;
 274
 275bool S_ISLNK(uint mode) {
 276	return (mode & S_IFMT) == S_IFLNK;
 277}
 278
 279bool S_ISREG(uint mode) {
 280	return (mode & S_IFMT) == S_IFREG;
 281}
 282
 283bool S_ISDIR(uint mode) {
 284	return ((mode & S_IFMT) & S_IFDIR) == S_IFDIR;
 285}
 286
 287bool S_ISCHR(uint mode) {
 288	return (mode & S_IFMT) == S_IFCHR;
 289}
 290
 291bool S_ISBLK(uint mode) {
 292	return (mode & S_IFMT) == S_IFBLK;
 293}
 294
 295bool S_ISFIFO(uint mode) {
 296	return (mode & S_IFMT) == S_IFIFO;
 297}
 298
 299bool S_ISSOCK(uint mode) {
 300	return (mode & S_IFMT) == S_IFSOCK;
 301}
 302
 303struct sigaction_t {
 304	union {
 305		extern(C) void function(int) sa_handler;
 306		extern(C) void function(int, siginfo_t *, void *) sa_sigaction;
 307	}
 308	sigset_t sa_mask;
 309	int sa_flags;
 310	ubyte[12] __pad1;
 311}
 312
 313
 314struct sockaddr {
 315	ushort sa_family;
 316	byte[14] sa_data;
 317}
 318
 319struct fd_set {
 320	byte[128] __opaque;
 321}
 322
 323
 324enum
 325{
 326	AF_MAX = 34,
 327	AF_APPLETALK = 5,
 328	AF_INET6 = 10,
 329	AF_NETLINK = 16,
 330	AF_FILE = 1,
 331	AF_ROSE = 11,
 332	AF_NETROM = 6,
 333	AF_ATMPVC = 8,
 334	AF_WANPIPE = 25,
 335	AF_UNSPEC = 0,
 336	AF_BRIDGE = 7,
 337	AF_X25 = 9,
 338	AF_BLUETOOTH = 31,
 339	AF_ROUTE = 16,
 340	AF_SECURITY = 14,
 341	AF_RXRPC = 33,
 342	AF_AX25 = 3,
 343	AF_KEY = 15,
 344	AF_IUCV = 32,
 345	AF_ECONET = 19,
 346	AF_INET = 2,
 347	AF_ATMSVC = 20,
 348	AF_PPPOX = 24,
 349	AF_PACKET = 17,
 350	AF_IRDA = 23,
 351	AF_NETBEUI = 13,
 352	AF_SNA = 22,
 353	AF_LOCAL = 1,
 354	AF_ASH = 18,
 355	AF_UNIX = 1,
 356	AF_DECnet = 12,
 357	AF_IPX = 4,
 358}
 359
 360struct sockaddr_in
 361{
 362	ushort sin_family = AF_INET;
 363	ushort sin_port;
 364	in_addr sin_addr;
 365	ubyte[8] sin_zero;
 366}
 367
 368struct protoent
 369{
 370	char* p_name;
 371	char** p_aliases;
 372	int p_proto;
 373	ubyte[4] __pad1;
 374}
 375
 376struct servent
 377{
 378	char* s_name;
 379	char** s_aliases;
 380	int s_port;
 381	ubyte[4] __pad1;
 382	char* s_proto;
 383}
 384
 385alias uint socklen_t;
 386enum
 387{
 388	SOL_ATM = 264,
 389	SOL_PACKET = 263,
 390	SOL_IPV6 = 41,
 391	SOL_DECNET = 261,
 392	SOL_X25 = 262,
 393	SOL_IP = 0,
 394	SOL_ICMPV6 = 58,
 395	SOL_SOCKET = 1,
 396	SOL_TCP = 6,
 397	SOL_RAW = 255,
 398	SOL_IRDA = 266,
 399	SOL_AAL = 265,
 400}
 401
 402struct sigset_t
 403{
 404	byte[128] __opaque;
 405}
 406
 407//alias extern(C) void function(int) __sighandler_t;
 408const __sighandler_t SIG_DFL = cast(__sighandler_t) 0;
 409const __sighandler_t SIG_IGN = cast(__sighandler_t) 1;
 410const __sighandler_t SIG_ERR = cast(__sighandler_t) 0xffffffffffffffffUL;
 411struct siginfo_t
 412{
 413	int si_signo;
 414	int si_errno;
 415	int si_code;
 416	ubyte[116] __pad1;
 417}
 418
 419version(X86) {
 420	version(linux) {
 421		version = stat64;
 422	}
 423}
 424
 425version(stat64) {
 426	extern (C) int fstat64(int, struct_stat*);
 427	extern (C) int lstat64(in char*, struct_stat*);
 428	extern (C) int stat64(in char*, struct_stat*);
 429
 430	int fstat(int f, struct_stat* s) {
 431		return fstat64(f, s);
 432	}
 433
 434	int lstat(in char* f, struct_stat* s) {
 435		return lstat64(f, s);
 436	}
 437
 438	int stat(in char* f, struct_stat* s) {
 439		return stat64(f, s);
 440	}
 441} else {
 442	extern (C) int fstat(int, struct_stat*);
 443	extern (C) int lstat(in char*, struct_stat*);
 444	extern (C) int stat(in char*, struct_stat*);
 445}
 446
 447extern (C):
 448
 449	// DMD linux.d has dirent.h declarations
 450	//public import std.c.dirent;
 451	//int dirfd(DIR*);
 452	//public import std.c.stdio;
 453	int fseeko(FILE*, off_t, int);
 454	off_t ftello(FILE*);
 455
 456	int open(in char*, int, ...);
 457	ssize_t read(int, void*, size_t);
 458	ssize_t write(int, in void*, size_t);
 459	int close(int);
 460	off_t lseek(int, off_t, int);
 461	int access(in char *path, int mode);
 462	int utime(char *path, utimbuf *buf);
 463	int chmod(in char *, mode_t);
 464	int chdir(in char*);
 465	int mkdir(in char*, mode_t);
 466	int rmdir(in char*);
 467	char* getcwd(char*, size_t);
 468
 469	pid_t fork();
 470	int dup(int);
 471	int dup2(int, int);
 472	int pipe(int[2]);
 473	pid_t wait(int*);
 474	pid_t waitpid(pid_t, int*, int);
 475	int kill(pid_t, int);
 476
 477	int gettimeofday(timeval*, void*);
 478	int settimeofday(in timeval *, in void *);
 479	time_t time(time_t*);
 480	//tm *localtime(time_t*);
 481
 482	int sem_init (sem_t *, int, uint);
 483	int sem_destroy (sem_t *);
 484	sem_t * sem_open (char *, int, ...);
 485	int sem_close(sem_t *);
 486	int sem_wait(sem_t*);
 487	int sem_post(sem_t*);
 488	int sem_trywait(sem_t*);
 489	int sem_getvalue(sem_t*, int*);
 490
 491	int sigemptyset(sigset_t*);
 492	int sigfillset(sigset_t*);
 493	int sigdelset(sigset_t*, int);
 494	int sigismember(sigset_t *set, int);
 495	int sigaction(int, sigaction_t*, sigaction_t*);
 496	int sigsuspend(sigset_t*);
 497
 498	//Clong_t sysconf(int name);
 499
 500	// version ( Unix_Pthread )...
 501	int pthread_attr_init(pthread_attr_t *);
 502	int pthread_attr_destroy(pthread_attr_t *);
 503	int pthread_attr_setdetachstate(pthread_attr_t *, int);
 504	int pthread_attr_getdetachstate(pthread_attr_t *, int *);
 505	int pthread_attr_setguardsize(pthread_attr_t*, size_t);
 506	int pthread_attr_getguardsize(pthread_attr_t*, size_t *);
 507	int pthread_attr_setinheritsched(pthread_attr_t *, int);
 508	int pthread_attr_getinheritsched(pthread_attr_t *, int *);
 509	int pthread_attr_setschedparam(pthread_attr_t *, sched_param *);
 510	int pthread_attr_getschedparam(pthread_attr_t *, sched_param *);
 511	int pthread_attr_setschedpolicy(pthread_attr_t *, int);
 512	int pthread_attr_getschedpolicy(pthread_attr_t *, int*);
 513	int pthread_attr_setscope(pthread_attr_t *, int);
 514	int pthread_attr_getscope(pthread_attr_t *, int*);
 515	int pthread_attr_setstack(pthread_attr_t *, void*, size_t);
 516	int pthread_attr_getstack(pthread_attr_t *, void**, size_t *);
 517	int pthread_attr_setstackaddr(pthread_attr_t *, void *);
 518	int pthread_attr_getstackaddr(pthread_attr_t *, void **);
 519	int pthread_attr_setstacksize(pthread_attr_t *, size_t);
 520	int pthread_attr_getstacksize(pthread_attr_t *, size_t *);
 521
 522	int pthread_create(pthread_t*, pthread_attr_t*, void* (*)(void*), void*);
 523	int pthread_join(pthread_t, void**);
 524	int pthread_kill(pthread_t, int);
 525	pthread_t pthread_self();
 526	int pthread_equal(pthread_t, pthread_t);
 527	int pthread_suspend_np(pthread_t);
 528	int pthread_continue_np(pthread_t);
 529	int pthread_cancel(pthread_t);
 530	int pthread_setcancelstate(int state, int *oldstate);
 531	int pthread_setcanceltype(int type, int *oldtype);
 532	void pthread_testcancel();
 533	int pthread_detach(pthread_t);
 534	void pthread_exit(void*);
 535	int pthread_getattr_np(pthread_t, pthread_attr_t*);
 536	int pthread_getconcurrency();
 537	int pthread_getcpuclockid(pthread_t, clockid_t*);
 538
 539	int pthread_cond_init(pthread_cond_t *, pthread_condattr_t *);
 540	int pthread_cond_destroy(pthread_cond_t *);
 541	int pthread_cond_signal(pthread_cond_t *);
 542	int pthread_cond_broadcast(pthread_cond_t *);
 543	int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
 544	int pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *, timespec *);
 545	int pthread_condattr_init(pthread_condattr_t *);
 546	int pthread_condattr_destroy(pthread_condattr_t *);
 547	int pthread_condattr_getpshared(pthread_condattr_t *, int *);
 548	int pthread_condattr_setpshared(pthread_condattr_t *, int);
 549
 550	int pthread_mutex_init(pthread_mutex_t *, pthread_mutexattr_t *);
 551	int pthread_mutex_lock(pthread_mutex_t *);
 552	int pthread_mutex_trylock(pthread_mutex_t *);
 553	int pthread_mutex_unlock(pthread_mutex_t *);
 554	int pthread_mutex_destroy(pthread_mutex_t *);
 555	int pthread_mutexattr_init(pthread_mutexattr_t *);
 556	int pthread_mutexattr_destroy(pthread_mutexattr_t *);
 557	int pthread_mutexattr_getpshared(pthread_mutexattr_t *, int *);
 558	int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
 559
 560	int pthread_barrierattr_init(pthread_barrierattr_t*);
 561	int pthread_barrierattr_getpshared(pthread_barrierattr_t*, int*);
 562	int pthread_barrierattr_destroy(pthread_barrierattr_t*);
 563	int pthread_barrierattr_setpshared(pthread_barrierattr_t*, int);
 564
 565	int pthread_barrier_init(pthread_barrier_t*, pthread_barrierattr_t*, uint);
 566	int pthread_barrier_destroy(pthread_barrier_t*);
 567	int pthread_barrier_wait(pthread_barrier_t*);
 568
 569	// version ( Unix_Sched )
 570	void sched_yield();
 571
 572	// from <sys/mman.h>
 573	void* mmap(void* addr, size_t len, int prot, int flags, int fd, off_t offset);
 574	int munmap(void* addr, size_t len);
 575	int msync(void* start, size_t length, int flags);
 576	int madvise(void*, size_t, int);
 577	int mlock(void*, size_t);
 578	int munlock(void*, size_t);
 579	int mlockall(int);
 580	int munlockall();
 581	//void* mremap(void*, size_t, size_t, Culong_t); // Linux specific
 582	int mincore(void*, size_t, ubyte*);
 583	int remap_file_pages(void*, size_t, int, ssize_t, int); // Linux specific
 584	int shm_open(in char*, int, mode_t);
 585	int shm_unlink(in char*);
 586
 587	// from <fcntl.h>
 588	int fcntl(int fd, int cmd, ...);
 589
 590	int select(int n, fd_set *, fd_set *, fd_set *, timeval *);
 591
 592	// could probably rewrite fd_set stuff in D, but for now...
 593	private void _d_gnu_fd_set(int n, fd_set * p);
 594	private void _d_gnu_fd_clr(int n, fd_set * p);
 595	private int  _d_gnu_fd_isset(int n, fd_set * p);
 596	private void _d_gnu_fd_copy(fd_set * f, fd_set * t);
 597	private void _d_gnu_fd_zero(fd_set * p);
 598	// maybe these should go away in favor of fd_set methods
 599	/*version (none)
 600	  {
 601	  void FD_SET(int n, inout fd_set p) { return _d_gnu_fd_set(n, & p); }
 602	  void FD_CLR(int n, inout fd_set p) { return _d_gnu_fd_clr(n, & p); }
 603	  int FD_ISSET(int n, inout fd_set p) { return _d_gnu_fd_isset(n, & p); }
 604	  void FD_COPY(inout fd_set f, inout fd_set t) { return _d_gnu_fd_copy(& f, & t); }
 605	  void FD_ZERO(inout fd_set p) { return _d_gnu_fd_zero(& p); }
 606	  }*/
 607	/*void FD_SET(int n,  fd_set * p) { return _d_gnu_fd_set(n, p); }
 608	  void FD_CLR(int n,  fd_set * p) { return _d_gnu_fd_clr(n, p); }
 609	  int FD_ISSET(int n, fd_set * p) { return _d_gnu_fd_isset(n, p); }
 610	  void FD_COPY(fd_set * f, inout fd_set * t) { return _d_gnu_fd_copy(f, t); }
 611	  void FD_ZERO(fd_set * p) { return _d_gnu_fd_zero(p); }*/
 612
 613	//void FD_SET(int, fd_set*p);
 614
 615	// from <pwd.h>
 616	passwd *getpwnam(in char *name);
 617	passwd *getpwuid(uid_t uid);
 618	int getpwnam_r(char *name, passwd *pwbuf, char *buf, size_t buflen, passwd **pwbufp);
 619	int getpwuid_r(uid_t uid, passwd *pwbuf, char *buf, size_t buflen, passwd **pwbufp);
 620
 621	// std/socket.d
 622enum: int
 623{
 624	SD_RECEIVE =  0,
 625	SD_SEND =     1,
 626	SD_BOTH =     2,
 627}
 628
 629int socket(int af, int type, int protocol);
 630int bind(int s, sockaddr* name, int namelen);
 631int connect(int s, sockaddr* name, int namelen);
 632int listen(int s, int backlog);
 633int accept(int s, sockaddr* addr, int* addrlen);
 634int shutdown(int s, int how);
 635int getpeername(int s, sockaddr* name, int* namelen);
 636int getsockname(int s, sockaddr* name, int* namelen);
 637ssize_t send(int s, void* buf, size_t len, int flags);
 638ssize_t sendto(int s, void* buf, size_t len, int flags, sockaddr* to, int tolen);
 639ssize_t recv(int s, void* buf, size_t len, int flags);
 640ssize_t recvfrom(int s, void* buf, size_t len, int flags, sockaddr* from, int* fromlen);
 641int getsockopt(int s, int level, int optname, void* optval, int* optlen);
 642int setsockopt(int s, int level, int optname, void* optval, int optlen);
 643uint inet_addr(char* cp);
 644char* inet_ntoa(in_addr ina);
 645hostent* gethostbyname(char* name);
 646int gethostbyname_r(char* name, hostent* ret, void* buf, size_t buflen, hostent** result, int* h_errnop);
 647int gethostbyname2_r(char* name, int af, hostent* ret, void* buf, size_t buflen, hostent** result, int* h_errnop);
 648hostent* gethostbyaddr(void* addr, int len, int type);
 649protoent* getprotobyname(char* name);
 650protoent* getprotobynumber(int number);
 651servent* getservbyname(char* name, char* proto);
 652servent* getservbyport(int port, char* proto);
 653int gethostname(char* name, int namelen);
 654int getaddrinfo(char* nodename, char* servname, addrinfo* hints, addrinfo** res);
 655void freeaddrinfo(addrinfo* ai);
 656int getnameinfo(sockaddr* sa, socklen_t salen, char* node, socklen_t nodelen, char* service, socklen_t servicelen, int flags);
 657
 658int htonl(int x);
 659short htons(int x);
 660
 661
 662//private import std.stdint;
 663
 664/*version(BigEndian)
 665  {
 666  uint16_t htons(uint16_t x)
 667  {
 668  return x;
 669  }
 670
 671
 672  uint32_t htonl(uint32_t x)
 673  {
 674  return x;
 675  }
 676  }
 677  else version(LittleEndian)
 678  {
 679  private import std.intrinsic;
 680
 681
 682  uint16_t htons(uint16_t x)
 683  {
 684  return (x >> 8) | (x << 8);
 685  }
 686
 687
 688  uint32_t htonl(uint32_t x)
 689  {
 690  return bswap(x);
 691  }
 692  }
 693  else
 694  {
 695  static assert(0);
 696  }*/
 697
 698//alias htons ntohs;
 699//alias htonl ntohl;
 700
 701// from <time.h>
 702//char* asctime_r(in tm* t, char* buf);
 703char* ctime_r(in time_t* timep, char* buf);
 704//tm* gmtime_r(in time_t* timep, tm* result);
 705//tm* localtime_r(in time_t* timep, tm* result);
 706
 707// misc.
 708uint alarm(uint);
 709char* basename(char*);
 710//wint_t btowc(int);
 711int chown(in char*, uid_t, gid_t);
 712int chroot(in char*);
 713size_t confstr(int, char*, size_t);
 714int creat(in char*, mode_t);
 715char* ctermid(char*);
 716char* dirname(char*);
 717int fattach(int, char*);
 718int fchmod(int, mode_t);
 719int fdatasync(int);
 720int ffs(int);
 721int fmtmsg(int, char*, int, char*, char*, char*);
 722int fpathconf(int, int);
 723
 724extern char** environ;
 725
 726// unix common somehow missing from phobos
 727
 728alias int clockid_t;
 729alias void* timer_t;
 730alias int time_t;
 731
 732alias int __pid_t;
 733
 734//struct timespec {
 735//	time_t tv_sec;		/* Seconds.  */
 736//	int tv_nsec;		/* Nanoseconds.  */
 737//};//
 738
 739struct itimerspec {
 740	timespec it_interval;
 741	timespec it_value;
 742};
 743
 744const auto SIGEV_SIGNAL	= 0;	/* notify via signal */
 745const auto SIGEV_NONE	= 1;	/* other notification: meaningless */
 746const auto SIGEV_THREAD	= 2;	/* deliver via thread creation */
 747
 748union sigval {
 749	int	sival_int;	/* integer value */
 750	void *sival_ptr;	/* pointer value */
 751}
 752
 753const int __SIGEV_PAD_SIZE = 13;
 754
 755// signals
 756
 757alias void function(int) sighandler_t;
 758
 759extern(C)
 760	sighandler_t signal(int signum, sighandler_t handler);
 761
 762	enum
 763{
 764	SIGHUP = 1,
 765	SIGINT,
 766	SIGQUIT,
 767	SIGILL,
 768	SIGTRAP,
 769	SIGABRT,
 770	SIGBUS,
 771	SIGFPE,
 772	SIGKILL,
 773	SIGUSR1,
 774	SIGSEGV,
 775	SIGUSR2,
 776	SIGPIPE,
 777	SIGALRM,
 778	SIGTERM,
 779	SIGSTKFLT,
 780	SIGCHLD,
 781	SIGCONT,
 782	SIGSTOP,
 783	SIGTSTP,
 784	SIGTTIN,
 785	SIGTTOU,
 786	SIGURG,
 787	SIGXCPU,
 788	SIGXFSZ,
 789	SIGVALRM,
 790	SIGPROF,
 791	SIGWINCH,
 792	SIGIO
 793}
 794
 795/* c_iflag bits */
 796const auto IGNBRK	= 0000001;
 797const auto BRKINT	= 0000002;
 798const auto IGNPAR	= 0000004;
 799const auto PARMRK	= 0000010;
 800const auto INPCK	= 0000020;
 801const auto ISTRIP	= 0000040;
 802const auto INLCR	= 0000100;
 803const auto IGNCR	= 0000200;
 804const auto ICRNL	= 0000400;
 805const auto IUCLC	= 0001000;
 806const auto IXON		= 0002000;
 807const auto IXANY	= 0004000;
 808const auto IXOFF	= 0010000;
 809const auto IMAXBEL	= 0020000;
 810const auto IUTF8	= 0040000;
 811
 812/* c_lflag bits */
 813const auto ISIG		= 0000001;
 814const auto ICANON	= 0000002;
 815const auto XCASE	= 0000004;
 816const auto ECHO		= 0000010;
 817const auto ECHOE	= 0000020;
 818const auto ECHOK	= 0000040;
 819const auto ECHONL	= 0000100;
 820const auto NOFLSH	= 0000200;
 821const auto TOSTOP	= 0000400;
 822const auto ECHOCTL	= 0001000;
 823const auto ECHOPRT	= 0002000;
 824const auto ECHOKE	= 0004000;
 825const auto FLUSHO	= 0010000;
 826const auto PENDIN	= 0040000;
 827const auto IEXTEN	= 0100000;
 828
 829
 830
 831struct sigevent_sigev_un_sigev_thread
 832{
 833	void function (sigval) _function; /* Function to start.  */
 834	void* _attribute;			/* Really pthread_attr_t.  */
 835}
 836
 837union sigevent_sigev_un
 838{
 839	int _pad[__SIGEV_PAD_SIZE];
 840
 841	/* When SIGEV_SIGNAL and SIGEV_THREAD_ID set, LWP ID of the
 842	   thread to receive the signal.  */
 843	__pid_t _tid;
 844
 845	sigevent_sigev_un_sigev_thread _sigev_thread;
 846
 847}
 848
 849struct sigevent
 850{
 851	sigval sigev_value;
 852	int sigev_signo;
 853	int sigev_notify;
 854
 855	sigevent_sigev_un _sigev_un;
 856}
 857
 858/+
 859struct sigevent {
 860	int		sigev_notify;	/* notification mode */
 861	int		sigev_signo;	/* signal number */
 862	sigval	sigev_value;	/* signal value */
 863	void function(sigval) sigev_notify_function;
 864	pthread_attr_t	*sigev_notify_attributes;
 865	int		__sigev_pad2;
 866}
 867+/
 868
 869enum:uint
 870{
 871	STDIN = 0,
 872	STDOUT = 1,
 873	STDERR = 2
 874}
 875
 876alias ubyte	cc_t;
 877alias uint	speed_t;
 878alias uint	tcflag_t;
 879
 880const auto NCCS = 19;
 881
 882struct termios {
 883	tcflag_t c_iflag;		/* input mode flags */
 884	tcflag_t c_oflag;		/* output mode flags */
 885	tcflag_t c_cflag;		/* control mode flags */
 886	tcflag_t c_lflag;		/* local mode flags */
 887	cc_t c_line;			/* line discipline */
 888	cc_t c_cc[NCCS];		/* control characters */
 889}
 890
 891extern(C)
 892	char *setlocale(int category, char *locale);
 893
 894extern(C)
 895	int timer_create(clockid_t clockid, sigevent* evp,
 896			timer_t *timerid);
 897
 898extern(C)
 899	int timer_delete(timer_t timerid);
 900
 901extern(C)
 902	int timer_settime(timer_t timerid, int flags,
 903			itimerspec* value, itimerspec* ovalue);
 904
 905extern(C)
 906	int nanosleep(timespec* rqtp, timespec* rmtp);
 907
 908extern (C)
 909	int ioctl (int, uint, ...);
 910
 911	alias void function(int) __sighandler_t;
 912
 913	extern(C) __sighandler_t sigset (int, __sighandler_t);
 914
 915	const int CLOCK_REALTIME = 0;
 916
 917enum:int
 918{
 919	LC_CTYPE = 0,
 920	LC_NUMERIC = 1,
 921	LC_TIME = 2,
 922	LC_COLLATE = 3,
 923	LC_MONETARY = 4,
 924	LC_MESSAGES = 5,
 925	LC_ALL = 6,
 926	LC_PAPER = 7,
 927	LC_NAME = 8,
 928	LC_ADDRESS = 9,
 929	LC_TELEPHONE = 10,
 930	LC_MEASUREMENT = 11,
 931	LC_IDENTIFICATION = 12,
 932}
 933
 934
 935/* 0x54 is just a magic number to make these relatively unique ('T') */
 936
 937const auto TCGETS		= 0x5401;
 938const auto TCSETS		= 0x5402; /* Clashes with SNDCTL_TMR_START sound ioctl */
 939const auto TCSETSW		= 0x5403;
 940const auto TCSETSF		= 0x5404;
 941const auto TCGETA		= 0x5405;
 942const auto TCSETA		= 0x5406;
 943const auto TCSETAW		= 0x5407;
 944const auto TCSETAF		= 0x5408;
 945const auto TCSBRK		= 0x5409;
 946const auto TCXONC		= 0x540A;
 947const auto TCFLSH		= 0x540B;
 948const auto TIOCEXCL		= 0x540C;
 949const auto TIOCNXCL		= 0x540D;
 950const auto TIOCSCTTY	= 0x540E;
 951const auto TIOCGPGRP	= 0x540F;
 952const auto TIOCSPGRP	= 0x5410;
 953const auto TIOCOUTQ		= 0x5411;
 954const auto TIOCSTI		= 0x5412;
 955const auto TIOCGWINSZ	= 0x5413;
 956const auto TIOCSWINSZ	= 0x5414;
 957const auto TIOCMGET		= 0x5415;
 958const auto TIOCMBIS		= 0x5416;
 959const auto TIOCMBIC		= 0x5417;
 960const auto TIOCMSET		= 0x5418;
 961const auto TIOCGSOFTCAR	= 0x5419;
 962const auto TIOCSSOFTCAR	= 0x541A;
 963const auto FIONREAD		= 0x541B;
 964const auto TIOCINQ		= FIONREAD;
 965const auto TIOCLINUX	= 0x541C;
 966const auto TIOCCONS		= 0x541D;
 967const auto TIOCGSERIAL	= 0x541E;
 968const auto TIOCSSERIAL	= 0x541F;
 969const auto TIOCPKT		= 0x5420;
 970const auto FIONBIO		= 0x5421;
 971const auto TIOCNOTTY	= 0x5422;
 972const auto TIOCSETD		= 0x5423;
 973const auto TIOCGETD		= 0x5424;
 974const auto TCSBRKP		= 0x5425;	/* Needed for POSIX tcsendbreak() */
 975/* const auto TIOCTTYGSTRUCT 0x5426 - Former debugging-only ioctl */
 976const auto TIOCSBRK		= 0x5427;  /* BSD compatibility */
 977const auto TIOCCBRK		= 0x5428;  /* BSD compatibility */
 978const auto TIOCGSID		= 0x5429;  /* Return the session ID of FD */
 979//const auto TIOCGPTN	_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 980//const auto TIOCSPTLCK	_IOW('T',0x31, int)  /* Lock/unlock Pty */
 981
 982const auto FIONCLEX			= 0x5450;
 983const auto FIOCLEX			= 0x5451;
 984const auto FIOASYNC			= 0x5452;
 985const auto TIOCSERCONFIG	= 0x5453;
 986const auto TIOCSERGWILD		= 0x5454;
 987const auto TIOCSERSWILD		= 0x5455;
 988const auto TIOCGLCKTRMIOS	= 0x5456;
 989const auto TIOCSLCKTRMIOS	= 0x5457;
 990const auto TIOCSERGSTRUCT	= 0x5458; /* For debugging only */
 991const auto TIOCSERGETLSR   	= 0x5459; /* Get line status register */
 992const auto TIOCSERGETMULTI 	= 0x545A; /* Get multiport config  */
 993const auto TIOCSERSETMULTI 	= 0x545B; /* Set multiport config */
 994
 995const auto TIOCMIWAIT		= 0x545C;	/* wait for a change on serial input line(s) */
 996const auto TIOCGICOUNT		= 0x545D;	/* read serial port __inline__ interrupt counts */
 997const auto TIOCGHAYESESP   	= 0x545E;  /* Get Hayes ESP configuration */
 998const auto TIOCSHAYESESP   	= 0x545F;  /* Set Hayes ESP configuration */
 999const auto FIOQSIZE			= 0x5460;
1000
1001/* Used for packet mode */
1002const auto TIOCPKT_DATA		 	=  0;
1003const auto TIOCPKT_FLUSHREAD	=  1;
1004const auto TIOCPKT_FLUSHWRITE	=  2;
1005const auto TIOCPKT_STOP		 	=  4;
1006const auto TIOCPKT_START		=  8;
1007const auto TIOCPKT_NOSTOP		= 16;
1008const auto TIOCPKT_DOSTOP		= 32;
1009
1010const auto TIOCSER_TEMT    		= 0x01;	/* Transmitter physically empty */
1011
1012enum
1013{
1014	IPPROTO_IP = 0,
1015	IPPROTO_ROUTING = 43,
1016	IPPROTO_EGP = 8,
1017	IPPROTO_PIM = 103,
1018	IPPROTO_ENCAP = 98,
1019	IPPROTO_ESP = 50,
1020	IPPROTO_PUP = 12,
1021	IPPROTO_IDP = 22,
1022	IPPROTO_IPIP = 4,
1023	IPPROTO_TCP = 6,
1024	IPPROTO_IPV6 = 41,
1025	IPPROTO_SCTP = 132,
1026	IPPROTO_AH = 51,
1027	IPPROTO_MTP = 92,
1028	IPPROTO_TP = 29,
1029	IPPROTO_UDP = 17,
1030	IPPROTO_HOPOPTS = 0,
1031	IPPROTO_RAW = 255,
1032	IPPROTO_ICMP = 1,
1033	IPPROTO_GGP = 3,
1034	IPPROTO_FRAGMENT = 44,
1035	IPPROTO_GRE = 47,
1036	IPPROTO_DSTOPTS = 60,
1037	IPPROTO_NONE = 59,
1038	IPPROTO_RSVP = 46,
1039	IPPROTO_IGMP = 2,
1040	IPPROTO_ICMPV6 = 58,
1041	IPPROTO_COMP = 108,
1042}
1043
1044enum
1045{
1046	IPV6_RTHDR_TYPE_0 = 0,
1047	IPV6_LEAVE_GROUP = 21,
1048	IPV6_PMTUDISC_WANT = 1,
1049	IPV6_NEXTHOP = 9,
1050	IPV6_IPSEC_POLICY = 34,
1051	IPV6_2292HOPOPTS = 3,
1052	IPV6_HOPOPTS = 54,
1053	IPV6_MTU_DISCOVER = 23,
1054	IPV6_AUTHHDR = 10,
1055	IPV6_ADD_MEMBERSHIP = 20,
1056	IPV6_DSTOPTS = 59,
1057	IPV6_2292PKTOPTIONS = 6,
1058	IPV6_RECVHOPOPTS = 53,
1059	IPV6_XFRM_POLICY = 35,
1060	IPV6_RXHOPOPTS = 54,
1061	IPV6_UNICAST_HOPS = 16,
1062	IPV6_ROUTER_ALERT = 22,
1063	IPV6_V6ONLY = 26,
1064	IPV6_RECVRTHDR = 56,
1065	IPV6_RECVHOPLIMIT = 51,
1066	IPV6_RECVTCLASS = 66,
1067	IPV6_RTHDR_STRICT = 1,
1068	IPV6_MTU = 24,
1069	IPV6_RECVDSTOPTS = 58,
1070	IPV6_MULTICAST_IF = 17,
1071	IPV6_RECVERR = 25,
1072	IPV6_RXDSTOPTS = 59,
1073	IPV6_2292PKTINFO = 2,
1074	IPV6_2292DSTOPTS = 4,
1075	IPV6_MULTICAST_HOPS = 18,
1076	IPV6_HOPLIMIT = 52,
1077	IPV6_PMTUDISC_DO = 2,
1078	IPV6_PKTINFO = 50,
1079	IPV6_RTHDRDSTOPTS = 55,
1080	IPV6_JOIN_ANYCAST = 27,
1081	IPV6_TCLASS = 67,
1082	IPV6_2292RTHDR = 5,
1083	IPV6_RTHDR_LOOSE = 0,
1084	IPV6_ADDRFORM = 1,
1085	IPV6_JOIN_GROUP = 20,
1086	IPV6_RTHDR = 57,
1087	IPV6_RECVPKTINFO = 49,
1088	IPV6_DROP_MEMBERSHIP = 21,
1089	IPV6_MULTICAST_LOOP = 19,
1090	IPV6_2292HOPLIMIT = 8,
1091	IPV6_LEAVE_ANYCAST = 28,
1092	IPV6_PMTUDISC_DONT = 0,
1093	IPV6_CHECKSUM = 7,
1094}
1095
1096enum : uint
1097{
1098	INADDR_MAX_LOCAL_GROUP = -536870657,
1099	INADDR_ALLHOSTS_GROUP = -536870911,
1100	INADDR_ANY = 0,
1101	INADDR_UNSPEC_GROUP = -536870912,
1102	INADDR_NONE = -1,
1103	INADDR_ALLRTRS_GROUP = -536870910,
1104	INADDR_LOOPBACK = 2130706433,
1105	INADDR_BROADCAST = -1,
1106}
1107
1108enum { ADDR_ANY = INADDR_ANY }
1109enum
1110{
1111	TCP_KEEPCNT = 6,
1112	TCP_CONGESTION = 13,
1113	TCP_CORK = 3,
1114	TCP_WINDOW_CLAMP = 10,
1115	TCP_MSS = 512,
1116	TCP_DEFER_ACCEPT = 9,
1117	TCP_KEEPIDLE = 4,
1118	TCP_MD5SIG_MAXKEYLEN = 80,
1119	TCP_MAX_WINSHIFT = 14,
1120	TCP_SYNCNT = 7,
1121	TCP_MAXSEG = 2,
1122	TCP_QUICKACK = 12,
1123	TCP_MAXWIN = 65535,
1124	TCP_KEEPINTVL = 5,
1125	TCP_INFO = 11,
1126	TCP_LINGER2 = 8,
1127	TCP_MD5SIG = 14,
1128	TCP_NODELAY = 1,
1129}
1130
1131
1132enum
1133{
1134	SOCK_RAW = 3,
1135	SOCK_RDM = 4,
1136	SOCK_SEQPACKET = 5,
1137	SOCK_PACKET = 10,
1138	SOCK_DGRAM = 2,
1139	SOCK_STREAM = 1,
1140}
1141