linux下 lseek函式用法

2021-06-21 16:02:15 字數 606 閱讀 2180

lseek函式 用法 :

表頭檔案:#include 

#include 

定義函式:off_t  lseek(int fildes,  off_t  offset,  int  whence)

seek_set            引數offset即為新的讀寫位置

seek_cur            當前讀寫位置後增加offset個位移量。

seek_end            將讀寫位置指向檔案尾後再增加offset個位移量

當whence值為seek_cur或seek_end時,引數offset允許負值的出現

下列是較特別的使用方式:

1)欲將讀寫位置移到檔案開頭時:lseek(int  fildes, 0, seek_set)

2)欲將讀寫位置移到檔案尾時時:lseek(int fildes, 0, seek_end)

3)欲將取得目前檔案位置時:lseek(int fildes, 0, seek_cur)

返回值:當呼叫成功時則返回目前的讀寫位置,也就是距離檔案開頭多少個字元。若有錯誤則返回-1, errno會存放錯誤**。

錯誤**:eintr        此呼叫被訊號所中斷

lseek函式的用法lseek函式的用法

使用 lseek 函式可以改變檔案的 cfo include unistd.h include off t lseek int filedes,off t offset,int whence 返回值 新的偏移量 成功 1 失敗 引數 offset 的含義取決於引數 whence 1.如果 whenc...

lseek函式用法

lseek函式 include off t lseek int fd,off t offset,int whence 返回值 若成功,返回新的檔案偏移量 若失敗,返回 1 可以呼叫lseek顯示地為乙個開啟檔案設定偏移量。檔案偏移都是核心概念,所以lseek並不會引起任何真正的 i o 操作。對引數...

Linux系統庫函式 lseek函式用法

使用 lseek 函式可以改變檔案的 cfo include off t lseek int filedes,off t offset,int whence 返回值 新的偏移量 成功 1 失敗 引數 offset 的含義取決於引數 whence 1.如果 whence 是 seek set,檔案偏移...