posts - 403, comments - 310, trackbacks - 0, articles - 7
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          APUE - File I/O (2)

          Posted on 2007-08-13 22:14 ZelluX 閱讀(399) 評論(0)  編輯  收藏 所屬分類: LinuxC/C++
           1. File hole
          The file's offset can be greater than the file's current size, in which case the next write to the file will extend the file. This is referred to as creating a hole in a file and is allowed. Any bytes in a file that not been written are read back as 0.
          A hole in a file isn't required to have storage backing it on disk. Depending on the file system implementation, when you write after seeking past the end of the file, new disk blocks might be allocated to store the data, but there's no need to allocate disk blocks for the data between the old end of file and t he location where you start writing.

          2. read Function
          #include <unistd.h>
          ssize_t read(int filedes, void *buf, size_t nbytes);
          // Returns: number of bytes read, 0 if end of file, -1 on error
          read讀取的字節(jié)數(shù)小于所要求的字節(jié)數(shù)的幾種可能:
          1) 從文件中讀取,在所要求的字節(jié)數(shù)讀取完成前到達(dá)文件尾。
          2) 從終端讀取,這種情況下通常每次最多讀取一行內(nèi)容。
          3) 通過網(wǎng)絡(luò)讀取,網(wǎng)絡(luò)緩沖可能導(dǎo)致讀取到少于要求的字節(jié)數(shù)。
          4) 從管道或者FIFO中讀取
          5) 從record-oriented設(shè)備中讀取,如磁帶,每次至多返回一個(gè)記錄。orz...
          6) 在一定數(shù)量的數(shù)據(jù)讀取后被信號中斷。

          3. write Function
          #include <unistd.h>
          ssize_t write(int filedes, const void *buf, size_t nbytes);
          // Returns: number of bytes written if OK, -1 on error
          導(dǎo)致錯(cuò)誤的通常原因是磁盤已滿,或者超出了給定進(jìn)程的文件大小限制。
          主站蜘蛛池模板: 保山市| 堆龙德庆县| 富顺县| 马龙县| 页游| 安西县| 巴塘县| 甘德县| 高邮市| 遂平县| 称多县| 上思县| 淳化县| 武强县| 沛县| 泉州市| 申扎县| 洛川县| 大英县| 孟州市| 莱芜市| 天气| 广灵县| 贵州省| 安化县| 会同县| 清苑县| 鸡泽县| 昭觉县| 交口县| 博爱县| 通州区| 浏阳市| 门头沟区| 安仁县| 南溪县| 新龙县| 攀枝花市| 察隅县| 仲巴县| 乌审旗|