[Toybox] [PATCH] Implement `file -`.

enh enh at google.com
Fri May 4 10:53:29 PDT 2018


okay, here's an alternative patch that only does the temporary file
dance for regular files...


[PATCH] Implement `file -`.

Previously we'd just always bogusly report "empty".
---
 tests/file.test   |  6 ++++++
 toys/posix/file.c | 34 +++++++++++++++++++++++++++-------
 2 files changed, 33 insertions(+), 7 deletions(-)


On Thu, May 3, 2018 at 8:12 PM, enh <enh at google.com> wrote:
> the FSF file(1) is inconsistent too, in a way that suggests it's being
> clever:
>
> ~$ file /dev/zero
> /dev/zero: character special (1/5)
> ~$ file - < /dev/zero
> /dev/stdin: data
> ~$
>
>
>
> On Thu, May 3, 2018, 18:36 Rob Landley <rob at landley.net> wrote:
>>
>> On 05/03/2018 06:40 PM, enh wrote:
>> > +    // If we're working on stdin, copy to a temporary file and then use
>> > +    // an fd for that file. That way the rest of the code doesn't have
>> > to
>> > +    // worry about non-seekable/non-mmap'able input.
>>
>> Hmmm, in the old code:
>>
>> $ ./file ../filesystems.tar.gz
>> ../filesystems.tar.gz: gzip compressed data
>> $ ./file - < ../filesystems.tar.gz
>> -: gzip compressed data
>> $ file /dev/zero
>> /dev/zero: character special
>> $ file - < /dev/zero
>> /dev/stdin: data
>>
>> That's inconsistent about /dev/zero, not sure why.
>>
>> But if we copy /dev/zero to a temp file we'll fill the hard drive...
>>
>> Rob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Implement-file.patch
Type: text/x-patch
Size: 2930 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20180504/71a17cdb/attachment-0003.bin>


More information about the Toybox mailing list