Radek Brich <[EMAIL PROTECTED]> wrote: > On Tue 11. of December 2007 13:55:53 you wrote: >> Radek Brich <[EMAIL PROTECTED]> ha escrit: >> > Although it'd need some cleaning, I'd like to hear what >> > you think about the idea? >> >> Generally speaking, looks nice, except that fstat may fail (e.g. if >> stdout is closed) in which case st_stdout would contain garbage. ... > + struct stat st_buf; > + ino_t stdout_ino = fstat(STDOUT_FILENO, &st_buf) == -1 ? > + 0 : st_buf.st_ino; > + ino_t archive_ino = stat(archive_name_array[0], &st_buf) == -1 ? > + 0 : st_buf.st_ino; > + bool archive_is_stdout = (archive_ino != 0 && archive_ino == stdout_ino);
You'll want to compare st_dev, as well. Otherwise, there's a small risk of a false positive with a file on a different partition, but with the same inode number. You can use the SAME_INODE macro from gnulib's lib/same-inode.h, since tar already has that file.
