#include “unistd.h” 头文件的理解

您所在的位置:网站首页 头文件windows是什么意思 #include “unistd.h” 头文件的理解

#include “unistd.h” 头文件的理解

2024-07-13 09:36| 来源: 网络整理| 查看: 265

转一篇:https://www.cnblogs.com/haore147/p/3646243.html

1.百度百科定义

unistd.h 是 C 和 C++ 程序设计语言中提供对 POSIX 操作系统 API 的访问功能的头文件的名称。该头文件由 POSIX.1 标准(单一UNIX规范的基础)提出,故所有遵循该标准的操作系统和编译器均应提供该头文件(如 Unix 的所有官方版本,包括 Mac OS X、Linux 等)。

对于类 Unix 系统,unistd.h 中所定义的接口通常都是大量针对系统调用的封装(英语:wrapper functions),如 fork、pipe 以及各种 I/O 原语(read、write、close 等等)。

**我的定义:**这是一个头文件,封装了类UNIX系统下的很多固定名称的system_call系统调用。所以,这个函数是依赖于编译器,依赖于操作系统的。

2.源码

可以从源码中,查看它封装了哪些固定名称的操作系统api。使用的是VxWorks5.5源码中的unistd.h文件。这也意味着之前的日志系统也是适用于VxWorks操作系统的。日志系统模块基础、C语言实现一个日志模块、zlog日志模块基础

/* unistd.h - unix standard library header file */ /* Copyright 1984-1994 Wind River Systems, Inc. */ /* modification history -------------------- 02h,20jul00,jgn add POSIX version information + removed old style prototypes 02g,24sep01,jkf added const to rmdir() 02f,19aug94,ism added getcwd() prototypes (SPR #3536) 02e,12nov93,dvs added prototype for ftruncate. 02d,08feb93,smb changed int to size_t in protype for read() and write() 02c,22sep92,rrr added support for c++ 02b,18sep92,smb added the rmdir prototype. 02a,04jul92,jcf cleaned up. 01c,26may92,rrr the tree shuffle 01b,05dec91,rrr added SEEK_ macros (was in ioLib.h) 01a,19nov91,rrr written. */ #ifndef __INCunistdh #define __INCunistdh #ifdef __cplusplus extern "C" { #endif #include "vxWorks.h" #ifndef SEEK_SET #define SEEK_SET 0 /* absolute offset, was L_SET */ #define SEEK_CUR 1 /* relative to current offset, was L_INCR */ #define SEEK_END 2 /* relative to end of file, was L_XTND */ #endif /* POSIX defines */ #ifndef _POSIX_VERSION #define _POSIX_VERSION 199506L #endif #ifndef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 199506L #endif /* function declarations */ #if defined(__STDC__) || defined(__cplusplus) extern STATUS unlink (char *name); extern STATUS close (int fd); extern int read (int fd, char *buffer, size_t maxbytes); extern int write (int fd, char *buffer, size_t nbytes); extern int lseek (int fd, long offset, int whence); extern STATUS chdir (char *pathname); extern STATUS pause (void); extern BOOL isatty (int fd); extern STATUS rmdir (const char *dirName); extern char * getcwd (char *buffer, int size); extern int ftruncate (int fildes, off_t length); extern unsigned int sleep (unsigned int); extern unsigned int alarm (unsigned int); #else /* __STDC__ */ extern STATUS unlink (); extern STATUS close (); extern int read (); extern int write (); extern int lseek (); extern STATUS chdir (); extern STATUS pause (); extern BOOL isatty (); extern STATUS rmdir (); extern char *getcwd(); extern int ftruncate (); #endif /* __STDC__ */ #ifdef __cplusplus } #endif #endif /* __INCunistdh */


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3