本文整理汇总了C++中FILE::write方法的典型用法代码示例。如果您正苦于以下问题:C++ FILE::write方法的具体用法?C++ FILE::write怎么用?C++ FILE::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FILE
的用法示例。
在下文中一共展示了FILE::write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write
int write(int fid, const void *buf, unsigned int nbytes)
{
int written;
FILE *file;
#if OS_PARM_CHECK
/*-------------------------------------------------------------------*/
/* Ensure file descriptor is valid. */
/*-------------------------------------------------------------------*/
if (fid < 0 || fid >= FOPEN_MAX)
{
set_errno(EBADF);
return -1;
}
/*-------------------------------------------------------------------*/
/* Return error if buffer pointer is invalid. */
/*-------------------------------------------------------------------*/
if (buf == NULL)
{
Files[fid].errcode = EFAULT;
set_errno(EFAULT);
return -1;
}
#endif
/*-------------------------------------------------------------------*/
/* Acquire exclusive write access to stream. */
/*-------------------------------------------------------------------*/
file = &Files[fid];
file->acquire(file, F_WRITE);
/*-------------------------------------------------------------------*/
/* Return error if file is closed. */
/*-------------------------------------------------------------------*/
if (file->ioctl == NULL)
{
set_errno(EBADF);
file->release(file, F_WRITE);
return -1;
}
/*-------------------------------------------------------------------*/
/* Call file system specific write routine. */
/*-------------------------------------------------------------------*/
written = file->write(file, buf, nbytes);
/*-------------------------------------------------------------------*/
/* Set file's errno if less than requested number was written. */
/*-------------------------------------------------------------------*/
if (written < (int)nbytes)
{
file->errcode = get_errno();
if (written == 0)
written = -1;
}
/*-------------------------------------------------------------------*/
/* Release exclusive write access to stream. */
/*-------------------------------------------------------------------*/
file->release(file, F_WRITE);
/*-------------------------------------------------------------------*/
/* Return -1 or actual number of bytes read. */
/*-------------------------------------------------------------------*/
return written;
}