On Sun, Dec 04, 2016 at 09:55:11PM -0800, Michael Forney wrote:
> ---
>  tail.c | 16 +++++++---------
>  1 file changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/tail.c b/tail.c
> index ad97308..000be62 100644
> --- a/tail.c
> +++ b/tail.c
> @@ -133,7 +133,7 @@ main(int argc, char *argv[])
>                       }
>                       if (many)
>                               printf("%s==> %s <==\n", newline ? "\n" : "", 
> *argv);
> -                     if (stat(*argv, &st1) < 0)
> +                     if (fstat(fileno(fp), &st1) < 0)
>                               eprintf("stat %s:", *argv);

The error message should be "fstat" here instead of "stat".

>                       if (!(S_ISFIFO(st1.st_mode) || S_ISREG(st1.st_mode)))
>                               fflag = 0;
> @@ -153,15 +153,13 @@ main(int argc, char *argv[])
>                               if (ferror(fp))
>                                       eprintf("fgetc %s:", *argv);
>                               clearerr(fp);
> -                             /* ignore error in case file was removed, we 
> continue
> -                              * tracking the existing open file descriptor */
> -                             if (!stat(*argv, &st2)) {
> -                                     if (st2.st_size < st1.st_size) {
> -                                             fprintf(stderr, "%s: file 
> truncated\n", *argv);
> -                                             rewind(fp);
> -                                     }
> -                                     st1 = st2;
> +                             if (fstat(fileno(fp), &st2) < 0)
> +                                     eprintf("fstat:");
> +                             if (st2.st_size < st1.st_size) {
> +                                     fprintf(stderr, "%s: file truncated\n", 
> *argv);
> +                                     rewind(fp);
>                               }
> +                             st1 = st2;
>                               sleep(1);
>                       }
>               }
> -- 
> 2.11.0
> 
> 

-- 
Kind regards,
Hiltjo

Reply via email to