[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-tar] tar -vf /dev/stdout produces corrupted archives
From: |
Jim Meyering |
Subject: |
Re: [Bug-tar] tar -vf /dev/stdout produces corrupted archives |
Date: |
Wed, 12 Dec 2007 12:08:43 +0100 |
Radek Brich <address@hidden> wrote:
> On Tue 11. of December 2007 13:55:53 you wrote:
>> Radek Brich <address@hidden> 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.
Re: [Bug-tar] tar -vf /dev/stdout produces corrupted archives, Radek Brich, 2007/12/11
- Re: [Bug-tar] tar -vf /dev/stdout produces corrupted archives, Sergey Poznyakoff, 2007/12/11
- Re: [Bug-tar] tar -vf /dev/stdout produces corrupted archives, Radek Brich, 2007/12/11
- Re: [Bug-tar] tar -vf /dev/stdout produces corrupted archives, Radek Brich, 2007/12/11
- Re: [Bug-tar] tar -vf /dev/stdout produces corrupted archives,
Jim Meyering <=
- Re: [Bug-tar] tar -vf /dev/stdout produces corrupted archives, Radek Brich, 2007/12/12
- Re: [Bug-tar] tar -vf /dev/stdout produces corrupted archives, Radek Brich, 2007/12/12
- Re: [Bug-tar] tar -vf /dev/stdout produces corrupted archives, Paul Eggert, 2007/12/17