bug-readline
[Top][All Lists]
Advanced

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

[Bug-readline] Wrong use of fputs() in examples/rlcat.c


From: Pedro Giffuni
Subject: [Bug-readline] Wrong use of fputs() in examples/rlcat.c
Date: Wed, 3 May 2017 13:30:34 -0500
User-agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:52.0) Gecko/20100101 Thunderbird/52.0.1

Hello;


In FreeBSD we are still using libreadline-5.2 and we noticed you are expecting fputs() to return zero.

According to POSIX:

"Upon successful completion, fputs() shall return a non-negative number."

Apple's libc and recent FreeBSD return the last character written so this code will not work as expected.

A possible fix:

--- examples/rlcat.c    (revision 317755)
+++ examples/rlcat.c    (working copy)
@@ -138,7 +138,7 @@
       if (vflag && isascii ((unsigned char)c) && isprint((unsigned char)c) == 0)
        {
          x = rl_untranslate_keyseq (c);
-         if (fputs (x, stdout) != 0)
+         if (fputs (x, stdout) == EOF)
            return 1;
        }
       else if (putchar (c) == EOF)

___


Pedro.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]