转载地址:http://baike.baidu.com/link?url=nEyMMFYevs4yoHgQUs2bcfd5WApHUKx0b1ervi7ulR09YhtqC4txmvL1Ce3FS8xTKtWQuvmEBHC9xezMGpvGHa

unistd.h 是 C 和 C++ 程序设计语言中提供对 POSIX 操作系统 API 的访问功能的头文件的名称。该头文件由 POSIX.1 标准(单一UNIX规范的基础)提出,故所有遵循该标准的操作系统和编译器均应提供该头文件(如 Unix 的所有官方版本,包括 Mac OS XLinux 等)。
对于类 Unix 系统,unistd.h 中所定义的接口通常都是大量针对系统调用的封装(英语:wrapper functions),如 fork、pipe 以及各种 I/O 原语(read、write、close 等等)。
类似于 Cygwin 和 MinGW 的 Unix 兼容层也提供相应版本的 unistd.h。

unistd.h 源码

  1. #ifndef _UNISTD_H
  2. #define _UNISTD_H
  3. #include <features.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #include <_ansi.h>
  8. #include <sys/types.h>
  9. #include <sys/_types.h>
  10. #define __need_size_t
  11. #define __need_ptrdiff_t
  12. #include <stddef.h>
  13. extern char **environ;
  14. void    _EXFUN(_exit, (int __status ) _ATTRIBUTE ((noreturn)));
  15. int    _EXFUN(access,(const char *__path, int __amode ));
  16. unsigned  _EXFUN(alarm, (unsigned __secs ));
  17. int     _EXFUN(chdir, (const char *__path ));
  18. int     _EXFUN(chmod, (const char *__path, mode_t __mode ));
  19. int     _EXFUN(chown, (const char *__path, uid_t __owner, gid_t __group ));
  20. int     _EXFUN(chroot, (const char *__path ));
  21. int     _EXFUN(close, (int __fildes ));
  22. char    _EXFUN(*ctermid, (char *__s ));
  23. char    _EXFUN(*cuserid, (char *__s ));
  24. int     _EXFUN(dup, (int __fildes ));
  25. int     _EXFUN(dup2, (int __fildes, int __fildes2 ));
  26. int     _EXFUN(execl, (const char *__path, const char *, ... ));
  27. int     _EXFUN(execle, (const char *__path, const char *, ... ));
  28. int     _EXFUN(execlp, (const char *__file, const char *, ... ));
  29. int     _EXFUN(execv, (const char *__path, char * const __argv[] ));
  30. int     _EXFUN(execve, (const char *__path, char * const __argv[], char * const __envp[] ));
  31. int     _EXFUN(execvp, (const char *__file, char * const __argv[] ));
  32. int     _EXFUN(fchdir, (int __fildes));
  33. int     _EXFUN(fchmod, (int __fildes, mode_t __mode ));
  34. int     _EXFUN(fchown, (int __fildes, uid_t __owner, gid_t __group ));
  35. pid_t   _EXFUN(fork, (void ));
  36. long    _EXFUN(fpathconf, (int __fd, int __name ));
  37. int     _EXFUN(fsync, (int __fd));
  38. int     _EXFUN(ftruncate, (int __fd, off_t __length));
  39. char    _EXFUN(*getcwd, (char *__buf, size_t __size ));
  40. int    _EXFUN(getdomainname ,(char *__name, size_t __len));
  41. gid_t   _EXFUN(getegid, (void ));
  42. uid_t   _EXFUN(geteuid, (void ));
  43. gid_t   _EXFUN(getgid, (void ));
  44. int     _EXFUN(getgroups, (int __gidsetsize, gid_t __grouplist[] ));
  45. int     _EXFUN(__gethostname, (char *__name, size_t __len));
  46. char    _EXFUN(*getlogin, (void ));
  47. #if defined(_POSIX_THREAD_SAFE_FUNCTIONS)
  48. int _EXFUN(getlogin_r, (char *name, size_t namesize) );
  49. #endif
  50. char     _EXFUN(*getpass, (__const char *__prompt));
  51. int  _EXFUN(getpagesize, (void));
  52. pid_t   _EXFUN(getpgid, (pid_t));
  53. pid_t   _EXFUN(getpgrp, (void ));
  54. pid_t   _EXFUN(getpid, (void ));
  55. pid_t   _EXFUN(getppid, (void ));
  56. uid_t   _EXFUN(getuid, (void ));
  57. char *    _EXFUN(getusershell, (void));
  58. char    _EXFUN(*getwd, (char *__buf ));
  59. int     _EXFUN(isatty, (int __fildes ));
  60. int     _EXFUN(lchown, (const char *__path, uid_t __owner, gid_t __group ));
  61. int     _EXFUN(link, (const char *__path1, const char *__path2 ));
  62. int    _EXFUN(nice, (int __nice_value ));
  63. off_t   _EXFUN(lseek, (int __fildes, off_t __offset, int __whence ));
  64. long    _EXFUN(pathconf, (const char *__path, int __name ));
  65. int     _EXFUN(pause, (void ));
  66. int     _EXFUN(pipe, (int __fildes[2] ));
  67. ssize_t _EXFUN(pread, (int __fd, void *__buf, size_t __nbytes, off_t __offset));
  68. ssize_t _EXFUN(pwrite, (int __fd, const void *__buf, size_t __nbytes, off_t __offset));
  69. _READ_WRITE_RETURN_TYPE _EXFUN(read, (int __fd, void *__buf, size_t __nbyte ));
  70. int     _EXFUN(readlink, (const char *path, char *buf, size_t bufsiz));
  71. int     _EXFUN(rmdir, (const char *__path ));
  72. void *  _EXFUN(sbrk,  (ptrdiff_t __incr));
  73. int     _EXFUN(setegid, (gid_t __gid ));
  74. int     _EXFUN(seteuid, (uid_t __uid ));
  75. int     _EXFUN(setgid, (gid_t __gid ));
  76. int     _EXFUN(setpgid, (pid_t __pid, pid_t __pgid ));
  77. int     _EXFUN(setpgrp, (void ));
  78. pid_t   _EXFUN(setsid, (void ));
  79. int     _EXFUN(setuid, (uid_t __uid ));
  80. unsigned _EXFUN(sleep, (unsigned int __seconds ));
  81. void    _EXFUN(swab, (const void *, void *, ssize_t));
  82. int     _EXFUN(symlink, (const char *oldpath, const char *newpath));
  83. long    _EXFUN(sysconf, (int __name ));
  84. pid_t   _EXFUN(tcgetpgrp, (int __fildes ));
  85. int     _EXFUN(tcsetpgrp, (int __fildes, pid_t __pgrp_id ));
  86. int     _EXFUN(truncate, (const char *, off_t __length));
  87. char *  _EXFUN(ttyname, (int __fildes ));
  88. int     _EXFUN(ttyname_r, (int __fildes, char *__buf, size_t __len));
  89. int     _EXFUN(unlink, (const char *__path ));
  90. int     _EXFUN(usleep, (__useconds_t __useconds));
  91. int     _EXFUN(vhangup, (void ));
  92. _READ_WRITE_RETURN_TYPE _EXFUN(write, (int __fd, const void *__buf, size_t __nbyte ));
  93. extern char *optarg;            /** getopt(3) external variables */
  94. extern int optind, opterr, optopt;
  95. int     getopt(int, char * const [], const char *);
  96. extern int optreset;            /** getopt(3) external variable */
  97. #ifndef        _POSIX_SOURCE
  98. pid_t   _EXFUN(vfork, (void ));
  99. extern char *suboptarg;            /** getsubopt(3) external variable */
  100. int     getsubopt(char **, char * const *, char **);
  101. #endif /** _POSIX_SOURCE */
  102. /** Provide prototypes for most of the _<systemcall> names that are
  103. provided in newlib for some compilers.  */
  104. int     _EXFUN(_close, (int __fildes ));
  105. pid_t   _EXFUN(_fork, (void ));
  106. pid_t   _EXFUN(_getpid, (void ));
  107. int     _EXFUN(_link, (const char *__path1, const char *__path2 ));
  108. off_t   _EXFUN(_lseek, (int __fildes, off_t __offset, int __whence ));
  109. _READ_WRITE_RETURN_TYPE _EXFUN(_read, (int __fd, void *__buf, size_t __nbyte ));
  110. void *  _EXFUN(_sbrk,  (size_t __incr));
  111. int     _EXFUN(_unlink, (const char *__path ));
  112. _READ_WRITE_RETURN_TYPE _EXFUN(_write, (int __fd, const void *__buf, size_t __nbyte ));
  113. int     _EXFUN(_execve, (const char *__path, char * const __argv[], char * const __envp[] ));
  114. #define    F_OK    0
  115. #define    R_OK    4
  116. #define    W_OK    2
  117. #define    X_OK    1
  118. # define    SEEK_SET    0
  119. # define    SEEK_CUR    1
  120. # define    SEEK_END    2
  121. #include <sys/features.h>
  122. #define STDIN_FILENO    0       /** standard input file descriptor */
  123. #define STDOUT_FILENO   1       /** standard output file descriptor */
  124. #define STDERR_FILENO   2       /** standard error file descriptor */
  125. #include <bits/environments.h>
  126. #include <bits/confname.h>
  127. # define        MAXPATHLEN      1024
  128. #ifdef __cplusplus
  129. }
  130. #endif
  131. #endif /** _SYS_UNISTD_H */

unistd.h文件的更多相关文章

  1. Python 安装zbar-py时出现 无法打开包括文件: “unistd.h” no such file or directory

    问题 途中使用的命令是cl.exe,在执行命令的时候找不到对应的unistd.h文件. unistd.h是Unix系统的文件,因此,十有八九,使用的是Windows系统.下面的代码可以修复,但是如果修 ...

  2. vc编程时说“Cannot open include file: 'unistd.h': No such file or directory”

    本文专自http://blog.csdn.net/mangobar/article/details/6314700 unistd.h是unix standard header之意,因此,Linux下开 ...

  3. #include<unistd.h>头文件的理解

    1.百度百科定义 unistd.h 是 C 和 C++ 程序设计语言中提供对 POSIX 操作系统 API 的访问功能的头文件的名称.该头文件由 POSIX.1 标准(单一UNIX规范的基础)提出,故 ...

  4. sys/types.h fcntl.h unistd.h sys/stat.h

    sys/types.h 是Unix/Linux系统的基本系统数据类型的头文件,含有size_t,time_t,pid_t等类型. 在应用程序源文件中包含 <sys/types.h> 以访问 ...

  5. #include<unistd.h>存在linux中,含有系统服务的函数

    #include<unistd.h> linux标准库#include <unistd.h>与windows的#include <windows.h>(C语言开发) ...

  6. unistd.h

    unistd.h是unix std的意思,是POSIX标准定义的unix类系统定义符号常量的头文件, 包含了许多UNIX系统服务的函数原型 unistd.h在unix中类似于window中的windo ...

  7. VS 2015 报错 " 'unistd.h': No such file or directory" 的解决办法

    使用 Visual Studio 2015 进行程序开发工作时,如果编译的是来自于Linux平台的源文件,该源文件可能会包含头文件 uninstd.h,这样会产生报错信息: "fatal e ...

  8. #include <unistd.h> 的作用

    原文:http://blog.csdn.net/ybsun2010/article/details/24832113 由字面意思,unistd.h是unix std的意思,是POSIX标准定义的uni ...

  9. <unistd.h>的close(0)导致std::cout被关闭

    代码如下:其中ZJ::open_max返回系统允许的打开的文件的最大个数 #include "util.h" #include <unistd.h> // int cl ...

随机推荐

  1. js中的promise详解

    一 概述   Promise是异步编程的一种解决方案,可以替代传统的解决方案--回调函数和事件.ES6统一了用法,并原生提供了Promise对象.作为对象,Promise有一下两个特点: (1)对象的 ...

  2. 使用scp命令,远程上传下载文件/文件夹

    1.从服务器下载文件 scp username@servername:/path/filename /local/path例如: scp ubuntu@117.50.20.56:/ygf/data/d ...

  3. Scala 中使用 akka system 的 scheduler 的例子

    这是在scala控制台直接执行的例子.   import akka.actor._ import scala.concurrent.duration._ import scala.concurrent ...

  4. java service wrapper将java程序包装成系统服务(一)

    一. 概述 使用java语言开发应用程序,在windows平台下,一般存在3种应用形式: 1. web应用.web应用多数打成war包在web容器(如tomcat,jetty等)中运行. 2. 桌面应 ...

  5. linux 创建软链接和硬链接

    Linux 系统中有软链接和硬链接两种特殊的“文件”. 软链接可以看作是Windows中的快捷方式,可以让你快速链接到目标档案或目录. 硬链接则透过文件系统的inode来产生新档名,而不是产生新档案. ...

  6. 【Qt开发】常用控件--QLineEdit

    QLineEdit是单行文本编辑控件.比如用户名,密码等输入框可以使用该控件. 所属头文件<QLineEdit> 常用方法 1.void setText(const QString &am ...

  7. WPF Binding(四种模式)

    在使用Binding类的时候有4中绑定模式可以选择 BindingMode TwoWay 导致对源属性或目标属性的更改可自动更新对方.此绑定类型适用于可编辑窗体或其他完全交互式 UI 方案. OneW ...

  8. hibernate 中addScalar的用法与作用

    作用: 1.提高性能 2.指定要返回哪几个字段,为指定的不返回(主要用于select *查询全部) 3.也可指定返回字段的具体类型 常用于自定义本地sql中 如: StringBuffer sql=n ...

  9. MYSQL数据库的参数文件

    参数文件:告诉MySQL实例启动时在哪里可以找到数据库文件,并且指定某些初始化参数,这些参数定义了某种内存结构的大小等设置,还会介绍各种参数的类型. 参数文件 当MySQL实例启动时,MySQL会先去 ...

  10. ORA-04091: table xxx is mutating, trigger/function may not see it

    Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Connected as tbcs SQL> SQL ...