PageRenderTime 52ms CodeModel.GetById 16ms app.highlight 32ms RepoModel.GetById 1ms app.codeStats 0ms

/src/core/sys/posix/unistd.d

http://github.com/AlexeyProkhin/druntime
D | 622 lines | 517 code | 46 blank | 59 comment | 11 complexity | 733bd0bdb66574feb5192cddfe0a9ff5 MD5 | raw file
  1/**
  2 * D header file for POSIX.
  3 *
  4 * Copyright: Copyright Sean Kelly 2005 - 2009.
  5 * License:   <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
  6 * Authors:   Sean Kelly
  7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
  8 */
  9
 10/*          Copyright Sean Kelly 2005 - 2009.
 11 * Distributed under the Boost Software License, Version 1.0.
 12 *    (See accompanying file LICENSE or copy at
 13 *          http://www.boost.org/LICENSE_1_0.txt)
 14 */
 15module core.sys.posix.unistd;
 16
 17private import core.sys.posix.config;
 18private import core.stdc.stddef;
 19public import core.sys.posix.inttypes;  // for intptr_t
 20public import core.sys.posix.sys.types; // for size_t, ssize_t, uid_t, gid_t, off_t, pid_t, useconds_t
 21
 22version (Posix):
 23extern (C):
 24
 25version( Posix )
 26{
 27    enum STDIN_FILENO  = 0;
 28    enum STDOUT_FILENO = 1;
 29    enum STDERR_FILENO = 2;
 30
 31    __gshared char*   optarg;
 32    __gshared int     optind;
 33    __gshared int     opterr;
 34    __gshared int     optopt;
 35
 36    int     access(in char*, int);
 37    uint    alarm(uint);
 38    int     chdir(in char*);
 39    int     chown(in char*, uid_t, gid_t);
 40    int     close(int);
 41    size_t  confstr(int, char*, size_t);
 42    int     dup(int);
 43    int     dup2(int, int);
 44    int     execl(in char*, in char*, ...);
 45    int     execle(in char*, in char*, ...);
 46    int     execlp(in char*, in char*, ...);
 47    int     execv(in char*, in char**);
 48    int     execve(in char*, in char**, in char**);
 49    int     execvp(in char*, in char**);
 50    void    _exit(int);
 51    int     fchown(int, uid_t, gid_t);
 52    pid_t   fork();
 53    c_long  fpathconf(int, int);
 54    //int     ftruncate(int, off_t);
 55    char*   getcwd(char*, size_t);
 56    gid_t   getegid();
 57    uid_t   geteuid();
 58    gid_t   getgid();
 59    int     getgroups(int, gid_t *);
 60    int     gethostname(char*, size_t);
 61    char*   getlogin();
 62    int     getlogin_r(char*, size_t);
 63    int     getopt(int, in char**, in char*);
 64    pid_t   getpgrp();
 65    pid_t   getpid();
 66    pid_t   getppid();
 67    uid_t   getuid();
 68    int     isatty(int);
 69    int     link(in char*, in char*);
 70    //off_t   lseek(int, off_t, int);
 71    c_long  pathconf(in char*, int);
 72    int     pause();
 73    int     pipe(ref int[2]);
 74    ssize_t read(int, void*, size_t);
 75    ssize_t readlink(in char*, char*, size_t);
 76    int     rmdir(in char*);
 77    int     setegid(gid_t);
 78    int     seteuid(uid_t);
 79    int     setgid(gid_t);
 80    int     setpgid(pid_t, pid_t);
 81    pid_t   setsid();
 82    int     setuid(uid_t);
 83    uint    sleep(uint);
 84    int     symlink(in char*, in char*);
 85    c_long  sysconf(int);
 86    pid_t   tcgetpgrp(int);
 87    int     tcsetpgrp(int, pid_t);
 88    char*   ttyname(int);
 89    int     ttyname_r(int, char*, size_t);
 90    int     unlink(in char*);
 91    ssize_t write(int, in void*, size_t);
 92}
 93
 94version( linux )
 95{
 96  static if( __USE_FILE_OFFSET64 )
 97  {
 98    off_t lseek64(int, off_t, int);
 99    alias lseek64 lseek;
100  }
101  else
102  {
103    off_t lseek(int, off_t, int);
104  }
105  static if( __USE_LARGEFILE64 )
106  {
107    int   ftruncate64(int, off_t);
108    alias ftruncate64 ftruncate;
109  }
110  else
111  {
112    int   ftruncate(int, off_t);
113  }
114}
115else version( FreeBSD )
116{
117    off_t lseek(int, off_t, int);
118    int   ftruncate(int, off_t);
119}
120else version( Posix )
121{
122    off_t lseek(int, off_t, int);
123    int   ftruncate(int, off_t);
124}
125
126version( linux )
127{
128    enum F_OK       = 0;
129    enum R_OK       = 4;
130    enum W_OK       = 2;
131    enum X_OK       = 1;
132
133    enum F_ULOCK    = 0;
134    enum F_LOCK     = 1;
135    enum F_TLOCK    = 2;
136    enum F_TEST     = 3;
137
138    enum
139    {
140        _CS_PATH,
141
142        _CS_V6_WIDTH_RESTRICTED_ENVS,
143
144        _CS_GNU_LIBC_VERSION,
145        _CS_GNU_LIBPTHREAD_VERSION,
146
147        _CS_LFS_CFLAGS = 1000,
148        _CS_LFS_LDFLAGS,
149        _CS_LFS_LIBS,
150        _CS_LFS_LINTFLAGS,
151        _CS_LFS64_CFLAGS,
152        _CS_LFS64_LDFLAGS,
153        _CS_LFS64_LIBS,
154        _CS_LFS64_LINTFLAGS,
155
156        _CS_XBS5_ILP32_OFF32_CFLAGS = 1100,
157        _CS_XBS5_ILP32_OFF32_LDFLAGS,
158        _CS_XBS5_ILP32_OFF32_LIBS,
159        _CS_XBS5_ILP32_OFF32_LINTFLAGS,
160        _CS_XBS5_ILP32_OFFBIG_CFLAGS,
161        _CS_XBS5_ILP32_OFFBIG_LDFLAGS,
162        _CS_XBS5_ILP32_OFFBIG_LIBS,
163        _CS_XBS5_ILP32_OFFBIG_LINTFLAGS,
164        _CS_XBS5_LP64_OFF64_CFLAGS,
165        _CS_XBS5_LP64_OFF64_LDFLAGS,
166        _CS_XBS5_LP64_OFF64_LIBS,
167        _CS_XBS5_LP64_OFF64_LINTFLAGS,
168        _CS_XBS5_LPBIG_OFFBIG_CFLAGS,
169        _CS_XBS5_LPBIG_OFFBIG_LDFLAGS,
170        _CS_XBS5_LPBIG_OFFBIG_LIBS,
171        _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS,
172
173        _CS_POSIX_V6_ILP32_OFF32_CFLAGS,
174        _CS_POSIX_V6_ILP32_OFF32_LDFLAGS,
175        _CS_POSIX_V6_ILP32_OFF32_LIBS,
176        _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS,
177        _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS,
178        _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS,
179        _CS_POSIX_V6_ILP32_OFFBIG_LIBS,
180        _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS,
181        _CS_POSIX_V6_LP64_OFF64_CFLAGS,
182        _CS_POSIX_V6_LP64_OFF64_LDFLAGS,
183        _CS_POSIX_V6_LP64_OFF64_LIBS,
184        _CS_POSIX_V6_LP64_OFF64_LINTFLAGS,
185        _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS,
186        _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS,
187        _CS_POSIX_V6_LPBIG_OFFBIG_LIBS,
188        _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS
189    }
190
191    enum
192    {
193        _PC_LINK_MAX,
194        _PC_MAX_CANON,
195        _PC_MAX_INPUT,
196        _PC_NAME_MAX,
197        _PC_PATH_MAX,
198        _PC_PIPE_BUF,
199        _PC_CHOWN_RESTRICTED,
200        _PC_NO_TRUNC,
201        _PC_VDISABLE,
202        _PC_SYNC_IO,
203        _PC_ASYNC_IO,
204        _PC_PRIO_IO,
205        _PC_SOCK_MAXBUF,
206        _PC_FILESIZEBITS,
207        _PC_REC_INCR_XFER_SIZE,
208        _PC_REC_MAX_XFER_SIZE,
209        _PC_REC_MIN_XFER_SIZE,
210        _PC_REC_XFER_ALIGN,
211        _PC_ALLOC_SIZE_MIN,
212        _PC_SYMLINK_MAX,
213        _PC_2_SYMLINKS
214    }
215
216    enum
217    {
218        _SC_ARG_MAX,
219        _SC_CHILD_MAX,
220        _SC_CLK_TCK,
221        _SC_NGROUPS_MAX,
222        _SC_OPEN_MAX,
223        _SC_STREAM_MAX,
224        _SC_TZNAME_MAX,
225        _SC_JOB_CONTROL,
226        _SC_SAVED_IDS,
227        _SC_REALTIME_SIGNALS,
228        _SC_PRIORITY_SCHEDULING,
229        _SC_TIMERS,
230        _SC_ASYNCHRONOUS_IO,
231        _SC_PRIORITIZED_IO,
232        _SC_SYNCHRONIZED_IO,
233        _SC_FSYNC,
234        _SC_MAPPED_FILES,
235        _SC_MEMLOCK,
236        _SC_MEMLOCK_RANGE,
237        _SC_MEMORY_PROTECTION,
238        _SC_MESSAGE_PASSING,
239        _SC_SEMAPHORES,
240        _SC_SHARED_MEMORY_OBJECTS,
241        _SC_AIO_LISTIO_MAX,
242        _SC_AIO_MAX,
243        _SC_AIO_PRIO_DELTA_MAX,
244        _SC_DELAYTIMER_MAX,
245        _SC_MQ_OPEN_MAX,
246        _SC_MQ_PRIO_MAX,
247        _SC_VERSION,
248        _SC_PAGESIZE,
249        _SC_PAGE_SIZE = _SC_PAGESIZE,
250        _SC_RTSIG_MAX,
251        _SC_SEM_NSEMS_MAX,
252        _SC_SEM_VALUE_MAX,
253        _SC_SIGQUEUE_MAX,
254        _SC_TIMER_MAX,
255
256        _SC_BC_BASE_MAX,
257        _SC_BC_DIM_MAX,
258        _SC_BC_SCALE_MAX,
259        _SC_BC_STRING_MAX,
260        _SC_COLL_WEIGHTS_MAX,
261        _SC_EQUIV_CLASS_MAX,
262        _SC_EXPR_NEST_MAX,
263        _SC_LINE_MAX,
264        _SC_RE_DUP_MAX,
265        _SC_CHARCLASS_NAME_MAX,
266
267        _SC_2_VERSION,
268        _SC_2_C_BIND,
269        _SC_2_C_DEV,
270        _SC_2_FORT_DEV,
271        _SC_2_FORT_RUN,
272        _SC_2_SW_DEV,
273        _SC_2_LOCALEDEF,
274
275        _SC_PII,
276        _SC_PII_XTI,
277        _SC_PII_SOCKET,
278        _SC_PII_INTERNET,
279        _SC_PII_OSI,
280        _SC_POLL,
281        _SC_SELECT,
282        _SC_UIO_MAXIOV,
283        _SC_IOV_MAX = _SC_UIO_MAXIOV,
284        _SC_PII_INTERNET_STREAM,
285        _SC_PII_INTERNET_DGRAM,
286        _SC_PII_OSI_COTS,
287        _SC_PII_OSI_CLTS,
288        _SC_PII_OSI_M,
289        _SC_T_IOV_MAX,
290
291        _SC_THREADS,
292        _SC_THREAD_SAFE_FUNCTIONS,
293        _SC_GETGR_R_SIZE_MAX,
294        _SC_GETPW_R_SIZE_MAX,
295        _SC_LOGIN_NAME_MAX,
296        _SC_TTY_NAME_MAX,
297        _SC_THREAD_DESTRUCTOR_ITERATIONS,
298        _SC_THREAD_KEYS_MAX,
299        _SC_THREAD_STACK_MIN,
300        _SC_THREAD_THREADS_MAX,
301        _SC_THREAD_ATTR_STACKADDR,
302        _SC_THREAD_ATTR_STACKSIZE,
303        _SC_THREAD_PRIORITY_SCHEDULING,
304        _SC_THREAD_PRIO_INHERIT,
305        _SC_THREAD_PRIO_PROTECT,
306        _SC_THREAD_PROCESS_SHARED,
307
308        _SC_NPROCESSORS_CONF,
309        _SC_NPROCESSORS_ONLN,
310        _SC_PHYS_PAGES,
311        _SC_AVPHYS_PAGES,
312        _SC_ATEXIT_MAX,
313        _SC_PASS_MAX,
314
315        _SC_XOPEN_VERSION,
316        _SC_XOPEN_XCU_VERSION,
317        _SC_XOPEN_UNIX,
318        _SC_XOPEN_CRYPT,
319        _SC_XOPEN_ENH_I18N,
320        _SC_XOPEN_SHM,
321
322        _SC_2_CHAR_TERM,
323        _SC_2_C_VERSION,
324        _SC_2_UPE,
325
326        _SC_XOPEN_XPG2,
327        _SC_XOPEN_XPG3,
328        _SC_XOPEN_XPG4,
329
330        _SC_CHAR_BIT,
331        _SC_CHAR_MAX,
332        _SC_CHAR_MIN,
333        _SC_INT_MAX,
334        _SC_INT_MIN,
335        _SC_LONG_BIT,
336        _SC_WORD_BIT,
337        _SC_MB_LEN_MAX,
338        _SC_NZERO,
339        _SC_SSIZE_MAX,
340        _SC_SCHAR_MAX,
341        _SC_SCHAR_MIN,
342        _SC_SHRT_MAX,
343        _SC_SHRT_MIN,
344        _SC_UCHAR_MAX,
345        _SC_UINT_MAX,
346        _SC_ULONG_MAX,
347        _SC_USHRT_MAX,
348
349        _SC_NL_ARGMAX,
350        _SC_NL_LANGMAX,
351        _SC_NL_MSGMAX,
352        _SC_NL_NMAX,
353        _SC_NL_SETMAX,
354        _SC_NL_TEXTMAX,
355
356        _SC_XBS5_ILP32_OFF32,
357        _SC_XBS5_ILP32_OFFBIG,
358        _SC_XBS5_LP64_OFF64,
359        _SC_XBS5_LPBIG_OFFBIG,
360
361        _SC_XOPEN_LEGACY,
362        _SC_XOPEN_REALTIME,
363        _SC_XOPEN_REALTIME_THREADS,
364
365        _SC_ADVISORY_INFO,
366        _SC_BARRIERS,
367        _SC_BASE,
368        _SC_C_LANG_SUPPORT,
369        _SC_C_LANG_SUPPORT_R,
370        _SC_CLOCK_SELECTION,
371        _SC_CPUTIME,
372        _SC_THREAD_CPUTIME,
373        _SC_DEVICE_IO,
374        _SC_DEVICE_SPECIFIC,
375        _SC_DEVICE_SPECIFIC_R,
376        _SC_FD_MGMT,
377        _SC_FIFO,
378        _SC_PIPE,
379        _SC_FILE_ATTRIBUTES,
380        _SC_FILE_LOCKING,
381        _SC_FILE_SYSTEM,
382        _SC_MONOTONIC_CLOCK,
383        _SC_MULTI_PROCESS,
384        _SC_SINGLE_PROCESS,
385        _SC_NETWORKING,
386        _SC_READER_WRITER_LOCKS,
387        _SC_SPIN_LOCKS,
388        _SC_REGEXP,
389        _SC_REGEX_VERSION,
390        _SC_SHELL,
391        _SC_SIGNALS,
392        _SC_SPAWN,
393        _SC_SPORADIC_SERVER,
394        _SC_THREAD_SPORADIC_SERVER,
395        _SC_SYSTEM_DATABASE,
396        _SC_SYSTEM_DATABASE_R,
397        _SC_TIMEOUTS,
398        _SC_TYPED_MEMORY_OBJECTS,
399        _SC_USER_GROUPS,
400        _SC_USER_GROUPS_R,
401        _SC_2_PBS,
402        _SC_2_PBS_ACCOUNTING,
403        _SC_2_PBS_LOCATE,
404        _SC_2_PBS_MESSAGE,
405        _SC_2_PBS_TRACK,
406        _SC_SYMLOOP_MAX,
407        _SC_STREAMS,
408        _SC_2_PBS_CHECKPOINT,
409
410        _SC_V6_ILP32_OFF32,
411        _SC_V6_ILP32_OFFBIG,
412        _SC_V6_LP64_OFF64,
413        _SC_V6_LPBIG_OFFBIG,
414
415        _SC_HOST_NAME_MAX,
416        _SC_TRACE,
417        _SC_TRACE_EVENT_FILTER,
418        _SC_TRACE_INHERIT,
419        _SC_TRACE_LOG,
420
421        _SC_LEVEL1_ICACHE_SIZE,
422        _SC_LEVEL1_ICACHE_ASSOC,
423        _SC_LEVEL1_ICACHE_LINESIZE,
424        _SC_LEVEL1_DCACHE_SIZE,
425        _SC_LEVEL1_DCACHE_ASSOC,
426        _SC_LEVEL1_DCACHE_LINESIZE,
427        _SC_LEVEL2_CACHE_SIZE,
428        _SC_LEVEL2_CACHE_ASSOC,
429        _SC_LEVEL2_CACHE_LINESIZE,
430        _SC_LEVEL3_CACHE_SIZE,
431        _SC_LEVEL3_CACHE_ASSOC,
432        _SC_LEVEL3_CACHE_LINESIZE,
433        _SC_LEVEL4_CACHE_SIZE,
434        _SC_LEVEL4_CACHE_ASSOC,
435        _SC_LEVEL4_CACHE_LINESIZE,
436
437        _SC_IPV6 = _SC_LEVEL1_ICACHE_SIZE + 50,
438        _SC_RAW_SOCKETS
439    }
440}
441else version( OSX )
442{
443    enum F_OK       = 0;
444    enum R_OK       = 4;
445    enum W_OK       = 2;
446    enum X_OK       = 1;
447
448    enum F_ULOCK    = 0;
449    enum F_LOCK     = 1;
450    enum F_TLOCK    = 2;
451    enum F_TEST     = 3;
452}
453else version( FreeBSD )
454{
455    enum F_OK       = 0;
456    enum R_OK       = 0x04;
457    enum W_OK       = 0x02;
458    enum X_OK       = 0x01;
459
460    enum F_ULOCK    = 0;
461    enum F_LOCK     = 1;
462    enum F_TLOCK    = 2;
463    enum F_TEST     = 3;
464}
465
466//
467// File Synchronization (FSC)
468//
469/*
470int fsync(int);
471*/
472
473version( linux )
474{
475    int fsync(int);
476}
477else version( OSX )
478{
479    int fsync(int);
480}
481else version( FreeBSD )
482{
483    int fsync(int);
484}
485
486//
487// Synchronized I/O (SIO)
488//
489/*
490int fdatasync(int);
491*/
492
493version( linux )
494{
495    int fdatasync(int);
496}
497
498//
499// XOpen (XSI)
500//
501/*
502char*      crypt(in char*, in char*);
503char*      ctermid(char*);
504void       encrypt(ref char[64], int);
505int        fchdir(int);
506c_long     gethostid();
507pid_t      getpgid(pid_t);
508pid_t      getsid(pid_t);
509char*      getwd(char*); // LEGACY
510int        lchown(in char*, uid_t, gid_t);
511int        lockf(int, int, off_t);
512int        nice(int);
513ssize_t    pread(int, void*, size_t, off_t);
514ssize_t    pwrite(int, in void*, size_t, off_t);
515pid_t      setpgrp();
516int        setregid(gid_t, gid_t);
517int        setreuid(uid_t, uid_t);
518void       swab(in void*, void*, ssize_t);
519void       sync();
520int        truncate(in char*, off_t);
521useconds_t ualarm(useconds_t, useconds_t);
522int        usleep(useconds_t);
523pid_t      vfork();
524*/
525
526version( linux )
527{
528    char*      crypt(in char*, in char*);
529    char*      ctermid(char*);
530    void       encrypt(ref char[64], int);
531    int        fchdir(int);
532    c_long     gethostid();
533    pid_t      getpgid(pid_t);
534    pid_t      getsid(pid_t);
535    char*      getwd(char*); // LEGACY
536    int        lchown(in char*, uid_t, gid_t);
537    //int        lockf(int, int, off_t);
538    int        nice(int);
539    //ssize_t    pread(int, void*, size_t, off_t);
540    //ssize_t    pwrite(int, in void*, size_t, off_t);
541    pid_t      setpgrp();
542    int        setregid(gid_t, gid_t);
543    int        setreuid(uid_t, uid_t);
544    void       swab(in void*, void*, ssize_t);
545    void       sync();
546    //int        truncate(in char*, off_t);
547    useconds_t ualarm(useconds_t, useconds_t);
548    int        usleep(useconds_t);
549    pid_t      vfork();
550
551  static if( __USE_FILE_OFFSET64 )
552  {
553    int        lockf64(int, int, off_t);
554    alias      lockf64 lockf;
555
556    ssize_t    pread64(int, void*, size_t, off_t);
557    alias      pread64 pread;
558
559    ssize_t    pwrite64(int, in void*, size_t, off_t);
560    alias      pwrite64 pwrite;
561
562    int        truncate64(in char*, off_t);
563    alias      truncate64 truncate;
564  }
565  else
566  {
567    int        lockf(int, int, off_t);
568    ssize_t    pread(int, void*, size_t, off_t);
569    ssize_t    pwrite(int, in void*, size_t, off_t);
570    int        truncate(in char*, off_t);
571  }
572}
573else version( OSX )
574{
575    char*      crypt(in char*, in char*);
576    char*      ctermid(char*);
577    void       encrypt(ref char[64], int);
578    int        fchdir(int);
579    c_long     gethostid();
580    pid_t      getpgid(pid_t);
581    pid_t      getsid(pid_t);
582    char*      getwd(char*); // LEGACY
583    int        lchown(in char*, uid_t, gid_t);
584    int        lockf(int, int, off_t);
585    int        nice(int);
586    ssize_t    pread(int, void*, size_t, off_t);
587    ssize_t    pwrite(int, in void*, size_t, off_t);
588    pid_t      setpgrp();
589    int        setregid(gid_t, gid_t);
590    int        setreuid(uid_t, uid_t);
591    void       swab(in void*, void*, ssize_t);
592    void       sync();
593    int        truncate(in char*, off_t);
594    useconds_t ualarm(useconds_t, useconds_t);
595    int        usleep(useconds_t);
596    pid_t      vfork();
597}
598else version( FreeBSD )
599{
600    char*      crypt(in char*, in char*);
601    //char*      ctermid(char*);
602    void       encrypt(ref char[64], int);
603    int        fchdir(int);
604    c_long     gethostid();
605    int        getpgid(pid_t);
606    int        getsid(pid_t);
607    char*      getwd(char*); // LEGACY
608    int        lchown(in char*, uid_t, gid_t);
609    int        lockf(int, int, off_t);
610    int        nice(int);
611    ssize_t    pread(int, void*, size_t, off_t);
612    ssize_t    pwrite(int, in void*, size_t, off_t);
613    int        setpgrp(pid_t, pid_t);
614    int        setregid(gid_t, gid_t);
615    int        setreuid(uid_t, uid_t);
616    void       swab(in void*, void*, ssize_t);
617    void       sync();
618    int        truncate(in char*, off_t);
619    useconds_t ualarm(useconds_t, useconds_t);
620    int        usleep(useconds_t);
621    pid_t      vfork();
622}