利用 庫函式 實現Linux下的 複製 cp 功能

2021-08-02 01:36:36 字數 601 閱讀 4792

今天, 我學習了 庫函式 和 系統呼叫 的有關知識, 利用庫函式寫了一段程式, 用於實現linux系統下的 複製(cp)功能。

#includeint main(int argc, char* argv[3])

file* file1 = fopen(argv[1], "r");

if (null == file1)

file* file2 = fopen(argv[2], "w");

if(null == file2)

char* butter[1024] = ;

while (!(feof(file1)))

int count2 = fwrite(butter, sizeof(void), count, file2);

if (0 == count2)

}fclose(file1);

fclose(file2);

return

0;}

這個程式的精妙之處在於其利用了乙個簡單的迴圈, 解決了複製檔案的大小的限制, 通過foef函式判斷原檔案是否被read到末尾。

但這個程式還有一些bug, 在今後學習了更多知識後, 會加以改進。

linux 下的 DL庫 函式

包含標頭檔案 include 函式定義 void dlopen const char pathname,int mode 函式描述 在dlopen的 函式以指定模式開啟指定的動態連線庫檔案,並返回乙個控制代碼給呼叫程序。使用dlclose 來解除安裝開啟的庫。mode 分為這兩種 rtld lazy...

Linux系統下C 標準庫函式

標頭檔案 include 函式名作用isalnum 測試字元是否為英文本母或數字 isalpha 測試字元是否為英文本母 isascii 測試字元是否為ascii碼字元 isblank 測試字元是否為空白字元 包括空格 r n t 符號 iscntrl 測試字元是否為ascii碼的控制字元 isdi...

linux下epoll系統呼叫實現I O復用

epoll系統呼叫 穿件核心事件表,返回指向被建立表的檔案描述符 作為其它epoll函式的第乙個引數 include int epoll create int size epoll ctl實現對核心事件表的操作 int epoll ctl int epfd,int op,int fd,struct ...