diff mbox series

iconv: restore verbosity with unrecognized encoding names (bug 30694)

Message ID mvmfs52kdho.fsf@suse.de
State New
Headers show
Series iconv: restore verbosity with unrecognized encoding names (bug 30694) | expand

Commit Message

Andreas Schwab Aug. 1, 2023, 3:07 p.m. UTC
Commit 91927b7c76 ("Rewrite iconv option parsing [BZ #19519]") changed the
iconv program to call __gconv_open directly instead of the iconv_open
wrapper, but the former does not set errno.  Update the caller to
interpret the return codes like iconv_open does.
---
 iconv/iconv_prog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Arjun Shankar Aug. 2, 2023, 11:05 a.m. UTC | #1
Hi Andreas,

> Commit 91927b7c76 ("Rewrite iconv option parsing [BZ #19519]") changed the
> iconv program to call __gconv_open directly instead of the iconv_open
> wrapper, but the former does not set errno.  Update the caller to
> interpret the return codes like iconv_open does.
> ---
>  iconv/iconv_prog.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/iconv/iconv_prog.c b/iconv/iconv_prog.c
> index bee898c63c..cf32cf9b44 100644
> --- a/iconv/iconv_prog.c
> +++ b/iconv/iconv_prog.c
> @@ -187,7 +187,7 @@ main (int argc, char *argv[])
>
>        if (res != __GCONV_OK)
>         {
> -         if (errno == EINVAL)
> +         if (res == __GCONV_NOCONV || res == __GCONV_NODB)
>             {
>               /* Try to be nice with the user and tell her which of the
>                  two encoding names is wrong.  This is possible because

OK. errno could have changed in ways we don't know since the
assignment we actually care about, but res contains the correct reason
returned by __gconv_open. This also aligns with iconv_open where we
set errno (as required by the standard) after checking the value of
res.

This looks good to me. Thanks!

Reviewed-by: Arjun Shankar <arjun@redhat.com>
diff mbox series

Patch

diff --git a/iconv/iconv_prog.c b/iconv/iconv_prog.c
index bee898c63c..cf32cf9b44 100644
--- a/iconv/iconv_prog.c
+++ b/iconv/iconv_prog.c
@@ -187,7 +187,7 @@  main (int argc, char *argv[])
 
       if (res != __GCONV_OK)
 	{
-	  if (errno == EINVAL)
+	  if (res == __GCONV_NOCONV || res == __GCONV_NODB)
 	    {
 	      /* Try to be nice with the user and tell her which of the
 		 two encoding names is wrong.  This is possible because