linux下的檔案io程式設計實現檔案的拷貝

2021-07-10 16:40:32 字數 517 閱讀 7980

/* copy_file.c */

#include #include #include #include #include #include #define buffer_size 1024 /* 每次讀寫快取大小,影響執行效率*/

#define src_file_name "src_file" /* 源檔名 */

#define dest_file_name "dest_file" /* 目標檔名檔名 */

#define offset 10240 /* 拷貝的資料大小 */

int main()

/* 將原始檔的讀寫指標移到最後10kb的起始位置*/

lseek(src_file, -offset, seek_end);

/* 讀取原始檔的最後10kb資料並寫到目標檔案中,每次讀寫1kb */

while ((real_read_len = read(src_file, buff, sizeof(buff))) >

linux 檔案I O 程式設計

1.基本操作 include include include open fd open tmp hello.c o wronly o creat,0600 close close fd read read fd,buf,len write write fd,buf,len lseek off t l...

linux下的檔案緩衝IO

1 dup dup2 複製乙個現有的檔案描述符時,不會賦值檔案表。出現多個檔案描述符對應同一張檔案表的情況 dup 複製時系統會自動選擇乙個位置用的檔案描述符,通常選擇未使用的最小值 dup2 是程式設計師指定的新的檔案描述符,如果已被使用,則會強行關閉原始檔後繼續為我所有。dup.c 他們經常用來...

linux程式設計之檔案I O

linux下c語言對於檔案的操作,我們會經常用到fopen fclose fwrite fread fgets 等一系列庫函式,基本和是和windows下學習c語言一樣的,其實這些庫函式就是在linuxx下對系統呼叫函式的封裝,因此這裡只介紹系統函式下的檔案操作函式。一 open 開啟檔案 incl...