From 6a14f1c2502f58ff7bed8cb451f95a83f5ee920a Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 24 Sep 2009 10:59:01 +0200 Subject: [PATCH] avoid use of all ctype macros * cfg.mk (disable_temporarily): Don't disable sc_avoid_ctype_macros. * fish/tilde.c: Remove unnecessary inclusion of ctype.h. * bootstrap: Add gnulib's c-ctype module to the list. * daemon/m4/gnulib-cache.m4: Likewise. * daemon/ext2.c: Include "c-ctype.h", not . Use c_isspace, etc, rather than isspace. * daemon/guestfsd.c: Likewise. * daemon/lvm.c: Likewise. * daemon/proto.c: Likewise. * fish/fish.c: Likewise. * fish/tilde.c: Likewise. * src/generator.ml: Likewise. * src/guestfs.c: Likewise. * examples/to-xml.c: Likewise. * examples/Makefile.am (to_xml_CPPFLAGS): Add -I$(top_srcdir)/gnulib/lib so inclusion of "c-ctype.h" works. (to_xml_CPPFLAGS): Rename from to_xml_CFLAGS. --- bootstrap | 1 + cfg.mk | 1 - daemon/ext2.c | 8 ++++---- daemon/guestfsd.c | 4 ++-- daemon/lvm.c | 6 +++--- daemon/m4/gnulib-cache.m4 | 3 ++- daemon/proto.c | 4 ++-- examples/Makefile.am | 4 +++- examples/to-xml.c | 4 ++-- fish/fish.c | 6 +++--- fish/tilde.c | 1 - src/generator.ml | 10 +++++----- src/guestfs.c | 4 ++-- 13 files changed, 29 insertions(+), 27 deletions(-) diff --git a/bootstrap b/bootstrap index 1e32517..c92d1e1 100755 --- a/bootstrap +++ b/bootstrap @@ -58,6 +58,7 @@ gnulib_tool=$GNULIB_SRCDIR/gnulib-tool modules=' arpa_inet +c-ctype closeout gitlog-to-changelog gnu-make diff --git a/cfg.mk b/cfg.mk index 09a3231..134725a 100644 --- a/cfg.mk +++ b/cfg.mk @@ -50,7 +50,6 @@ disable_temporarily = \ sc_unmarked_diagnostics \ sc_prohibit_ctype_h \ sc_prohibit_asprintf \ - sc_avoid_ctype_macros \ sc_avoid_write # Avoid uses of write(2). Either switch to streams (fwrite), or use diff --git a/daemon/ext2.c b/daemon/ext2.c index a26891b..0021a06 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -21,10 +21,10 @@ #include #include #include -#include #include "../src/guestfs_protocol.h" #include "daemon.h" +#include "c-ctype.h" #include "actions.h" char ** @@ -72,7 +72,7 @@ do_tune2fs_l (const char *device) if (colon) { *colon = '\0'; - do { colon++; } while (*colon && isspace (*colon)); + do { colon++; } while (*colon && c_isspace (*colon)); if (add_string (&ret, &size, &alloc, p) == -1) { free (out); @@ -202,7 +202,7 @@ do_get_e2uuid (const char *device) } p += 17; - while (*p && isspace (*p)) + while (*p && c_isspace (*p)) p++; if (!*p) { reply_with_error ("malformed Filesystem UUID in the output of tune2fs -l"); @@ -212,7 +212,7 @@ do_get_e2uuid (const char *device) /* Now 'p' hopefully points to the start of the UUID. */ q = p; - while (*q && (isxdigit (*q) || *q == '-')) + while (*q && (c_isxdigit (*q) || *q == '-')) q++; if (!*q) { reply_with_error ("malformed Filesystem UUID in the output of tune2fs -l"); diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index e3b8883..8c39c39 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -34,10 +34,10 @@ #include #include #include -#include #include #include +#include "c-ctype.h" #include "daemon.h" static char *read_cmdline (void); @@ -835,7 +835,7 @@ print_shell_quote (FILE *stream, const struct printf_info *info ATTRIBUTE_UNUSED, const void *const *args) { -#define SAFE(c) (isalnum((c)) || \ +#define SAFE(c) (c_isalnum((c)) || \ (c) == '/' || (c) == '-' || (c) == '_' || (c) == '.') int i, len; const char *str = *((const char **) (args[0])); diff --git a/daemon/lvm.c b/daemon/lvm.c index 742b40b..9865bb2 100644 --- a/daemon/lvm.c +++ b/daemon/lvm.c @@ -22,9 +22,9 @@ #include #include #include -#include #include "daemon.h" +#include "c-ctype.h" #include "actions.h" /* LVM actions. Keep an eye on liblvm, although at the time @@ -49,12 +49,12 @@ convert_lvm_output (char *out, const char *prefix) pend++; } - while (*p && isspace (*p)) /* Skip any leading whitespace. */ + while (*p && c_isspace (*p)) /* Skip any leading whitespace. */ p++; /* Sigh, skip trailing whitespace too. "pvs", I'm looking at you. */ len = strlen (p)-1; - while (*p && isspace (p[len])) + while (*p && c_isspace (p[len])) p[len--] = '\0'; if (!*p) { /* Empty line? Skip it. */ diff --git a/daemon/m4/gnulib-cache.m4 b/daemon/m4/gnulib-cache.m4 index bd6cf61..df69113 100644 --- a/daemon/m4/gnulib-cache.m4 +++ b/daemon/m4/gnulib-cache.m4 @@ -15,11 +15,12 @@ # Specification in the form of a command-line invocation: -# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --with-tests --no-libtool --macro-prefix=gl hash ignore-value manywarnings warnings +# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --with-tests --no-libtool --macro-prefix=gl c-ctype hash ignore-value manywarnings warnings # Specification in the form of a few gnulib-tool.m4 macro invocations: gl_LOCAL_DIR([]) gl_MODULES([ + c-ctype hash ignore-value manywarnings diff --git a/daemon/proto.c b/daemon/proto.c index c22bbee..a0d3736 100644 --- a/daemon/proto.c +++ b/daemon/proto.c @@ -24,11 +24,11 @@ #include #include #include -#include #include /* defines MIN */ #include #include +#include "c-ctype.h" #include "ignore-value.h" #include "daemon.h" @@ -96,7 +96,7 @@ main_loop (int _sock) printf (" "); printf ("|"); for (j = i; j < MIN (i+16, len); ++j) - if (isprint (buf[j])) + if (c_isprint (buf[j])) printf ("%c", buf[j]); else printf ("."); diff --git a/examples/Makefile.am b/examples/Makefile.am index fb3d656..adbb934 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -7,7 +7,9 @@ hello_CFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src -Wall hello_LDADD = $(top_builddir)/src/libguestfs.la to_xml_SOURCES = to-xml.c -to_xml_CFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src -Wall +to_xml_CPPFLAGS = \ + -I$(top_srcdir)/gnulib/lib \ + -I$(top_srcdir)/src -I$(top_builddir)/src -Wall to_xml_LDADD = $(top_builddir)/src/libguestfs.la CLEANFILES = $(noinst_PROGRAMS) diff --git a/examples/to-xml.c b/examples/to-xml.c index 6d0a1df..e9ea063 100644 --- a/examples/to-xml.c +++ b/examples/to-xml.c @@ -16,9 +16,9 @@ #include #include #include -#include #include +#include "c-ctype.h" /* Note that if any API call fails, we can just exit. The * standard error handler will have printed the error message @@ -149,7 +149,7 @@ display_partitions (guestfs_h *g, const char *dev) * That's a limitation of sorts of the Linux kernel. (Actually, * we could do this if we add the kpartx program to libguestfs). */ - if (strncmp (dev, "/dev/sd", 7) != 0 || isdigit (dev[strlen(dev)-1])) { + if (strncmp (dev, "/dev/sd", 7) != 0 || c_isdigit (dev[strlen(dev)-1])) { printf ("\n", dev); return; } diff --git a/fish/fish.c b/fish/fish.c index f8c0483..3300536 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -38,6 +37,7 @@ #include #include "fish.h" +#include "c-ctype.h" #include "closeout.h" #include "progname.h" @@ -579,7 +579,7 @@ script (int prompt) /* Skip any initial whitespace before the command. */ again: - while (*buf && isspace (*buf)) + while (*buf && c_isspace (*buf)) buf++; if (!*buf) continue; @@ -1127,7 +1127,7 @@ parse_string_list (const char *str) * as separate fragments because we can't just copy it: we have to remove * the \. */ - while (*p && (!isblank (*p) || in_quote)) { + while (*p && (!c_isblank (*p) || in_quote)) { const char *end = p; /* Check if the fragment starts with a quote */ diff --git a/fish/tilde.c b/fish/tilde.c index 4085417..1c52d3e 100644 --- a/fish/tilde.c +++ b/fish/tilde.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include diff --git a/src/generator.ml b/src/generator.ml index 6f77e4b..4f03c06 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -4956,11 +4956,11 @@ and generate_daemon_actions () = pr "#include \n"; pr "#include \n"; pr "#include \n"; - pr "#include \n"; pr "#include \n"; pr "#include \n"; pr "\n"; pr "#include \"daemon.h\"\n"; + pr "#include \"c-ctype.h\"\n"; pr "#include \"../src/guestfs_protocol.h\"\n"; pr "#include \"actions.h\"\n"; pr "\n"; @@ -5186,7 +5186,7 @@ and generate_daemon_actions () = pr " fprintf (stderr, \"%%s: failed: passed a NULL string\\n\", __func__);\n"; pr " return -1;\n"; pr " }\n"; - pr " if (!*str || isspace (*str)) {\n"; + pr " if (!*str || c_isspace (*str)) {\n"; pr " fprintf (stderr, \"%%s: failed: passed a empty string or one beginning with whitespace\\n\", __func__);\n"; pr " return -1;\n"; pr " }\n"; @@ -5288,7 +5288,7 @@ and generate_daemon_actions () = pr " pend++;\n"; pr " }\n"; pr "\n"; - pr " while (*p && isspace (*p)) /* Skip any leading whitespace. */\n"; + pr " while (*p && c_isspace (*p)) /* Skip any leading whitespace. */\n"; pr " p++;\n"; pr "\n"; pr " if (!*p) { /* Empty line? Skip it. */\n"; @@ -6073,9 +6073,9 @@ and generate_fish_cmds () = pr "#include \n"; pr "#include \n"; pr "#include \n"; - pr "#include \n"; pr "\n"; pr "#include \n"; + pr "#include \"c-ctype.h\"\n"; pr "#include \"fish.h\"\n"; pr "\n"; @@ -6193,7 +6193,7 @@ and generate_fish_cmds () = | name, FBuffer -> pr " printf (\"%%s%s: \", indent);\n" name; pr " for (i = 0; i < %s->%s_len; ++i)\n" typ name; - pr " if (isprint (%s->%s[i]))\n" typ name; + pr " if (c_isprint (%s->%s[i]))\n" typ name; pr " printf (\"%%s%%c\", indent, %s->%s[i]);\n" typ name; pr " else\n"; pr " printf (\"%%s\\\\x%%02x\", indent, %s->%s[i]);\n" typ name; diff --git a/src/guestfs.c b/src/guestfs.c index 03089ea..e49f57a 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -62,6 +61,7 @@ #include "guestfs.h" #include "guestfs-internal-actions.h" #include "guestfs_protocol.h" +#include "c-ctype.h" #include "ignore-value.h" #ifdef HAVE_GETTEXT @@ -2136,7 +2136,7 @@ recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn) printf (" "); printf ("|"); for (j = i; j < MIN (i+16, nr); ++j) - if (isprint ((*(char **)buf_rtn)[j])) + if (c_isprint ((*(char **)buf_rtn)[j])) printf ("%c", (*(char **)buf_rtn)[j]); else printf ("."); -- 1.8.3.1