diff options
author | Karel Zak | 2006-12-07 00:25:44 +0100 |
---|---|---|
committer | Karel Zak | 2006-12-07 00:25:44 +0100 |
commit | 66ee8158b69525e12060ef558cb5d77feadab1dc (patch) | |
tree | 08b30f2d07df9213f5647bc6f60b5090a263ef43 /lib/carefulputc.c | |
parent | Imported from util-linux-2.10m tarball. (diff) | |
download | kernel-qcow2-util-linux-66ee8158b69525e12060ef558cb5d77feadab1dc.tar.gz kernel-qcow2-util-linux-66ee8158b69525e12060ef558cb5d77feadab1dc.tar.xz kernel-qcow2-util-linux-66ee8158b69525e12060ef558cb5d77feadab1dc.zip |
Imported from util-linux-2.10s tarball.
Diffstat (limited to 'lib/carefulputc.c')
-rw-r--r-- | lib/carefulputc.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/carefulputc.c b/lib/carefulputc.c new file mode 100644 index 000000000..932233772 --- /dev/null +++ b/lib/carefulputc.c @@ -0,0 +1,26 @@ +/* putc() for use in write and wall (that sometimes are sgid tty) */ +/* Avoid control characters in our locale, and also ASCII control characters. + Note that the locale of the recipient is unknown. */ +#include <stdio.h> +#include <ctype.h> +#include "carefulputc.h" + +#define iso8859x_iscntrl(c) \ + (((c) & 0x7f) < 0x20 || (c) == 0x7f) + +int +carefulputc(int c, FILE *fp) { + int ret; + + if (c == '\007' || c == '\t' || c == '\r' || c == '\n' || + (!iso8859x_iscntrl(c) && (isprint(c) || isspace(c)))) + ret = putc(c, fp); + else if ((c & 0x80) || !isprint(c^0x40)) + ret = fprintf(fp, "\\%3o", (unsigned char) c); + else { + ret = putc('^', fp); + if (ret != EOF) + ret = putc(c^0x40, fp); + } + return (ret < 0) ? EOF : 0; +} |