linux下c語言實現檔案拷貝
/*function:copy file from file1 to file2
how to execute: ./copyfile file1 file2 (under linux)
data:2007-05-09
*/#include /*fprintf(),stderr,bufsiz*/
#include /**/
#include /*stderror()*/
#include /*open(),flag*/
#include /*errno*/
#include /*ssize_t*/
#include
#include /*mode_t*/
#define buffer_size 3
int main(int argc,char **argv)
/* 開啟原始檔 */
if((from_fd=open(argv[1],o_rdonly))==-1) /*open file readonly,返回-1表示出錯,否則返回檔案描述符*/
/* 建立目的檔案 */
/* 使用了o_creat選項-建立檔案,open()函式需要第3個引數,
mode=s_irusr|s_iwusr表示s_irusr 使用者可以讀 s_iwusr 使用者可以寫*/
if((to_fd=open(argv[2],o_wronly|o_creat,s_irusr|s_iwusr))==-1)
/* 以下**是乙個經典的拷貝檔案的** */
while(bytes_read=read(from_fd,buffer,buffer_size))
}/* 寫的時候發生的致命錯誤 */
if(bytes_write==-1)
break;}}
close(from_fd);
close(to_fd);
return;
}
Linux下C語言實現UDP Socket程式設計
該博文參考了linux c socket 程式設計之udp一文,在這裡表示感謝!傳送方 file udp sender.c author henry created on 2019年5月29日17 08 13 主要實現 傳送20個文字訊息,然後再傳送乙個終止訊息 include include in...
Linux下C語言實現簡單Shell
include include include include include include include include define max string 256 define signin define signout define signpine const char expst ex...
linux下ping的C語言實現
include stdio.h include signal.h include arpa inet.h include sys types.h include sys socket.h include unistd.h include netinet in h include netinet ip...