小记——linux复制文件与重命名

落日映苍穹つ 2022-09-23 14:46 306阅读 0赞
  1. 重命名

    include

    int rename (const char oldpath, const char newpath);

两个文件必在同一文件系统中,目录是不能复制的。

  1. 复制

linux系统中并没有提供文件复制的系统调用或C语言函数,这个功能要自己实现,一般步骤为:

In copying a file src to a file named dst, the steps are as follows:

  1. Open src.
  2. Open dst, creating it if it does not exist, and truncating it to zero length if it does exist.
  3. Read a chunk of src into memory.
  4. Write the chunk to dst.
  5. Continue until all of src has been read and written to dst.
  6. Close dst.
  7. Close src.
    If copying a directory, the individual directory and any subdirectories are created via mkdir(); each file therein is then copied individually.

发表评论

表情:
评论列表 (有 0 条评论,306人围观)

还没有评论,来说两句吧...

相关阅读