Re: [PATCH 3/4] dir: introduce file_size() to check the size of file
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Jun 8, 2016, 07:37 UTC
- Message-ID
- <CAPig+cTgnp3tm_S7ybDBiGfesw9mh3J4_OtEV7timnsgL0AGjA@mail.gmail.com>
- In-Reply-To
- <20160607205454.22576-3-pranit.bauva@gmail.com>
On Tue, Jun 7, 2016 at 4:54 PM, Pranit Bauva <pranit.bauva@gmail.com> wrote:
Show 5 quoted lines
> dir: introduce file_size() to check the size of file > > At times we require to see if the file is empty and get the size of the > file. By using stat we can get the file size without actually having to > open the file to check for its contents.
The sole caller of this function in patch 4/4 does so only to check if the file exists; it doesn't even care about the file's size, thus neither this function nor this patch seem justified and probably ought to be dropped unless some better and stronger justification can be shown.
Show 20 quoted lines
> Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
> ---
> diff --git a/dir.c b/dir.c
> @@ -2036,6 +2036,14 @@ int file_exists(const char *f)
> +ssize_t file_size(const char *filename)
> +{
> + struct stat st;
> + if (stat(filename, &st) < 0)
> + return -1;
> + return xsize_t(st.st_size);
> +}
> +
> diff --git a/dir.h b/dir.h
> @@ -248,6 +248,13 @@ extern void clear_exclude_list(struct exclude_list *el);
> +/*
> + * Return the size of the file `filename`. It returns -1 if error
> + * occurred, 0 if file is empty and a positive number denoting the size
> + * of the file.
> + */
> +extern ssize_t file_size(const char *);