linux ,编写一个程序,把一个文件复制到另一个文件上
即实现简单的copy功能 要求:只用 open() read() write() 和close()系统调用.
cat file1 >> file2 ? open()连个文件,read()其中一个内容,write()到另外一个文件上,最后close()掉。 能不能用lseek函数? C/C++ code: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #define BUF_SIZE 1024*8 int main() { int fds, fdd; char buf[BUF_SIZE]; size_t hasread = 0; fds = open("filea", O_RDONLY); fdd = open("fileb", O_WRONLY, O_CREAT); if(fds && fdd) { while((hasread = read(fds, buf, sizeof(buf))) > 0) { write(fdd, buf, hasread); } close(fds); close(fdd); } 不好意思,少copy半边“}”引用 不好意思,少copy半边“}” 非常好
相关问答:
Linux新手,请大哥大姐不要见笑。 我用root用户登录到Linux系统。在根目录下面建了目录dir1,后用命令cd /dir1进入到dir1目录下,然后再用mkdir dir2建立了目录dir2 ,再后来用命令cd /dir2是,提示为:-bush ......
我之前制作的linux自动安装iso已经成功了,现在想对其进行一些定制修改,比如,更改grub图片等。 我在ks.cfg的%post段里面是这样写的: %post --nochroot # Move the contents of the tar into their new locati ......
各位大虾,我正在学习Linux,可是Linux图形界面和命令行之间切换遇到困难,在命令行下输入startx,不是进入图形界面 而是出现 请问各位,这是为什么? 而且按Ctrl+Alt+F7,也不能命令行进入图形界面。&nbs ......
请教: 在 LINUX系统中的ORACLE怎么新建表空间? 一样的命令啊。如果没用omf的话,你就指定下路径和数据文件名就行了。 create tablespace xxx datafile '/u01/..../aaa.dbf' size 10m; CREATE TA ......
linux初始化时把支持的物理内存都映射到page table中,之后进程需要内存时,也是映射到这个物理内存中,如此说来,linux初始化时创建的page table和进程中创建的page table指向同一块物理页面吗?这样做的目的是什么 ......