当前位置: 首页>>代码示例>>C++>>正文


C++ FILE::write方法代码示例

本文整理汇总了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;
}
开发者ID:lubing521,项目名称:protocols,代码行数:67,代码来源:_WRITE.C


注:本文中的FILE::write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。