开发者

Test for directory existence in C

开发者 https://www.devze.com 2023-01-08 12:40 出处:网络
I have a function that should create a directory.I want to test to make sure that the directory is create开发者_StackOverflow社区d, and

I have a function that should create a directory. I want to test to make sure that the directory is

I can't use lstat since I get EPERM when I do so (I assume I'm not supposed to know that much about a directory). So what else should I use? I can try to open it it with opendir, but that doesn't tell me what its permissions are.


Actually, yes you should use stat or lstat, depends whether the dir is a symbolic link or not. If you are getting EPERM from lstat, that probably means that the dir you are passing to lstat is a link and it points to someplace where you do not have the apropriate permissions to even see if a dir or file exists.

In fact, are you sure you should be using lstat and not just stat?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号