From: G.raud Meyer Date: Tue, 5 Apr 2011 09:31:03 +0000 (+0200) Subject: rename: ask(): call __fpurge() to cater for multi-byte characters X-Git-Tag: v2.33-rc1~309^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=33785dd33ceaa61386d3aa29d3cd550315e05edc;p=thirdparty%2Futil-linux.git rename: ask(): call __fpurge() to cater for multi-byte characters Making a purge in cbreak mode also makes the code compatible with canonical mode. This can be useful in the case a shell, like bash, does not restore the tty state of stopped jobs before restarting them. An alternative fix to this minor shortcoming would be to retest the tty state each time inside ask(). --- diff --git a/misc-utils/rename.c b/misc-utils/rename.c index 032a039bfa..c9add77803 100644 --- a/misc-utils/rename.c +++ b/misc-utils/rename.c @@ -14,6 +14,7 @@ for i in $@; do N=`echo "$i" | sed "s/$FROM/$TO/g"`; mv "$i" "$N"; done * in cases involving special characters. Here a C version. */ #include +#include #include #include #include @@ -71,8 +72,15 @@ static int ask(char *name) } else { buf[0] = c; - if (c != '\n' && tty_cbreak) /* no purge necessary */ + if (c != '\n' && tty_cbreak) { + /* Possibly purge a multi-byte character; or do a + required purge of the rest of the line (including + the newline) if the tty has been put back in + canonical mode (for example by a shell after a + SIGTSTP signal). */ + __fpurge(stdin); printf("\n"); + } else if (c != '\n') while ((c = fgetc(stdin)) != '\n' && c != EOF); }