The first c-set cleans up the list of excluded syntax-checks.
The second enables the sc_avoid_ctype_macros test and changes
each use of a ctype macro like isspace to c_isspace.
This makes it so such tests (often parsing-related) is locale-independent.
Otherwise, in some odd corner cases (combination of non-C locale
and perverted inputs), I suspect that libguestfs tools would mistakenly
accept surprising inputs.
From 0ca36888c6975ffa7e03df11bf8ded42156939c7 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Thu, 24 Sep 2009 09:34:53 +0200
Subject: [PATCH libguestfs 1/2] maint: prune dead wood from list of skipped syntax-check
rules
* cfg.mk (local-checks-to-skip): Remove now-passing and
no-longer-relevant rule names.
---
cfg.mk | 19 +------------------
1 files changed, 1 insertions(+), 18 deletions(-)
diff --git a/cfg.mk b/cfg.mk
index 1d02b24..09a3231 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -27,46 +27,29 @@ url_dir_list = \
# Tests not to run as part of "make distcheck".
local-checks-to-skip = \
sc_po_check \
- changelog-check \
- check-AUTHORS \
- makefile-check \
- makefile_path_separator_check \
- patch-check \
sc_GPL_version \
- sc_always_defined_macros \
- sc_cast_of_alloca_return_value \
- sc_dd_max_sym_length \
sc_error_exit_success \
sc_file_system \
- sc_immutable_NEWS \
sc_makefile_path_separator_check \
sc_obsolete_symbols \
- sc_prohibit_S_IS_definition \
sc_prohibit_atoi_atof \
- sc_prohibit_jm_in_m4 \
sc_prohibit_quote_without_use \
sc_prohibit_quotearg_without_use \
sc_prohibit_stat_st_blocks \
sc_prohibit_strcmp_and_strncmp \
sc_prohibit_strcmp \
- sc_root_tests \
sc_space_tab \
- sc_sun_os_names \
- sc_system_h_headers \
- sc_tight_scope \
sc_two_space_separator_in_usage \
sc_error_message_uppercase \
sc_program_name \
- sc_require_test_exit_idiom \
- sc_makefile_check \
$(disable_temporarily) \
sc_useless_cpp_parens
disable_temporarily = \
+ sc_makefile_check \
sc_unmarked_diagnostics \
sc_prohibit_ctype_h \
sc_prohibit_asprintf \
- sc_m4_quote_check \
sc_avoid_ctype_macros \
sc_avoid_write
--
1.6.5.rc2.177.ga9dd6
From 6a14f1c2502f58ff7bed8cb451f95a83f5ee920a Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Thu, 24 Sep 2009 10:59:01 +0200
Subject: [PATCH libguestfs 2/2] 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 <ctype.h>.
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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include <ctype.h>
#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 <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include <ctype.h>
#include <signal.h>
#include <printf.h>
+#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 <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <ctype.h>
#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 <string.h>
#include <unistd.h>
#include <errno.h>
-#include <ctype.h>
#include <sys/param.h> /* defines MIN */
#include <rpc/types.h>
#include <rpc/xdr.h>
+#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 <stdint.h>
#include <inttypes.h>
#include <unistd.h>
-#include <ctype.h>
#include <guestfs.h>
+#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 ("<vm-image dev=\"%s\"/>\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 <getopt.h>
#include <signal.h>
#include <assert.h>
-#include <ctype.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -38,6 +37,7 @@
#include <guestfs.h>
#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 <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <ctype.h>
#include <assert.h>
#include <pwd.h>
#include <sys/types.h>
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 <stdlib.h>\n";
pr "#include <string.h>\n";
pr "#include <inttypes.h>\n";
- pr "#include <ctype.h>\n";
pr "#include <rpc/types.h>\n";
pr "#include <rpc/xdr.h>\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 <stdlib.h>\n";
pr "#include <string.h>\n";
pr "#include <inttypes.h>\n";
- pr "#include <ctype.h>\n";
pr "\n";
pr "#include <guestfs.h>\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 <stdarg.h>
#include <stddef.h>
#include <unistd.h>
-#include <ctype.h>
#include <string.h>
#include <fcntl.h>
#include <time.h>
@@ -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.6.5.rc2.177.ga9dd6