5 Years
Discussion Span
Last Post by BobS0327

i'm writing a program in c++ using linux and i face the following issue:
i want to tell the difference between a hard link and a file,given a path.
To be more specific, i consider that it is the file itself when there's only one hard link pointing to the file.If there're more than 1 hard links pointing to the file then i consider the path as a hardlink.I do the following:

struct stat statbuf ;
bool decideHardLink(){
 return statbuf.st_nlink>1

i cant think of another way to check it ..is this one correct?

How about the following???

if (!S_ISLNK (statinfo.st_mode) && statinfo.st_nlink > 1)
  	printf("The file %s IS A HARD LINK to another filename\n", filename);         
   else if (S_ISLNK (statinfo.st_mode))
      printf("The file %s IS A SYMBOLIC LINK\n", filename);         
   else {
      printf("The file %s IS NOT A LINK\n", filename);         
      printf("Check the dp->d_type flag to spesify the filetype (DT_DIR, DT_REG, DT_FIFO, DT_CHR, DT_BLK, DT_SOCK etc)\n");
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.