#include 的作用

由字面意思,unistd.h是unix std的意思,是POSIX標準定義的unix類系統定義符號常量的頭文件,

包含了許多UNIX系統服務的函數原型,例如read函數、write函數和getpid函數。 

參考自 http://hi.baidu.com/w_dalu/item/e8d29860374ae02369105b11

unistd.h在unix中類似於window中的windows.h!


#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif

unistd.h含有的常量與函數:

ssize_t      read(int, void *, size_t); // 讀取文件使用
int          unlink(const char *);
ssize_t      write(int, const void *, size_t); // 寫文件
int          usleep(useconds_t); // 進程休眠,單位爲微妙
unsigned     sleep(unsigned); // 進程休眠,單位爲秒

int          access(const char *, int); // 獲取文件的權限
unsigned     alarm(unsigned);
int          chdir(const char *);
int          chown(const char *, uid_t, gid_t);
int          close(int); // 關閉文件
size_t       confstr(int, char *, size_t);
void        _exit(int);
pid_t        fork(void);

 

NULL           // Null pointer
SEEK_CUR    // Set file offset to current plus offset.
SEEK_END    // Set file offset to EOF plus offset.
SEEK_SET    // Set file offset to offset.



許多在Linux下開發的C程序都需要頭文件unistd.h,但VC中沒有個頭文件,
所以用VC編譯總是報錯。把下面的內容保存爲unistd.h,可以解決這個問題。
/** This file is part of the Mingw32 package.
unistd.h maps (roughly) to io.h
*/

#ifndef _UNISTD_H
#define _UNISTD_H
#include <io.h>
#include <process.h>
#endif /* _UNISTD_H */


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章