mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-02-28 01:23:14 +01:00
[svn r5] Initial commit. Most things are very rough.
This commit is contained in:
478
lphobos/std/c/linux/linux.d
Normal file
478
lphobos/std/c/linux/linux.d
Normal file
@@ -0,0 +1,478 @@
|
||||
|
||||
/* Written by Walter Bright, Christopher E. Miller, and many others.
|
||||
* www.digitalmars.com
|
||||
* Placed into public domain.
|
||||
* Linux(R) is the registered trademark of Linus Torvalds in the U.S. and other
|
||||
* countries.
|
||||
*/
|
||||
|
||||
module std.c.linux.linux;
|
||||
|
||||
public import std.c.linux.linuxextern;
|
||||
public import std.c.linux.pthread;
|
||||
|
||||
private import std.c.stdio;
|
||||
|
||||
alias int pid_t;
|
||||
alias int off_t;
|
||||
alias uint mode_t;
|
||||
|
||||
alias uint uid_t;
|
||||
alias uint gid_t;
|
||||
|
||||
static if (size_t.sizeof == 4)
|
||||
alias int ssize_t;
|
||||
else
|
||||
alias long ssize_t;
|
||||
|
||||
enum : int
|
||||
{
|
||||
SIGHUP = 1,
|
||||
SIGINT = 2,
|
||||
SIGQUIT = 3,
|
||||
SIGILL = 4,
|
||||
SIGTRAP = 5,
|
||||
SIGABRT = 6,
|
||||
SIGIOT = 6,
|
||||
SIGBUS = 7,
|
||||
SIGFPE = 8,
|
||||
SIGKILL = 9,
|
||||
SIGUSR1 = 10,
|
||||
SIGSEGV = 11,
|
||||
SIGUSR2 = 12,
|
||||
SIGPIPE = 13,
|
||||
SIGALRM = 14,
|
||||
SIGTERM = 15,
|
||||
SIGSTKFLT = 16,
|
||||
SIGCHLD = 17,
|
||||
SIGCONT = 18,
|
||||
SIGSTOP = 19,
|
||||
SIGTSTP = 20,
|
||||
SIGTTIN = 21,
|
||||
SIGTTOU = 22,
|
||||
SIGURG = 23,
|
||||
SIGXCPU = 24,
|
||||
SIGXFSZ = 25,
|
||||
SIGVTALRM = 26,
|
||||
SIGPROF = 27,
|
||||
SIGWINCH = 28,
|
||||
SIGPOLL = 29,
|
||||
SIGIO = 29,
|
||||
SIGPWR = 30,
|
||||
SIGSYS = 31,
|
||||
SIGUNUSED = 31,
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
O_RDONLY = 0,
|
||||
O_WRONLY = 1,
|
||||
O_RDWR = 2,
|
||||
O_CREAT = 0100,
|
||||
O_EXCL = 0200,
|
||||
O_TRUNC = 01000,
|
||||
O_APPEND = 02000,
|
||||
}
|
||||
|
||||
struct struct_stat // distinguish it from the stat() function
|
||||
{
|
||||
ulong st_dev; /// device
|
||||
ushort __pad1;
|
||||
uint st_ino; /// file serial number
|
||||
uint st_mode; /// file mode
|
||||
uint st_nlink; /// link count
|
||||
uint st_uid; /// user ID of file's owner
|
||||
uint st_gid; /// user ID of group's owner
|
||||
ulong st_rdev; /// if device then device number
|
||||
ushort __pad2;
|
||||
int st_size; /// file size in bytes
|
||||
int st_blksize; /// optimal I/O block size
|
||||
int st_blocks; /// number of allocated 512 byte blocks
|
||||
int st_atime;
|
||||
uint st_atimensec;
|
||||
int st_mtime;
|
||||
uint st_mtimensec;
|
||||
int st_ctime;
|
||||
uint st_ctimensec;
|
||||
|
||||
uint __unused4;
|
||||
uint __unused5;
|
||||
}
|
||||
|
||||
static assert(struct_stat.sizeof == 88);
|
||||
|
||||
enum : int
|
||||
{
|
||||
S_IFIFO = 0010000,
|
||||
S_IFCHR = 0020000,
|
||||
S_IFDIR = 0040000,
|
||||
S_IFBLK = 0060000,
|
||||
S_IFREG = 0100000,
|
||||
S_IFLNK = 0120000,
|
||||
S_IFSOCK = 0140000,
|
||||
|
||||
S_IFMT = 0170000,
|
||||
|
||||
S_IREAD = 0000400,
|
||||
S_IWRITE = 0000200,
|
||||
S_IEXEC = 0000100,
|
||||
}
|
||||
|
||||
extern (C)
|
||||
{
|
||||
int access(char*, int);
|
||||
int open(char*, int, ...);
|
||||
int read(int, void*, int);
|
||||
int write(int, void*, int);
|
||||
int close(int);
|
||||
int lseek(int, int, int);
|
||||
int fstat(int, struct_stat*);
|
||||
int lstat(char*, struct_stat*);
|
||||
int stat(char*, struct_stat*);
|
||||
int chdir(char*);
|
||||
int mkdir(char*, int);
|
||||
int rmdir(char*);
|
||||
char* getcwd(char*, int);
|
||||
int chmod(char*, mode_t);
|
||||
int fork();
|
||||
int dup(int);
|
||||
int dup2(int, int);
|
||||
int pipe(int[2]);
|
||||
pid_t wait(int*);
|
||||
int waitpid(pid_t, int*, int);
|
||||
|
||||
uint alarm(uint);
|
||||
char* basename(char*);
|
||||
//wint_t btowc(int);
|
||||
int chown(char*, uid_t, gid_t);
|
||||
int chroot(char*);
|
||||
size_t confstr(int, char*, size_t);
|
||||
int creat(char*, mode_t);
|
||||
char* ctermid(char*);
|
||||
int dirfd(DIR*);
|
||||
char* dirname(char*);
|
||||
int fattach(int, char*);
|
||||
int fchmod(int, mode_t);
|
||||
int fdatasync(int);
|
||||
int ffs(int);
|
||||
int fmtmsg(int, char*, int, char*, char*, char*);
|
||||
int fpathconf(int, int);
|
||||
int fseeko(FILE*, off_t, int);
|
||||
off_t ftello(FILE*);
|
||||
|
||||
extern char** environ;
|
||||
}
|
||||
|
||||
struct timeval
|
||||
{
|
||||
int tv_sec;
|
||||
int tv_usec;
|
||||
}
|
||||
|
||||
struct struct_timezone
|
||||
{
|
||||
int tz_minuteswest;
|
||||
int tz_dstime;
|
||||
}
|
||||
|
||||
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;
|
||||
int tm_zone;
|
||||
}
|
||||
|
||||
extern (C)
|
||||
{
|
||||
int gettimeofday(timeval*, struct_timezone*);
|
||||
__time_t time(__time_t*);
|
||||
char* asctime(tm*);
|
||||
char* ctime(__time_t*);
|
||||
tm* gmtime(__time_t*);
|
||||
tm* localtime(__time_t*);
|
||||
__time_t mktime(tm*);
|
||||
char* asctime_r(tm* t, char* buf);
|
||||
char* ctime_r(__time_t* timep, char* buf);
|
||||
tm* gmtime_r(__time_t* timep, tm* result);
|
||||
tm* localtime_r(__time_t* timep, tm* result);
|
||||
}
|
||||
|
||||
/**************************************************************/
|
||||
// Memory mapping from <sys/mman.h> and <bits/mman.h>
|
||||
|
||||
enum
|
||||
{
|
||||
PROT_NONE = 0,
|
||||
PROT_READ = 1,
|
||||
PROT_WRITE = 2,
|
||||
PROT_EXEC = 4,
|
||||
}
|
||||
|
||||
// Memory mapping sharing types
|
||||
|
||||
enum
|
||||
{ MAP_SHARED = 1,
|
||||
MAP_PRIVATE = 2,
|
||||
MAP_TYPE = 0x0F,
|
||||
MAP_FIXED = 0x10,
|
||||
MAP_FILE = 0,
|
||||
MAP_ANONYMOUS = 0x20,
|
||||
MAP_ANON = 0x20,
|
||||
MAP_GROWSDOWN = 0x100,
|
||||
MAP_DENYWRITE = 0x800,
|
||||
MAP_EXECUTABLE = 0x1000,
|
||||
MAP_LOCKED = 0x2000,
|
||||
MAP_NORESERVE = 0x4000,
|
||||
MAP_POPULATE = 0x8000,
|
||||
MAP_NONBLOCK = 0x10000,
|
||||
}
|
||||
|
||||
// Values for msync()
|
||||
|
||||
enum
|
||||
{ MS_ASYNC = 1,
|
||||
MS_INVALIDATE = 2,
|
||||
MS_SYNC = 4,
|
||||
}
|
||||
|
||||
// Values for mlockall()
|
||||
|
||||
enum
|
||||
{
|
||||
MCL_CURRENT = 1,
|
||||
MCL_FUTURE = 2,
|
||||
}
|
||||
|
||||
// Values for mremap()
|
||||
|
||||
enum
|
||||
{
|
||||
MREMAP_MAYMOVE = 1,
|
||||
}
|
||||
|
||||
// Values for madvise
|
||||
|
||||
enum
|
||||
{ MADV_NORMAL = 0,
|
||||
MADV_RANDOM = 1,
|
||||
MADV_SEQUENTIAL = 2,
|
||||
MADV_WILLNEED = 3,
|
||||
MADV_DONTNEED = 4,
|
||||
}
|
||||
|
||||
extern (C)
|
||||
{
|
||||
void* mmap(void*, size_t, int, int, int, off_t);
|
||||
const void* MAP_FAILED = cast(void*)-1;
|
||||
|
||||
int munmap(void*, size_t);
|
||||
int mprotect(void*, size_t, int);
|
||||
int msync(void*, size_t, int);
|
||||
int madvise(void*, size_t, int);
|
||||
int mlock(void*, size_t);
|
||||
int munlock(void*, size_t);
|
||||
int mlockall(int);
|
||||
int munlockall();
|
||||
void* mremap(void*, size_t, size_t, int);
|
||||
int mincore(void*, size_t, ubyte*);
|
||||
int remap_file_pages(void*, size_t, int, size_t, int);
|
||||
int shm_open(char*, int, int);
|
||||
int shm_unlink(char*);
|
||||
}
|
||||
|
||||
extern(C)
|
||||
{
|
||||
|
||||
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,
|
||||
DT_WHT = 14,
|
||||
}
|
||||
|
||||
struct dirent
|
||||
{
|
||||
int d_ino;
|
||||
off_t d_off;
|
||||
ushort d_reclen;
|
||||
ubyte d_type;
|
||||
char[256] d_name;
|
||||
}
|
||||
|
||||
struct DIR
|
||||
{
|
||||
// Managed by OS.
|
||||
}
|
||||
|
||||
DIR* opendir(char* name);
|
||||
int closedir(DIR* dir);
|
||||
dirent* readdir(DIR* dir);
|
||||
void rewinddir(DIR* dir);
|
||||
off_t telldir(DIR* dir);
|
||||
void seekdir(DIR* dir, off_t offset);
|
||||
}
|
||||
|
||||
|
||||
extern(C)
|
||||
{
|
||||
private import std.intrinsic;
|
||||
|
||||
|
||||
int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* errorfds, timeval* timeout);
|
||||
int fcntl(int s, int f, ...);
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
EINTR = 4,
|
||||
EINPROGRESS = 115,
|
||||
}
|
||||
|
||||
|
||||
const uint FD_SETSIZE = 1024;
|
||||
//const uint NFDBITS = 8 * int.sizeof; // DMD 0.110: 8 * (int).sizeof is not an expression
|
||||
const int NFDBITS = 32;
|
||||
|
||||
|
||||
struct fd_set
|
||||
{
|
||||
int[FD_SETSIZE / NFDBITS] fds_bits;
|
||||
alias fds_bits __fds_bits;
|
||||
}
|
||||
|
||||
|
||||
int FDELT(int d)
|
||||
{
|
||||
return d / NFDBITS;
|
||||
}
|
||||
|
||||
|
||||
int FDMASK(int d)
|
||||
{
|
||||
return 1 << (d % NFDBITS);
|
||||
}
|
||||
|
||||
|
||||
// Removes.
|
||||
void FD_CLR(int fd, fd_set* set)
|
||||
{
|
||||
btr(cast(uint*)&set.fds_bits.ptr[FDELT(fd)], cast(uint)(fd % NFDBITS));
|
||||
}
|
||||
|
||||
|
||||
// Tests.
|
||||
int FD_ISSET(int fd, fd_set* set)
|
||||
{
|
||||
return bt(cast(uint*)&set.fds_bits.ptr[FDELT(fd)], cast(uint)(fd % NFDBITS));
|
||||
}
|
||||
|
||||
|
||||
// Adds.
|
||||
void FD_SET(int fd, fd_set* set)
|
||||
{
|
||||
bts(cast(uint*)&set.fds_bits.ptr[FDELT(fd)], cast(uint)(fd % NFDBITS));
|
||||
}
|
||||
|
||||
|
||||
// Resets to zero.
|
||||
void FD_ZERO(fd_set* set)
|
||||
{
|
||||
set.fds_bits[] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern (C)
|
||||
{
|
||||
/* From <dlfcn.h>
|
||||
* See http://www.opengroup.org/onlinepubs/007908799/xsh/dlsym.html
|
||||
*/
|
||||
|
||||
const int RTLD_NOW = 0x00002; // Correct for Red Hat 8
|
||||
|
||||
void* dlopen(char* file, int mode);
|
||||
int dlclose(void* handle);
|
||||
void* dlsym(void* handle, char* name);
|
||||
char* dlerror();
|
||||
}
|
||||
|
||||
extern (C)
|
||||
{
|
||||
/* from <pwd.h>
|
||||
*/
|
||||
|
||||
struct passwd
|
||||
{
|
||||
char *pw_name;
|
||||
char *pw_passwd;
|
||||
uid_t pw_uid;
|
||||
gid_t pw_gid;
|
||||
char *pw_gecos;
|
||||
char *pw_dir;
|
||||
char *pw_shell;
|
||||
}
|
||||
|
||||
const size_t _SIGSET_NWORDS = 1024 / (8 * uint.sizeof);
|
||||
struct sigset_t
|
||||
{
|
||||
uint[_SIGSET_NWORDS] __val;
|
||||
}
|
||||
|
||||
int getpwnam_r(char*, passwd*, void*, size_t, passwd**);
|
||||
passwd* getpwnam(char*);
|
||||
passwd* getpwuid(uid_t);
|
||||
int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**);
|
||||
int kill(pid_t, int);
|
||||
int sem_close(sem_t*);
|
||||
int sigemptyset(sigset_t*);
|
||||
int sigfillset(sigset_t*);
|
||||
int sigismember(sigset_t*, int);
|
||||
int sigsuspend(sigset_t*);
|
||||
}
|
||||
|
||||
extern (C)
|
||||
{
|
||||
/* from semaphore.h
|
||||
*/
|
||||
|
||||
struct sem_t
|
||||
{
|
||||
_pthread_fastlock __sem_lock;
|
||||
int __sem_value;
|
||||
void* __sem_waiting;
|
||||
}
|
||||
|
||||
int sem_init(sem_t*, int, uint);
|
||||
int sem_wait(sem_t*);
|
||||
int sem_trywait(sem_t*);
|
||||
int sem_post(sem_t*);
|
||||
int sem_getvalue(sem_t*, int*);
|
||||
int sem_destroy(sem_t*);
|
||||
}
|
||||
|
||||
extern (C)
|
||||
{
|
||||
/* from utime.h
|
||||
*/
|
||||
|
||||
struct utimbuf
|
||||
{
|
||||
__time_t actime;
|
||||
__time_t modtime;
|
||||
}
|
||||
|
||||
int utime(char* filename, utimbuf* buf);
|
||||
}
|
||||
25
lphobos/std/c/linux/linuxextern.d
Normal file
25
lphobos/std/c/linux/linuxextern.d
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
/* Written by Walter Bright.
|
||||
* www.digitalmars.com
|
||||
* Placed into public domain.
|
||||
* Linux(R) is the registered trademark of Linus Torvalds in the U.S. and other
|
||||
* countries.
|
||||
*/
|
||||
|
||||
/* These are all the globals defined by the linux C runtime library.
|
||||
* Put them separate so they'll be externed - do not link in linuxextern.o
|
||||
*/
|
||||
|
||||
module std.c.linux.linuxextern;
|
||||
|
||||
extern (C)
|
||||
{
|
||||
void* __libc_stack_end;
|
||||
int __data_start;
|
||||
int _end;
|
||||
int timezone;
|
||||
|
||||
void *_deh_beg;
|
||||
void *_deh_end;
|
||||
}
|
||||
|
||||
257
lphobos/std/c/linux/pthread.d
Normal file
257
lphobos/std/c/linux/pthread.d
Normal file
@@ -0,0 +1,257 @@
|
||||
/* Written by Walter Bright, Christopher E. Miller, and many others.
|
||||
* www.digitalmars.com
|
||||
* Placed into public domain.
|
||||
*/
|
||||
|
||||
module std.c.linux.pthread;
|
||||
|
||||
extern (C)
|
||||
{
|
||||
/* pthread declarations taken from pthread headers and
|
||||
http://svn.dsource.org/projects/bindings/trunk/pthreads.d
|
||||
*/
|
||||
|
||||
/* from bits/types.h
|
||||
*/
|
||||
|
||||
typedef int __time_t;
|
||||
|
||||
/* from time.h
|
||||
*/
|
||||
|
||||
struct timespec
|
||||
{
|
||||
__time_t tv_sec; /* seconds */
|
||||
int tv_nsec; /* nanosecs. */
|
||||
}
|
||||
|
||||
/* from bits/pthreadtypes.h
|
||||
*/
|
||||
|
||||
alias uint pthread_t;
|
||||
alias uint pthread_key_t;
|
||||
alias int pthread_once_t;
|
||||
alias int clockid_t;
|
||||
alias int pthread_spinlock_t; // volatile
|
||||
|
||||
struct _pthread_descr_struct
|
||||
{
|
||||
/* Not defined in the headers ???
|
||||
Just needed here to typedef
|
||||
the _pthread_descr pointer
|
||||
*/
|
||||
}
|
||||
|
||||
typedef _pthread_descr_struct* _pthread_descr;
|
||||
|
||||
struct _pthread_fastlock
|
||||
{
|
||||
int __status;
|
||||
int __spinlock;
|
||||
}
|
||||
|
||||
typedef long __pthread_cond_align_t;
|
||||
|
||||
struct pthread_cond_t
|
||||
{
|
||||
_pthread_fastlock __c_lock;
|
||||
_pthread_descr __c_waiting;
|
||||
char[48
|
||||
- _pthread_fastlock.sizeof
|
||||
- _pthread_descr.sizeof
|
||||
- __pthread_cond_align_t.sizeof
|
||||
] __padding;
|
||||
__pthread_cond_align_t __align;
|
||||
}
|
||||
|
||||
struct pthread_condattr_t
|
||||
{
|
||||
int __dummy;
|
||||
}
|
||||
|
||||
struct pthread_mutex_t
|
||||
{
|
||||
int __m_reserved;
|
||||
int __m_count;
|
||||
_pthread_descr __m_owner;
|
||||
int __m_kind;
|
||||
_pthread_fastlock __m_lock;
|
||||
}
|
||||
|
||||
struct pthread_mutexattr_t
|
||||
{
|
||||
int __mutexkind;
|
||||
}
|
||||
|
||||
/* from pthread.h
|
||||
*/
|
||||
|
||||
struct _pthread_cleanup_buffer
|
||||
{
|
||||
void function(void*) __routine;
|
||||
void* __arg;
|
||||
int __canceltype;
|
||||
_pthread_cleanup_buffer* __prev;
|
||||
}
|
||||
|
||||
struct __sched_param // bits/sched.h
|
||||
{
|
||||
int __sched_priority;
|
||||
}
|
||||
|
||||
struct pthread_attr_t
|
||||
{
|
||||
int __detachstate;
|
||||
int __schedpolicy;
|
||||
__sched_param schedparam;
|
||||
int __inheritshed;
|
||||
int __scope;
|
||||
size_t __guardsize;
|
||||
int __stackaddr_set;
|
||||
void* __stackaddr;
|
||||
size_t __stacksize;
|
||||
}
|
||||
|
||||
struct pthread_barrier_t
|
||||
{
|
||||
_pthread_fastlock __ba_lock;
|
||||
int __ba_required;
|
||||
int __ba_present;
|
||||
_pthread_descr __ba_waiting;
|
||||
}
|
||||
|
||||
struct pthread_barrierattr_t
|
||||
{
|
||||
int __pshared;
|
||||
}
|
||||
|
||||
struct pthread_rwlockattr_t
|
||||
{
|
||||
int __lockkind;
|
||||
int __pshared;
|
||||
}
|
||||
|
||||
struct pthread_rwlock_t
|
||||
{
|
||||
_pthread_fastlock __rw_lock;
|
||||
int __rw_readers;
|
||||
_pthread_descr __rw_writer;
|
||||
_pthread_descr __rw_read_waiting;
|
||||
_pthread_descr __rw_write_waiting;
|
||||
int __rw_kind;
|
||||
int __rw_pshared;
|
||||
}
|
||||
|
||||
int pthread_mutex_init(pthread_mutex_t*, pthread_mutexattr_t*);
|
||||
int pthread_mutex_destroy(pthread_mutex_t*);
|
||||
int pthread_mutex_trylock(pthread_mutex_t*);
|
||||
int pthread_mutex_lock(pthread_mutex_t*);
|
||||
int pthread_mutex_unlock(pthread_mutex_t*);
|
||||
|
||||
int pthread_mutexattr_init(pthread_mutexattr_t*);
|
||||
int pthread_mutexattr_destroy(pthread_mutexattr_t*);
|
||||
|
||||
int pthread_cond_init(pthread_cond_t*, pthread_condattr_t*);
|
||||
int pthread_cond_destroy(pthread_cond_t*);
|
||||
int pthread_cond_signal(pthread_cond_t*);
|
||||
int pthread_cond_wait(pthread_cond_t*, pthread_mutex_t*);
|
||||
int pthread_cond_timedwait(pthread_cond_t*, pthread_mutex_t*, timespec*);
|
||||
|
||||
int pthread_attr_init(pthread_attr_t*);
|
||||
int pthread_attr_destroy(pthread_attr_t*);
|
||||
int pthread_attr_setdetachstate(pthread_attr_t*, int);
|
||||
int pthread_attr_getdetachstate(pthread_attr_t*, int*);
|
||||
int pthread_attr_setinheritsched(pthread_attr_t*, int);
|
||||
int pthread_attr_getinheritsched(pthread_attr_t*, int*);
|
||||
int pthread_attr_setschedparam(pthread_attr_t*, __sched_param*);
|
||||
int pthread_attr_getschedparam(pthread_attr_t*, __sched_param*);
|
||||
int pthread_attr_setschedpolicy(pthread_attr_t*, int);
|
||||
int pthread_attr_getschedpolicy(pthread_attr_t*, int*);
|
||||
int pthread_attr_setscope(pthread_attr_t*, int);
|
||||
int pthread_attr_getscope(pthread_attr_t*, int*);
|
||||
int pthread_attr_setguardsize(pthread_attr_t*, size_t);
|
||||
int pthread_attr_getguardsize(pthread_attr_t*, size_t*);
|
||||
int pthread_attr_setstack(pthread_attr_t*, void*, size_t);
|
||||
int pthread_attr_getstack(pthread_attr_t*, void**, size_t*);
|
||||
int pthread_attr_setstackaddr(pthread_attr_t*, void*);
|
||||
int pthread_attr_getstackaddr(pthread_attr_t*, void**);
|
||||
int pthread_attr_setstacksize(pthread_attr_t*, size_t);
|
||||
int pthread_attr_getstacksize(pthread_attr_t*, size_t*);
|
||||
|
||||
int pthread_barrierattr_init(pthread_barrierattr_t*);
|
||||
int pthread_barrierattr_getpshared(pthread_barrierattr_t*, int*);
|
||||
int pthread_barrierattr_destroy(pthread_barrierattr_t*);
|
||||
int pthread_barrierattr_setpshared(pthread_barrierattr_t*, int);
|
||||
|
||||
int pthread_barrier_init(pthread_barrier_t*, pthread_barrierattr_t*, uint);
|
||||
int pthread_barrier_destroy(pthread_barrier_t*);
|
||||
int pthread_barrier_wait(pthread_barrier_t*);
|
||||
|
||||
int pthread_condattr_init(pthread_condattr_t*);
|
||||
int pthread_condattr_destroy(pthread_condattr_t*);
|
||||
int pthread_condattr_getpshared(pthread_condattr_t*, int*);
|
||||
int pthread_condattr_setpshared(pthread_condattr_t*, int);
|
||||
|
||||
int pthread_detach(pthread_t);
|
||||
void pthread_exit(void*);
|
||||
int pthread_getattr_np(pthread_t, pthread_attr_t*);
|
||||
int pthread_getconcurrency();
|
||||
int pthread_getcpuclockid(pthread_t, clockid_t*);
|
||||
|
||||
int pthread_mutexattr_getpshared(pthread_mutexattr_t*, int*);
|
||||
int pthread_mutexattr_setpshared(pthread_mutexattr_t*, int);
|
||||
int pthread_mutexattr_settype(pthread_mutexattr_t*, int);
|
||||
int pthread_mutexattr_gettype(pthread_mutexattr_t*, int*);
|
||||
int pthread_mutex_timedlock(pthread_mutex_t*, timespec*);
|
||||
int pthread_yield();
|
||||
|
||||
int pthread_rwlock_init(pthread_rwlock_t*, pthread_rwlockattr_t*);
|
||||
int pthread_rwlock_destroy(pthread_rwlock_t*);
|
||||
int pthread_rwlock_rdlock(pthread_rwlock_t*);
|
||||
int pthread_rwlock_tryrdlock(pthread_rwlock_t*);
|
||||
int pthread_rwlock_timedrdlock(pthread_rwlock_t*, timespec*);
|
||||
int pthread_rwlock_wrlock(pthread_rwlock_t*);
|
||||
int pthread_rwlock_trywrlock(pthread_rwlock_t*);
|
||||
int pthread_rwlock_timedwrlock(pthread_rwlock_t*, timespec*);
|
||||
int pthread_rwlock_unlock(pthread_rwlock_t*);
|
||||
|
||||
int pthread_rwlockattr_init(pthread_rwlockattr_t*);
|
||||
int pthread_rwlockattr_destroy(pthread_rwlockattr_t*);
|
||||
int pthread_rwlockattr_getpshared(pthread_rwlockattr_t*, int*);
|
||||
int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int);
|
||||
int pthread_rwlockattr_getkind_np(pthread_rwlockattr_t*, int*);
|
||||
int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t*, int);
|
||||
|
||||
int pthread_spin_init(pthread_spinlock_t*, int);
|
||||
int pthread_spin_destroy(pthread_spinlock_t*);
|
||||
int pthread_spin_lock(pthread_spinlock_t*);
|
||||
int pthread_spin_trylock(pthread_spinlock_t*);
|
||||
int pthread_spin_unlock(pthread_spinlock_t*);
|
||||
|
||||
int pthread_cancel(pthread_t);
|
||||
void pthread_testcancel();
|
||||
int pthread_once(pthread_once_t*, void function());
|
||||
|
||||
int pthread_join(pthread_t, void**);
|
||||
int pthread_create(pthread_t*, pthread_attr_t*, void*function(void*), void*);
|
||||
pthread_t pthread_self();
|
||||
int pthread_equal(pthread_t, pthread_t);
|
||||
int pthread_atfork(void function(), void function(), void function());
|
||||
void pthread_kill_other_threads_np();
|
||||
int pthread_setschedparam(pthread_t, int, __sched_param*);
|
||||
int pthread_getschedparam(pthread_t, int*, __sched_param*);
|
||||
int pthread_cond_broadcast(pthread_cond_t*);
|
||||
int pthread_key_create(pthread_key_t*, void function(void*));
|
||||
int pthread_key_delete(pthread_key_t);
|
||||
int pthread_setconcurrency(int);
|
||||
int pthread_setspecific(pthread_key_t, void*);
|
||||
void* pthread_getspecific(pthread_key_t);
|
||||
int pthread_setcanceltype(int, int*);
|
||||
int pthread_setcancelstate(int, int*);
|
||||
|
||||
void _pthread_cleanup_push(_pthread_cleanup_buffer*, void function(void*), void*);
|
||||
void _pthread_cleanup_push_defer(_pthread_cleanup_buffer*, void function(void*), void*);
|
||||
void _pthread_cleanup_pop(_pthread_cleanup_buffer*, int);
|
||||
void _pthread_cleanup_pop_restore(_pthread_cleanup_buffer*, int);
|
||||
}
|
||||
|
||||
396
lphobos/std/c/linux/socket.d
Normal file
396
lphobos/std/c/linux/socket.d
Normal file
@@ -0,0 +1,396 @@
|
||||
/*
|
||||
Written by Christopher E. Miller
|
||||
Placed into public domain.
|
||||
*/
|
||||
|
||||
|
||||
module std.c.linux.socket;
|
||||
|
||||
private import std.stdint;
|
||||
|
||||
|
||||
extern(C):
|
||||
|
||||
alias int socklen_t;
|
||||
|
||||
const int F_GETFL = 3;
|
||||
const int F_SETFL = 4;
|
||||
const int O_NONBLOCK = 0x800;
|
||||
|
||||
|
||||
int socket(int af, int type, int protocol);
|
||||
int bind(int s, sockaddr* name, int namelen);
|
||||
int connect(int s, sockaddr* name, int namelen);
|
||||
int listen(int s, int backlog);
|
||||
int accept(int s, sockaddr* addr, int* addrlen);
|
||||
int shutdown(int s, int how);
|
||||
int getpeername(int s, sockaddr* name, int* namelen);
|
||||
int getsockname(int s, sockaddr* name, int* namelen);
|
||||
int send(int s, void* buf, int len, int flags);
|
||||
int sendto(int s, void* buf, int len, int flags, sockaddr* to, int tolen);
|
||||
int recv(int s, void* buf, int len, int flags);
|
||||
int recvfrom(int s, void* buf, int len, int flags, sockaddr* from, int* fromlen);
|
||||
int getsockopt(int s, int level, int optname, void* optval, int* optlen);
|
||||
int setsockopt(int s, int level, int optname, void* optval, int optlen);
|
||||
uint inet_addr(char* cp);
|
||||
char* inet_ntoa(in_addr ina);
|
||||
hostent* gethostbyname(char* name);
|
||||
int gethostbyname_r(char* name, hostent* ret, void* buf, size_t buflen, hostent** result, int* h_errnop);
|
||||
int gethostbyname2_r(char* name, int af, hostent* ret, void* buf, size_t buflen, hostent** result, int* h_errnop);
|
||||
hostent* gethostbyaddr(void* addr, int len, int type);
|
||||
protoent* getprotobyname(char* name);
|
||||
protoent* getprotobynumber(int number);
|
||||
servent* getservbyname(char* name, char* proto);
|
||||
servent* getservbyport(int port, char* proto);
|
||||
int gethostname(char* name, int namelen);
|
||||
int getaddrinfo(char* nodename, char* servname, addrinfo* hints, addrinfo** res);
|
||||
void freeaddrinfo(addrinfo* ai);
|
||||
int getnameinfo(sockaddr* sa, socklen_t salen, char* node, socklen_t nodelen, char* service, socklen_t servicelen, int flags);
|
||||
|
||||
|
||||
|
||||
enum: int
|
||||
{
|
||||
AF_UNSPEC = 0,
|
||||
AF_UNIX = 1,
|
||||
AF_INET = 2,
|
||||
AF_IPX = 4,
|
||||
AF_APPLETALK = 5,
|
||||
AF_INET6 = 10,
|
||||
// ...
|
||||
|
||||
PF_UNSPEC = AF_UNSPEC,
|
||||
PF_UNIX = AF_UNIX,
|
||||
PF_INET = AF_INET,
|
||||
PF_IPX = AF_IPX,
|
||||
PF_APPLETALK = AF_APPLETALK,
|
||||
PF_INET6 = AF_INET6,
|
||||
}
|
||||
|
||||
|
||||
version(X86)
|
||||
version=SOL_SOCKET_IS_1;
|
||||
else version(X86_64)
|
||||
version=SOL_SOCKET_IS_1;
|
||||
else version(PPC)
|
||||
version=SOL_SOCKET_IS_1;
|
||||
else version(PPC64)
|
||||
version=SOL_SOCKET_IS_1;
|
||||
else
|
||||
static assert(0, "Unsupported architecture");
|
||||
|
||||
version(SOL_SOCKET_IS_1)
|
||||
{
|
||||
enum: int
|
||||
{
|
||||
SOL_SOCKET = 1,
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Different values on other platforms.
|
||||
static assert(0);
|
||||
}
|
||||
|
||||
|
||||
enum: int
|
||||
{
|
||||
SO_DEBUG = 1,
|
||||
SO_BROADCAST = 6,
|
||||
SO_REUSEADDR = 2,
|
||||
SO_LINGER = 13,
|
||||
SO_DONTLINGER = ~SO_LINGER,
|
||||
SO_OOBINLINE = 10,
|
||||
SO_SNDBUF = 7,
|
||||
SO_RCVBUF = 8,
|
||||
SO_ACCEPTCONN = 30,
|
||||
SO_DONTROUTE = 5,
|
||||
SO_TYPE = 3,
|
||||
|
||||
TCP_NODELAY = 1,
|
||||
|
||||
IP_MULTICAST_LOOP = 34,
|
||||
IP_ADD_MEMBERSHIP = 35,
|
||||
IP_DROP_MEMBERSHIP = 36,
|
||||
|
||||
// ...
|
||||
|
||||
IPV6_ADDRFORM = 1,
|
||||
IPV6_PKTINFO = 2,
|
||||
IPV6_HOPOPTS = 3,
|
||||
IPV6_DSTOPTS = 4,
|
||||
IPV6_RTHDR = 5,
|
||||
IPV6_PKTOPTIONS = 6,
|
||||
IPV6_CHECKSUM = 7,
|
||||
IPV6_HOPLIMIT = 8,
|
||||
IPV6_NEXTHOP = 9,
|
||||
IPV6_AUTHHDR = 10,
|
||||
IPV6_UNICAST_HOPS = 16,
|
||||
IPV6_MULTICAST_IF = 17,
|
||||
IPV6_MULTICAST_HOPS = 18,
|
||||
IPV6_MULTICAST_LOOP = 19,
|
||||
IPV6_JOIN_GROUP = 20,
|
||||
IPV6_LEAVE_GROUP = 21,
|
||||
IPV6_ROUTER_ALERT = 22,
|
||||
IPV6_MTU_DISCOVER = 23,
|
||||
IPV6_MTU = 24,
|
||||
IPV6_RECVERR = 25,
|
||||
IPV6_V6ONLY = 26,
|
||||
IPV6_JOIN_ANYCAST = 27,
|
||||
IPV6_LEAVE_ANYCAST = 28,
|
||||
IPV6_IPSEC_POLICY = 34,
|
||||
IPV6_XFRM_POLICY = 35,
|
||||
}
|
||||
|
||||
|
||||
struct linger
|
||||
{
|
||||
int32_t l_onoff;
|
||||
int32_t l_linger;
|
||||
}
|
||||
|
||||
|
||||
struct protoent
|
||||
{
|
||||
char* p_name;
|
||||
char** p_aliases;
|
||||
int32_t p_proto;
|
||||
}
|
||||
|
||||
|
||||
struct servent
|
||||
{
|
||||
char* s_name;
|
||||
char** s_aliases;
|
||||
int32_t s_port;
|
||||
char* s_proto;
|
||||
}
|
||||
|
||||
|
||||
version(BigEndian)
|
||||
{
|
||||
uint16_t htons(uint16_t x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
uint32_t htonl(uint32_t x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
}
|
||||
else version(LittleEndian)
|
||||
{
|
||||
private import std.intrinsic;
|
||||
|
||||
|
||||
uint16_t htons(uint16_t x)
|
||||
{
|
||||
return cast(uint16_t)((x >> 8) | (x << 8));
|
||||
}
|
||||
|
||||
|
||||
uint32_t htonl(uint32_t x)
|
||||
{
|
||||
return bswap(x);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
static assert(0);
|
||||
}
|
||||
|
||||
|
||||
uint16_t ntohs(uint16_t x)
|
||||
{
|
||||
return htons(x);
|
||||
}
|
||||
|
||||
|
||||
uint32_t ntohl(uint32_t x)
|
||||
{
|
||||
return htonl(x);
|
||||
}
|
||||
|
||||
|
||||
enum: int
|
||||
{
|
||||
SOCK_STREAM = 1,
|
||||
SOCK_DGRAM = 2,
|
||||
SOCK_RAW = 3,
|
||||
SOCK_RDM = 4,
|
||||
SOCK_SEQPACKET = 5,
|
||||
}
|
||||
|
||||
|
||||
enum: int
|
||||
{
|
||||
IPPROTO_IP = 0,
|
||||
IPPROTO_ICMP = 1,
|
||||
IPPROTO_IGMP = 2,
|
||||
IPPROTO_GGP = 3,
|
||||
IPPROTO_TCP = 6,
|
||||
IPPROTO_PUP = 12,
|
||||
IPPROTO_UDP = 17,
|
||||
IPPROTO_IDP = 22,
|
||||
IPPROTO_IPV6 = 41,
|
||||
IPPROTO_ND = 77,
|
||||
IPPROTO_RAW = 255,
|
||||
|
||||
IPPROTO_MAX = 256,
|
||||
}
|
||||
|
||||
|
||||
enum: int
|
||||
{
|
||||
MSG_OOB = 0x1,
|
||||
MSG_PEEK = 0x2,
|
||||
MSG_DONTROUTE = 0x4,
|
||||
}
|
||||
|
||||
|
||||
enum: int
|
||||
{
|
||||
SD_RECEIVE = 0,
|
||||
SD_SEND = 1,
|
||||
SD_BOTH = 2,
|
||||
}
|
||||
|
||||
|
||||
enum: uint
|
||||
{
|
||||
INADDR_ANY = 0,
|
||||
INADDR_LOOPBACK = 0x7F000001,
|
||||
INADDR_BROADCAST = 0xFFFFFFFF,
|
||||
INADDR_NONE = 0xFFFFFFFF,
|
||||
ADDR_ANY = INADDR_ANY,
|
||||
}
|
||||
|
||||
|
||||
enum: int
|
||||
{
|
||||
AI_PASSIVE = 0x1,
|
||||
AI_CANONNAME = 0x2,
|
||||
AI_NUMERICHOST = 0x4,
|
||||
}
|
||||
|
||||
|
||||
union in_addr
|
||||
{
|
||||
private union _S_un_t
|
||||
{
|
||||
private struct _S_un_b_t
|
||||
{
|
||||
uint8_t s_b1, s_b2, s_b3, s_b4;
|
||||
}
|
||||
_S_un_b_t S_un_b;
|
||||
|
||||
private struct _S_un_w_t
|
||||
{
|
||||
uint16_t s_w1, s_w2;
|
||||
}
|
||||
_S_un_w_t S_un_w;
|
||||
|
||||
uint32_t S_addr;
|
||||
}
|
||||
_S_un_t S_un;
|
||||
|
||||
uint32_t s_addr;
|
||||
|
||||
struct
|
||||
{
|
||||
uint8_t s_net, s_host;
|
||||
|
||||
union
|
||||
{
|
||||
uint16_t s_imp;
|
||||
|
||||
struct
|
||||
{
|
||||
uint8_t s_lh, s_impno;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
union in6_addr
|
||||
{
|
||||
private union _in6_u_t
|
||||
{
|
||||
uint8_t[16] u6_addr8;
|
||||
uint16_t[8] u6_addr16;
|
||||
uint32_t[4] u6_addr32;
|
||||
}
|
||||
_in6_u_t in6_u;
|
||||
|
||||
uint8_t[16] s6_addr8;
|
||||
uint16_t[8] s6_addr16;
|
||||
uint32_t[4] s6_addr32;
|
||||
}
|
||||
|
||||
|
||||
const in6_addr IN6ADDR_ANY = { s6_addr8: [0] };
|
||||
const in6_addr IN6ADDR_LOOPBACK = { s6_addr8: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] };
|
||||
//alias IN6ADDR_ANY IN6ADDR_ANY_INIT;
|
||||
//alias IN6ADDR_LOOPBACK IN6ADDR_LOOPBACK_INIT;
|
||||
|
||||
const uint INET_ADDRSTRLEN = 16;
|
||||
const uint INET6_ADDRSTRLEN = 46;
|
||||
|
||||
|
||||
struct sockaddr
|
||||
{
|
||||
int16_t sa_family;
|
||||
ubyte[14] sa_data;
|
||||
}
|
||||
|
||||
|
||||
struct sockaddr_in
|
||||
{
|
||||
int16_t sin_family = AF_INET;
|
||||
uint16_t sin_port;
|
||||
in_addr sin_addr;
|
||||
ubyte[8] sin_zero;
|
||||
}
|
||||
|
||||
|
||||
struct sockaddr_in6
|
||||
{
|
||||
int16_t sin6_family = AF_INET6;
|
||||
uint16_t sin6_port;
|
||||
uint32_t sin6_flowinfo;
|
||||
in6_addr sin6_addr;
|
||||
uint32_t sin6_scope_id;
|
||||
}
|
||||
|
||||
|
||||
struct addrinfo
|
||||
{
|
||||
int32_t ai_flags;
|
||||
int32_t ai_family;
|
||||
int32_t ai_socktype;
|
||||
int32_t ai_protocol;
|
||||
size_t ai_addrlen;
|
||||
sockaddr* ai_addr;
|
||||
char* ai_canonname;
|
||||
addrinfo* ai_next;
|
||||
}
|
||||
|
||||
|
||||
struct hostent
|
||||
{
|
||||
char* h_name;
|
||||
char** h_aliases;
|
||||
int32_t h_addrtype;
|
||||
int32_t h_length;
|
||||
char** h_addr_list;
|
||||
|
||||
|
||||
char* h_addr()
|
||||
{
|
||||
return h_addr_list[0];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user