gpt4 book ai didi

C重命名函数语法问题

转载 作者:太空宇宙 更新时间:2023-11-04 04:23:52 24 4
gpt4 key购买 nike

使用重命名时,使用完整的目录名是否可行?我似乎无法让这个例子起作用,尽管所有迹象都表明它应该起作用。有人知道为什么吗?例子;

original file location is: /home1/s/j/jb986132/402project4/402project4TEST/checkDirectory.c
final destination of file is: /home1/s/j/jb986132/402project4/402project4TEST/c/checkDirectory.c
filename is: checkDirectory.c
destinationName is: /c/checkDirectory.c
active is: /home1/s/j/jb986132/402project4/402project4TEST

我可以把它写成:

rename(original file location, final destination)

最佳答案

实际上,标准本身很少说明函数的允许参数是什么,它只是说明:

The rename function causes the file whose name is the string pointed to by old to be henceforth known by the name given by the string pointed to by new. The file named old is no longer accessible by that name. If a file named by the string pointed to by new exists prior to the call to the rename function, the behaviour is implementation-defined.

The rename function returns zero if the operation succeeds, nonzero if it fails, in which case if the file existed previously it is still known by its original name.

Among the reasons the implementation may cause the rename function to fail are that the file is open or that it is necessary to copy its contents to effectuate its renaming.

我在最后一段中突出显示了该片段,因为它意味着任何数量的其他原因都可能导致失败,例如尝试更改目录,或尝试在晚上 6 点之后调用它一个蓝色的月亮:-)

您可能会认为,如果子目录位于同一物理文件系统上,类 UNIX 操作系统至少不会有问题,因为它很可能只是一个简单的 inode 移动。

但是,C 标准似乎对底层文件系统没有任何预设。

关于C重命名函数语法问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43578259/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com