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

简介:

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

  

2.源码

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#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 */

  本文转自二郎三郎博客园博客,原文链接:http://www.cnblogs.com/haore147/p/3646243.html,如需转载请自行联系原作者

相关文章
|
2月前
|
编译器 C语言
#include
#include
47 0
|
9月前
makefile include 使用介绍
makefile include 使用介绍
51 0
|
9月前
|
编译器 程序员 C++
C头文件
C头文件。
26 0
|
8天前
#include的应用练习
【6月更文挑战第22天】#include的应用练习。
10 2
|
2月前
|
编译器 C语言
c头文件
c头文件
19 0
|
2月前
|
编译器 程序员 C++
头文件
头文件。
24 2
|
2月前
|
存储
include函数
【2月更文挑战第15天】include函数。
22 2
|
9月前
|
编译器 程序员 C++
C 头文件
C 头文件。
20 0
|
2月前
#include 的应用练习
#include 的应用练习。
28 3
|
编译器 C++
解决iostream.h在vc2008下不能被include
解决iostream.h在vc2008下不能被include
73 0