日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > windows >内容正文

windows

系统I/O小程序-文件拷贝

發(fā)布時間:2023/11/30 windows 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 系统I/O小程序-文件拷贝 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

系統(tǒng)I/O小程序-文件拷貝
使用系統(tǒng)IO函數(shù)編寫 ./syscopy src des

#include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <errno.h>/** * system i/o * ./syscopy src des */ int main(int argc, char *argv[]) {int des_fd, src_fd;char buf[128];int size;unsigned int count;if (argc < 3) {printf("The argc is wrong!\n");return -1;}src_fd = open(argv[1], O_RDONLY);if (src_fd < 0) {printf("open %s fail.\n", argv[1]);return -1;}des_fd = open(argv[2], O_RDWR|O_CREAT|O_TRUNC);if (des_fd < 0) {printf("open %s fail.\n", argv[2]);close(src_fd);return -1;}while (1) {size = read(src_fd, buf, 128);if (size == -1) {printf("read %s fail.\n", argv[1]);close(src_fd);close(des_fd);return -1;}if (size == 0) {if(errno == EINTR) {continue;}break;}if (write(des_fd, buf, size) != size) {printf("write %s fail.\n", argv[2]);close(src_fd);close(des_fd);return -1;}}count = lseek(src_fd, 0, SEEK_END);printf("src long:%d\n", count);count = lseek(des_fd, 0, SEEK_END);printf("des long:%d\n", count);close(src_fd);close(des_fd);return 0; }

總結(jié)

以上是生活随笔為你收集整理的系统I/O小程序-文件拷贝的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。