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?

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");
   }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.