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

Rob Landley rob at landley.net
Wed Sep 23 04:47:58 PDT 2020


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



More information about the Toybox mailing list