From 7b4c7a681cc4c0a53dc8a8baf4853e921cfbf5de Mon Sep 17 00:00:00 2001 From: bigbiff Date: Thu, 1 Jan 2015 19:44:14 -0500 Subject: Update blkid to 2.25.0 Break libblkid into 4 libraries: libblkid, libuuid, libutil-linux and libfdisk. This should help in later patch updates. Change-Id: I680d9a7feb031e5c29a603e9c58aff4b65826262 --- libblkid/include/carefulputc.h | 67 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 libblkid/include/carefulputc.h (limited to 'libblkid/include/carefulputc.h') diff --git a/libblkid/include/carefulputc.h b/libblkid/include/carefulputc.h new file mode 100644 index 000000000..3a0ec5b66 --- /dev/null +++ b/libblkid/include/carefulputc.h @@ -0,0 +1,67 @@ +#ifndef UTIL_LINUX_CAREFUULPUTC_H +#define UTIL_LINUX_CAREFUULPUTC_H + +/* + * A putc() for use in write and wall (that sometimes are sgid tty). + * It avoids control characters in our locale, and also ASCII control + * characters. Note that the locale of the recipient is unknown. +*/ +#include +#include +#include + +static inline int fputc_careful(int c, FILE *fp, const char fail) +{ + int ret; + + if (isprint(c) || c == '\a' || c == '\t' || c == '\r' || c == '\n') + ret = putc(c, fp); + else if (!isascii(c)) + ret = fprintf(fp, "\\%3o", (unsigned char)c); + else { + ret = putc(fail, fp); + if (ret != EOF) + ret = putc(c ^ 0x40, fp); + } + return (ret < 0) ? EOF : 0; +} + +static inline void fputs_quoted(const char *data, FILE *out) +{ + const char *p; + + fputc('"', out); + for (p = data; p && *p; p++) { + if ((unsigned char) *p == 0x22 || /* " */ + (unsigned char) *p == 0x5c || /* \ */ + (unsigned char) *p == 0x60 || /* ` */ + (unsigned char) *p == 0x24 || /* $ */ + !isprint((unsigned char) *p) || + iscntrl((unsigned char) *p)) { + + fprintf(out, "\\x%02x", (unsigned char) *p); + } else + fputc(*p, out); + } + fputc('"', out); +} + +static inline void fputs_nonblank(const char *data, FILE *out) +{ + const char *p; + + for (p = data; p && *p; p++) { + if (isblank((unsigned char) *p) || + (unsigned char) *p == 0x5c || /* \ */ + !isprint((unsigned char) *p) || + iscntrl((unsigned char) *p)) { + + fprintf(out, "\\x%02x", (unsigned char) *p); + + } else + fputc(*p, out); + } +} + + +#endif /* _CAREFUULPUTC_H */ -- cgit v1.2.3