Вопрос

With c code, I want to know the given file (like test.c) is a symbolic link or not. I tried with stat() function. I am checking the

nlink_t   st_nlink;   /* number of hard links */

member of stat structure.

struct stat stbuf;
stat("test.c", &stbuf)

stbuf.st_nlink is giving one in case of hard link as well as in softlink.

Is that i am doing right. Or is there any other way to check the given file is a soft link or hard link.

Это было полезно?

Решение

No, you need to use lstat() to be able to detect if a file is a soft link.

Also make sure that you understand that typically, there are not three different types of files: files, hard links to files, and soft links to files. Instead, there are only two: hard links to files and soft links. What you might think of as "the file" is in fact a hard link too, it's just typically the single link.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top