C语言拷贝文件函数实现(linux cp [source file] [target file] 命令的实现)
来源:互联网 发布:淘宝网海外购保健品 编辑:程序博客网 时间:2024/04/29 19:56
/** * 功能:拷贝文件函数 * 参数: * sourceFileNameWithPath:源文件名(带路径) * targetFileNameWithPath:目标文件名(带路径) * 返回值: * SUCCESS: 拷贝成功 * FAILURE:拷贝失败 * author:wangchangshuai jlu */int copyFile(const char *sourceFileNameWithPath, const char *targetFileNameWithPath){FILE *fpR, *fpW;char buffer[BUFFER_SIZE];int lenR, lenW;if ((fpR = fopen(sourceFileNameWithPath, "r")) == NULL){myLog("The file '%s' can not be opened! \n", sourceFileNameWithPath);return FAILURE;}if ((fpW = fopen(targetFileNameWithPath, "w")) == NULL){myLog("The file '%s' can not be opened! \n", targetFileNameWithPath);fclose(fpR);return FAILURE;}memset(buffer, 0, BUFFER_SIZE);while ((lenR = fread(buffer, 1, BUFFER_SIZE, fpR)) > 0){if ((lenW = fwrite(buffer, 1, lenR, fpW)) != lenR){myLog("Write to file '%s' failed!\n", targetFileNameWithPath);fclose(fpR);fclose(fpW);return FAILURE;}memset(buffer, 0, BUFFER_SIZE);}fclose(fpR);fclose(fpW);return SUCCESS;}
2 0
- C语言拷贝文件函数实现(linux cp [source file] [target file] 命令的实现)
- C语言实现Linux cp命令
- 【C语言】实现Linux下的cp命令的基本功能
- C语言实现cp -r --parents拷贝文件和文件夹
- 用Linux_C语言模拟CP命令,实现文件和文件夹的拷贝
- Linux文件复制cp命令的实现
- 自己写的unix文件拷贝指令cp实现函数
- c语言实现文件拷贝命令
- (十一)linux下用c语言 实现file流的刷新和定位的相关函数
- 实现cp命令–文件夹的拷贝
- 用c语言程序实现系统的cp命令 在linux下调用syscalls.h头文件
- Linux下C语言实现文件拷贝
- Linux cp命令 拷贝文件
- linux 的cp命令实现
- linux cp 命令的实现
- Linux命令-8:cp(Copy File)命令
- 内存拷贝函数的C语言实现
- 实现header file (.h)相应的source file (.cc/.cpp)文件时的注意事项
- SmartSVN设置忽略文件类型设置
- 基于visual Studio2013解决面试题之1007鸡蛋和篮子
- UltreEdit 宏命令加行号
- 布隆过滤器
- container_of(ptr, type, member)
- C语言拷贝文件函数实现(linux cp [source file] [target file] 命令的实现)
- springMVC入门
- Windows命令行高级操作
- 基于visual Studio2013解决面试题之1009兄弟字符串
- 数值计算线性方程组求解实现
- Delphi 的持续机制浅探
- 340 - Master-Mind Hints
- 关于decode参数类型
- vc中字符串和数字转换的函数:atoi,atol,strtod,strtol,strtoul 类型转换