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

unistd.h是C和C++编程中用于访问POSIX操作系统API的头文件,主要在类UNIX系统如Unix、Linux、MacOSX中使用。它包含了诸如fork、pipe、read、write等系统调用的封装。本文通过分析VxWorks5.5的unistd.h源码,展示了其中定义的函数声明,这些函数提供了对操作系统API的基本操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

1.百度百科定义

unistd.hCC++ 程序设计语言中提供对 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。使用的是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 */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

机载软件与适航

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值