Chinaunix首页 | 论坛 | 博客
  • 博客访问: 193945
  • 博文数量: 39
  • 博客积分: 1491
  • 博客等级: 上尉
  • 技术积分: 411
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-05 16:12
文章分类

全部博文(39)

文章存档

2011年(3)

2010年(6)

2009年(30)

我的朋友

分类: LINUX

2010-01-18 12:12:13

如果函数执行成功会返回读到的字节数,如果到达文件尾,则返回0.
当实际读到的数据字节数小于参数中指定的字节数时,会有以下几种情况:

  • When reading from a regular file, if the end of file is reached before the requested number of bytes has been read. For example, if 30 bytes remain until the end of file and we try to read 100 bytes, read returns 30. The next time we call read, it will return 0 (end of file).

  • When reading from a terminal device. Normally, up to one line is read at a time.

  • When reading from a network. Buffering within the network may cause less than the requested amount to be returned.

  • When reading from a pipe or FIFO. If the pipe contains fewer bytes than requested, read will return only what is available.

  • When reading from a record-oriented device. Some record-oriented devices, such as magnetic tape, can return up to a single record at a time.

  • When interrupted by a signal and a partial amount of data has already been read.

阅读(1644) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~