[Toybox] [PATCH] Add ftruncate logic to handle non-regular files

Chris Sarra chrissarra at google.com
Wed Sep 23 08:23:00 PDT 2020


IIUC, ftruncate will fail with `EISDIR` if its input is a directory. And I
don't know of any use-cases where we'd want or should be able to `dd` a
directory. Unless I'm missing something, the S_ISDIR could be removed,
since ftruncate ought to fail if a directory is given.

Thanks!
+Chris


On Wed, Sep 23, 2020 at 4:38 AM Rob Landley <rob at landley.net> wrote:

> On 9/15/20 12:10 PM, Chris Sarra via Toybox wrote:
> > -    if (trunc && ftruncate(TT.out.fd, bs)) perror_exit("ftruncate");
> > +    if (trunc && ftruncate(TT.out.fd, bs)) {
> > +      struct stat st;
> > +      if (fstat(TT.out.fd, &st) < 0 || S_ISREG(st.st_mode) ||
> S_ISDIR(st.st_mode)) {
> > +        perror_exit("unexpected ftruncate failure");
> > +      }
> > +    }
>
> What does truncating a directory do? Is there a valid use case where dd's
> target
> can be a directory? (How would that work?)
>
> Rob
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20200923/91385b15/attachment.htm>


More information about the Toybox mailing list