gpt4 book ai didi

linux - open(const char *path, int oflag) 不接受像 "~/my.log"这样的路径

转载 作者:太空宇宙 更新时间:2023-11-04 09:01:04 31 4
gpt4 key购买 nike

我试过用

open("~/my.log",  O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)

创建文件,但返回错误

"No such file or directory". 

是不是因为open()不翻译“~”?

最佳答案

你是对的。翻译~的是shell,不是open*? 等通配符也是如此。事实上,任何时候您可以键入除磁盘上文件名的确切字节以外的任何内容,都是您的 shell 为您翻译成实际的文件名。

关于linux - open(const char *path, int oflag) 不接受像 "~/my.log"这样的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21270673/

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