diff options
author | G.raud Meyer | 2011-04-05 11:31:03 +0200 |
---|---|---|
committer | G.raud Meyer | 2018-04-09 17:21:17 +0200 |
commit | 33785dd33ceaa61386d3aa29d3cd550315e05edc (patch) | |
tree | 503a8f177a244ccdc12b2dbb8878d7c1344ff38e /misc-utils/rename.c | |
parent | rename.1: describe interactive mode (diff) | |
download | kernel-qcow2-util-linux-33785dd33ceaa61386d3aa29d3cd550315e05edc.tar.gz kernel-qcow2-util-linux-33785dd33ceaa61386d3aa29d3cd550315e05edc.tar.xz kernel-qcow2-util-linux-33785dd33ceaa61386d3aa29d3cd550315e05edc.zip |
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().
Diffstat (limited to 'misc-utils/rename.c')
-rw-r--r-- | misc-utils/rename.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/misc-utils/rename.c b/misc-utils/rename.c index 032a039bf..c9add7780 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 <stdio.h> +#include <stdio_ext.h> #include <string.h> #include <stdlib.h> #include <errno.h> @@ -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); } |