From 33785dd33ceaa61386d3aa29d3cd550315e05edc Mon Sep 17 00:00:00 2001 From: "G.raud Meyer" Date: Tue, 5 Apr 2011 11:31:03 +0200 Subject: [PATCH] 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(). --- misc-utils/rename.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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); } -- 2.47.3