⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pwrite.c

📁 用于嵌入式Linux系统的标准C的库函数
💻 C
字号:
/*FUNCTION<<pwrite>>---write a file from specified positionINDEX	pwriteINDEX	_pwrite_rANSI_SYNOPSIS	#include <unistd.h>	ssize_t pwrite(int <[fd]>, const void *<[buf]>,                        size_t <[n]>, off_t <[off]>);	ssize_t _pwrite_r(struct _reent *<[rptr]>, int <[fd]>,                           const void *<[buf]>, size_t <[n]>, off_t <[off]>);TRAD_SYNOPSIS	#include <unistd.h>	ssize_t pwrite(<[fd]>, <[buf]>, <[n]>, <[off]>)	int <[fd]>;	const void *<[buf]>;	size_t <[n]>;	off_t <[off]>;	ssize_t _pwrite_r(<[rptr]>, <[fd]>, <[buf]>, <[n]>, <[off]>)	struct _reent *<[rptr]>;	int <[fd]>;	const void *<[buf]>;	size_t <[n]>;	off_t <[off]>;DESCRIPTIONThe <<pwrite>> function is similar to <<write>>.  One difference is that<<pwrite>> has an additional parameter <[off]> which is the offset toposition in the file before writing.  The function also differs in thatthe file position is unchanged by the function (i.e. the file positionis the same before and after a call to <<pwrite>>).The <<_pwrite_r>> function is the same as <<pwrite>>, only a reentrantstruct pointer <[rptr]> is provided to preserve reentrancy.RETURNS<<pwrite>> returns the number of bytes written or <<-1>> if failure occurred.PORTABILITY<<pwrite>> is non-ANSI and is specified by the Single Unix Specification.Supporting OS subroutine required: <<write>>, <<lseek>>.*/#include <_ansi.h>#include <unistd.h>#include <reent.h>ssize_t_DEFUN (_pwrite_r, (rptr, fd, buf, n, off),     struct _reent *rptr _AND     int fd _AND     _CONST _PTR buf _AND     size_t n _AND     off_t off){  off_t cur_pos;  _READ_WRITE_RETURN_TYPE num_written;    if ((cur_pos = _lseek_r (rptr, fd, 0, SEEK_CUR)) == (off_t)-1)    return -1;  if (_lseek_r (rptr, fd, off, SEEK_SET) == (off_t)-1)    return -1;  num_written = _write_r (rptr, fd, buf, n);  if (_lseek_r (rptr, fd, cur_pos, SEEK_SET) == (off_t)-1)    return -1;  return (ssize_t)num_written;}#ifndef _REENT_ONLYssize_t_DEFUN (pwrite, (fd, buf, n, off),     int fd _AND     _CONST _PTR buf _AND     size_t n _AND     off_t off){  return _pwrite_r (_REENT, fd, buf, n, off);}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -