1.百度百科定义

  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 等等)。
 
我的定义:
这是一个头文件,封装了类UNIX系统下的很多固定名称的system_call系统调用。所以,这个函数是依赖于编译器,依赖于操作系统的。

  

2.源码

  可以从源码中,查看它封装了哪些固定名称的操作系统api。

#ifndef _UNISTD_H
#define _UNISTD_H
#include <features.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <_ansi.h>
#include <sys/types.h>
#include <sys/_types.h>
#define __need_size_t
#define __need_ptrdiff_t
#include <stddef.h>
extern char **environ;
void _EXFUN(_exit, (int __status ) _ATTRIBUTE ((noreturn)));
int _EXFUN(access,(const char *__path, int __amode ));
unsigned _EXFUN(alarm, (unsigned __secs ));
int _EXFUN(chdir, (const char *__path ));
int _EXFUN(chmod, (const char *__path, mode_t __mode ));
int _EXFUN(chown, (const char *__path, uid_t __owner, gid_t __group ));
int _EXFUN(chroot, (const char *__path ));
int _EXFUN(close, (int __fildes ));
char _EXFUN(*ctermid, (char *__s ));
char _EXFUN(*cuserid, (char *__s ));
int _EXFUN(dup, (int __fildes ));
int _EXFUN(dup2, (int __fildes, int __fildes2 ));
int _EXFUN(execl, (const char *__path, const char *, ... ));
int _EXFUN(execle, (const char *__path, const char *, ... ));
int _EXFUN(execlp, (const char *__file, const char *, ... ));
int _EXFUN(execv, (const char *__path, char * const __argv[] ));
int _EXFUN(execve, (const char *__path, char * const __argv[], char * const __envp[] ));
int _EXFUN(execvp, (const char *__file, char * const __argv[] ));
int _EXFUN(fchdir, (int __fildes));
int _EXFUN(fchmod, (int __fildes, mode_t __mode ));
int _EXFUN(fchown, (int __fildes, uid_t __owner, gid_t __group ));
pid_t _EXFUN(fork, (void ));
long _EXFUN(fpathconf, (int __fd, int __name ));
int _EXFUN(fsync, (int __fd));
int _EXFUN(ftruncate, (int __fd, off_t __length));
char _EXFUN(*getcwd, (char *__buf, size_t __size ));
int _EXFUN(getdomainname ,(char *__name, size_t __len));
gid_t _EXFUN(getegid, (void ));
uid_t _EXFUN(geteuid, (void ));
gid_t _EXFUN(getgid, (void ));
int _EXFUN(getgroups, (int __gidsetsize, gid_t __grouplist[] ));
int _EXFUN(__gethostname, (char *__name, size_t __len));
char _EXFUN(*getlogin, (void ));
#if defined(_POSIX_THREAD_SAFE_FUNCTIONS)
int _EXFUN(getlogin_r, (char *name, size_t namesize) );
#endif
char _EXFUN(*getpass, (__const char *__prompt));
int _EXFUN(getpagesize, (void));
pid_t _EXFUN(getpgid, (pid_t));
pid_t _EXFUN(getpgrp, (void ));
pid_t _EXFUN(getpid, (void ));
pid_t _EXFUN(getppid, (void ));
uid_t _EXFUN(getuid, (void ));
char * _EXFUN(getusershell, (void));
char _EXFUN(*getwd, (char *__buf ));
int _EXFUN(isatty, (int __fildes ));
int _EXFUN(lchown, (const char *__path, uid_t __owner, gid_t __group ));
int _EXFUN(link, (const char *__path1, const char *__path2 ));
int _EXFUN(nice, (int __nice_value ));
off_t _EXFUN(lseek, (int __fildes, off_t __offset, int __whence ));
long _EXFUN(pathconf, (const char *__path, int __name ));
int _EXFUN(pause, (void ));
int _EXFUN(pipe, (int __fildes[2] ));
ssize_t _EXFUN(pread, (int __fd, void *__buf, size_t __nbytes, off_t __offset));
ssize_t _EXFUN(pwrite, (int __fd, const void *__buf, size_t __nbytes, off_t __offset));
_READ_WRITE_RETURN_TYPE _EXFUN(read, (int __fd, void *__buf, size_t __nbyte ));
int _EXFUN(readlink, (const char *path, char *buf, size_t bufsiz));
int _EXFUN(rmdir, (const char *__path ));
void * _EXFUN(sbrk, (ptrdiff_t __incr));
int _EXFUN(setegid, (gid_t __gid ));
int _EXFUN(seteuid, (uid_t __uid ));
int _EXFUN(setgid, (gid_t __gid ));
int _EXFUN(setpgid, (pid_t __pid, pid_t __pgid ));
int _EXFUN(setpgrp, (void ));
pid_t _EXFUN(setsid, (void ));
int _EXFUN(setuid, (uid_t __uid ));
unsigned _EXFUN(sleep, (unsigned int __seconds ));
void _EXFUN(swab, (const void *, void *, ssize_t));
int _EXFUN(symlink, (const char *oldpath, const char *newpath));
long _EXFUN(sysconf, (int __name ));
pid_t _EXFUN(tcgetpgrp, (int __fildes ));
int _EXFUN(tcsetpgrp, (int __fildes, pid_t __pgrp_id ));
int _EXFUN(truncate, (const char *, off_t __length));
char * _EXFUN(ttyname, (int __fildes ));
int _EXFUN(ttyname_r, (int __fildes, char *__buf, size_t __len));
int _EXFUN(unlink, (const char *__path ));
int _EXFUN(usleep, (__useconds_t __useconds));
int _EXFUN(vhangup, (void ));
_READ_WRITE_RETURN_TYPE _EXFUN(write, (int __fd, const void *__buf, size_t __nbyte ));
extern char *optarg; /** getopt(3) external variables */
extern int optind, opterr, optopt;
int getopt(int, char * const [], const char *);
extern int optreset; /** getopt(3) external variable */
#ifndef _POSIX_SOURCE
pid_t _EXFUN(vfork, (void ));
extern char *suboptarg; /** getsubopt(3) external variable */
int getsubopt(char **, char * const *, char **);
#endif /** _POSIX_SOURCE */
/** Provide prototypes for most of the _<systemcall> names that are
provided in newlib for some compilers. */
int _EXFUN(_close, (int __fildes ));
pid_t _EXFUN(_fork, (void ));
pid_t _EXFUN(_getpid, (void ));
int _EXFUN(_link, (const char *__path1, const char *__path2 ));
off_t _EXFUN(_lseek, (int __fildes, off_t __offset, int __whence ));
_READ_WRITE_RETURN_TYPE _EXFUN(_read, (int __fd, void *__buf, size_t __nbyte ));
void * _EXFUN(_sbrk, (size_t __incr));
int _EXFUN(_unlink, (const char *__path ));
_READ_WRITE_RETURN_TYPE _EXFUN(_write, (int __fd, const void *__buf, size_t __nbyte ));
int _EXFUN(_execve, (const char *__path, char * const __argv[], char * const __envp[] ));
#define F_OK 0
#define R_OK 4
#define W_OK 2
#define X_OK 1
# define SEEK_SET 0
# define SEEK_CUR 1
# define SEEK_END 2
#include <sys/features.h>
#define STDIN_FILENO 0 /** standard input file descriptor */
#define STDOUT_FILENO 1 /** standard output file descriptor */
#define STDERR_FILENO 2 /** standard error file descriptor */
#include <bits/environments.h>
#include <bits/confname.h>
# define MAXPATHLEN 1024
#ifdef __cplusplus
}
#endif
#endif /** _SYS_UNISTD_H */

  

#include<unistd.h>头文件的理解的更多相关文章

  1. include <ctype.h> 头文件包含函数总结

    里面包含的函数主要是: 1.字符测试函数,函数原型一般为:int isXXXX( int ); 参数为int, 只能正确处理[0, 127]. 2.字符映射函数,函数原型一般为:int toXXXX( ...

  2. VS2008和VC6.0下使用pthread.h头文件

    原文:http://www.cppblog.com/liquidx/archive/2009/06/16/87811.html 要在windows环境下使用 #include <pthread. ...

  3. 在头文件中声明class 类 与 include类所在的头文件区别---理解

    在头文件中声明class 类 与 include类所在的头文件的理解: 在头文件中,声明类 它告诉编译器:存在这样的类.而实际的类则可以位于同一个编译单元中,也可以放在其他编译单元中.没有这个类原型, ...

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

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

  5. apue.h头文件(UNIX环境高级编程)

    在看UNIX环境高级编程是,碰到一个头文件"apue.h",搜一下别人的帖子,其实apue.h是作者自己写的一个文件,包含了常用的头文件,系统不自带.其中包含了常用的头文件,以及出 ...

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

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

  7. 【C】.h头文件的重复包含问题

    .h头文件存在的意义就是封装,可以方便多个.c源文件使用,但要防止.h头文件被同一个.c源文件多次包含. 例如, io.h文件 #ifndef _IO_H_ #define _IO_H_ #defin ...

  8. 基础知识复习(二)——stdafx.h 头文件及x&(x-1)运算

    今天好久没写过C++程序了,使用VS2013 新建空的控制台程序,结果自动生成了头文件和main 方法. 就了解了stdafx.h头文件的含义及用法. stdafx:standard Applicat ...

  9. hpp头文件与h头文件的区别

    hpp,其实质就是将.cpp的实现代码混入.h头文件当中,定义与实现都包含在同一文件,则该类的调用者只需要include该hpp文件即可,无需再将cpp加入到project中进行编译.而实现代码将直接 ...

随机推荐

  1. SVN检出资源文件

    一.选择new,输入svn,点击“从SVN检出项目” 二.选择“创建新的资源库位置”或“使用现有的资源库位置”(如果是新建,则需要地址和用户名.密码) 三.从现有的资源库选中项目

  2. Reactjs相比较原生方案是绝对的快吗?哪些情况下React有优势

    作者:尤雨溪链接:http://www.zhihu.com/question/31809713/answer/53544875来源:知乎著作权归作者所有,转载请联系作者获得授权.   1. 原生 DO ...

  3. 利用Multi-Probe LSH构建ANN高维索引

    感谢大神们的无私奉献精神........因此笔者要坚持开源,专注开源,开源就像在HPU的考试中不像其他人作弊一样,长远来看,会有巨大收获. 一.背景介绍 1.1 相似性搜索简介 高维相似性搜索在音频. ...

  4. 剑指offer--面试题10

    题目:求整数二进制表示中1的个数. 分析:此题直接考查二进制表示与位运算!!! 正数和负数的二进制表示不同!在计算机中,正数的二进制表示即为通常所写的二进制:而负数的二进制表示则用补码表示,即原码的反 ...

  5. UVALive 6525

    二分图最大匹配 #include<cstdio> #include<iostream> #include<cstring> #define MAX 10010 us ...

  6. uva 10131

    DP 先对大象体重排序   然后寻找智力的最长升序子列  输出路径.... #include <iostream> #include <cstring> #include &l ...

  7. PowerDesigner修改设计图中文字的字体大小等样式

    设计图中默认的字体是对英文比较合适的,中文就看不清楚了,特别不美观.但是可以通过修改“Display Preferences”适应我们的汉字. 我使用的PowerDesigner版本是15.1(测试版 ...

  8. lintcode 中等题:subSets 子集

    题目 子集 给定一个含不同整数的集合,返回其所有的子集 样例 如果 S = [1,2,3],有如下的解: [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], ...

  9. lintcode:递归打印数字

    题目 用递归打印数字 用递归的方法找到从1到最大的N位整数. 样例 给出 N = 1, 返回[1,2,3,4,5,6,7,8,9]. 给出 N = 2, 返回[1,2,3,4,5,6,7,8,9,10 ...

  10. Vimrc配置以及Vim的常用操作

    """"""""""""""""&quo ...