Bug#761300: libc6: Printf("%c",'x') does not follow stdio
Am 14.10.2018 um 13:38 schrieb Florian Weimer: > * Sven Joachim: > >> This result is rather surprising. After all, "putchar('x')" is supposed >> to do the same as "putc('x', stdout)", but here it does not. > > Can you reproduce this with something newer than 2.13-38+rpi2+deb7u3? > Or on something else besides armhf? Surely, I tested 2.27-6 on amd64. Cheers, Sven
Bug#761300: libc6: Printf("%c",'x') does not follow stdio
* Sven Joachim: > This result is rather surprising. After all, "putchar('x')" is supposed > to do the same as "putc('x', stdout)", but here it does not. Can you reproduce this with something newer than 2.13-38+rpi2+deb7u3? Or on something else besides armhf?
Bug#761300: libc6: Printf("%c",'x') does not follow stdio
Control: retitle -1 libc6: putchar does not follow stdio On 2014-09-12 09:10 -0700, Thomas D. Dean wrote: > Package: libc6 > Version: 2.13-38+rpi2+deb7u3 > Severity: normal > > Dear Maintainer, > >* What led up to the situation? > > Redirecting stdout in C code does not work for printf("%c",'x') > I ssh into the system. I want to redirect all output to stdout to > the local terminal. This works as expected for everything except > when printing a single character. > >* What exactly did you do (or not do) that was effective (or > ineffective)? > > FILE *display_fp; > if ((display_fp = fopen("/dev/tty1","r+")) == NULL) { > perror("Open /dev/tty1"); > return -1; > } > stdout = display_fp; > > Then, > > printf("%s","asdfasdf"); /* output to /dev/tty1 */ > printf("%c",'x'); /* output to original terminal */ > >* What was the outcome of this action? > > All the output except for the "%c" case went to /dev/tty1. The > output in the "%c" case went to the ssh terminal It is actually a bit more subtle than that, as gcc has its own printf builtin function which comes into play. Compiling the program with -fno-builtin in fact makes it work as intended (at least with glibc 2.27-6). Looking closer, I found that with -fno-builtin printf("%c",'x'); works putc('x', stdout); works putchar('x'); exhibits the bug This result is rather surprising. After all, "putchar('x')" is supposed to do the same as "putc('x', stdout)", but here it does not. I'm attaching the whole program, so that future researchers have less to copy and paste. Cheers, Sven #include #include int main (int argc, char** argv) { FILE *display_fp; if ((display_fp = fopen("/dev/tty1","r+")) == NULL) { perror("Open /dev/tty1"); return -1; } stdout = display_fp; printf("%s","asdfasdf"); /* output to /dev/tty1 */ putchar('x'); /* output to original terminal */ }
Processed: Re: Bug#761300: libc6: Printf("%c",'x') does not follow stdio
Processing control commands: > retitle -1 libc6: putchar does not follow stdio Bug #761300 [libc6] libc6: Printf("%c",'x') does not follow stdio Changed Bug title to 'libc6: putchar does not follow stdio' from 'libc6: Printf("%c",'x') does not follow stdio'. -- 761300: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=761300 Debian Bug Tracking System Contact ow...@bugs.debian.org with problems
Bug#761300: libc6: Printf(%c,'x') does not follow stdio
Package: libc6 Version: 2.13-38+rpi2+deb7u3 Severity: normal Dear Maintainer, * What led up to the situation? Redirecting stdout in C code does not work for printf(%c,'x') I ssh into the system. I want to redirect all output to stdout to the local terminal. This works as expected for everything except when printing a single character. * What exactly did you do (or not do) that was effective (or ineffective)? FILE *display_fp; if ((display_fp = fopen(/dev/tty1,r+)) == NULL) { perror(Open /dev/tty1); return -1; } stdout = display_fp; Then, printf(%s,asdfasdf); /* output to /dev/tty1 */ printf(%c,'x'); /* output to original terminal */ * What was the outcome of this action? All the output except for the %c case went to /dev/tty1. The output in the %c case went to the ssh terminal * What outcome did you expect instead? I expected all the output to go to /dev/tty1 -- System Information: Debian Release: 7.6 Architecture: armhf (armv6l) Kernel: Linux 3.12.22+ (PREEMPT) Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=ANSI_X3.4-1968) (ignored: L C_ALL set to C) Shell: /bin/sh linked to /bin/dash Versions of packages libc6 depends on: ii libc-bin 2.13-38+rpi2+deb7u3 ii libgcc1 1:4.7.2-5+rpi1 libc6 recommends no packages. Versions of packages libc6 suggests: ii debconf [debconf-2.0] 1.5.49 pn glibc-doc none ii locales2.13-38+rpi2+deb7u3 -- debconf information: glibc/upgrade: true glibc/restart-services: * libraries/restart-without-asking: true glibc/disable-screensaver: glibc/restart-failed: -- To UNSUBSCRIBE, email to debian-glibc-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org Archive: https://lists.debian.org/54131afb.3030...@speakeasy.net