Re: [PATCH v2 00/41] Add and use error_errno() and warning_errno()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 3, 2016 at 8:03 AM, Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> wrote:
> Changes are in
>
>   [01/41] usage.c: move format processing out of die_errno()
>   [02/41] usage.c: add warning_errno() and error_errno()
>   [12/41] builtin/update-index.c: prefer "err" to "errno" in process_lstat_error
>   [17/41] compat/win32/syslog.c: use warning_errno()
>   [27/41] grep.c: use error_errno()
>
> 12/41 is basically a revert with s/strerror(errno)/strerror(err)/.
> Interdiff from v1

The interdiff looks quite sensible. Thanks.


> -- 8< --
> diff --git a/builtin/update-index.c b/builtin/update-index.c
> index 0c539ed..b8b8522 100644
> --- a/builtin/update-index.c
> +++ b/builtin/update-index.c
> @@ -251,11 +251,11 @@ static int remove_one_path(const char *path)
>   *    succeeds.
>   *  - permission error. That's never ok.
>   */
> -static int process_lstat_error(const char *path)
> +static int process_lstat_error(const char *path, int err)
>  {
> -       if (errno == ENOENT || errno == ENOTDIR)
> +       if (err == ENOENT || err == ENOTDIR)
>                 return remove_one_path(path);
> -       return error_errno("lstat(\"%s\")", path);
> +       return error("lstat(\"%s\"): %s", path, strerror(err));
>  }
>
>  static int add_one_path(const struct cache_entry *old, const char *path, int len, struct stat *st)
> @@ -382,7 +382,7 @@ static int process_path(const char *path)
>          * what to do about the pathname!
>          */
>         if (lstat(path, &st) < 0)
> -               return process_lstat_error(path);
> +               return process_lstat_error(path, errno);
>
>         if (S_ISDIR(st.st_mode))
>                 return process_directory(path, len, &st);
> diff --git a/compat/win32/syslog.c b/compat/win32/syslog.c
> index 1c2ae18..6c7c9b6 100644
> --- a/compat/win32/syslog.c
> +++ b/compat/win32/syslog.c
> @@ -28,7 +28,7 @@ void syslog(int priority, const char *fmt, ...)
>         va_end(ap);
>
>         if (str_len < 0) {
> -               warning_errno("vsnprintf failed:");
> +               warning_errno("vsnprintf failed");
>                 return;
>         }
>
> diff --git a/grep.c b/grep.c
> index 87c1890..4f3779a 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -1732,7 +1732,7 @@ static int grep_source_load_file(struct grep_source *gs)
>         if (lstat(filename, &st) < 0) {
>         err_ret:
>                 if (errno != ENOENT)
> -                       error_errno(_("'%s'"), filename);
> +                       error_errno("'%s'", filename);
>                 return -1;
>         }
>         if (!S_ISREG(st.st_mode))
> diff --git a/usage.c b/usage.c
> index af1b7d1..1dad03f 100644
> --- a/usage.c
> +++ b/usage.c
> @@ -109,9 +109,8 @@ void NORETURN die(const char *err, ...)
>         va_end(params);
>  }
>
> -static const char *fmt_with_err(const char *fmt)
> +static const char *fmt_with_err(char *buf, int n, const char *fmt)
>  {
> -       static char fmt_with_err[1024];
>         char str_error[256], *err;
>         int i, j;
>
> @@ -129,12 +128,13 @@ static const char *fmt_with_err(const char *fmt)
>                 }
>         }
>         str_error[j] = 0;
> -       snprintf(fmt_with_err, sizeof(fmt_with_err), "%s: %s", fmt, str_error);
> -       return fmt_with_err;
> +       snprintf(buf, n, "%s: %s", fmt, str_error);
> +       return buf;
>  }
>
>  void NORETURN die_errno(const char *fmt, ...)
>  {
> +       char buf[1024];
>         va_list params;
>
>         if (die_is_recursing()) {
> @@ -144,16 +144,17 @@ void NORETURN die_errno(const char *fmt, ...)
>         }
>
>         va_start(params, fmt);
> -       die_routine(fmt_with_err(fmt), params);
> +       die_routine(fmt_with_err(buf, sizeof(buf), fmt), params);
>         va_end(params);
>  }
>
>  int error_errno(const char *fmt, ...)
>  {
> +       char buf[1024];
>         va_list params;
>
>         va_start(params, fmt);
> -       error_routine(fmt_with_err(fmt), params);
> +       error_routine(fmt_with_err(buf, sizeof(buf), fmt), params);
>         va_end(params);
>         return -1;
>  }
> @@ -171,10 +172,11 @@ int error(const char *err, ...)
>
>  void warning_errno(const char *warn, ...)
>  {
> +       char buf[1024];
>         va_list params;
>
>         va_start(params, warn);
> -       warn_routine(fmt_with_err(warn), params);
> +       warn_routine(fmt_with_err(buf, sizeof(buf), warn), params);
>         va_end(params);
>  }
>
> -- 8< --
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]