Use guestfs___count_strings instead of custom versions in various places.

This commit is contained in:
Richard W.M. Jones
2013-02-20 20:03:47 +00:00
parent 907fbfff53
commit 9d6aa8b537
5 changed files with 14 additions and 54 deletions

View File

@@ -373,8 +373,6 @@ static int is_md (char *device);
static char **parents_of_md (char *device);
static char **parents_of_vg (char *vg);
static size_t count_strings (char **strings);
static void
do_output_title (void)
{
@@ -813,7 +811,7 @@ parents_of_vg (char *vg)
if (!pvuuids)
exit (EXIT_FAILURE);
n = count_strings (pvuuids);
n = guestfs___count_strings (pvuuids);
ret = malloc ((n + 1) * sizeof (char *));
if (!ret) {
@@ -1099,13 +1097,3 @@ do_output_end (void)
}
free (rows);
}
static size_t
count_strings (char **strings)
{
size_t i;
for (i = 0; strings[i] != NULL; ++i)
;
return i;
}

View File

@@ -59,7 +59,6 @@ static void output_mountpoints (xmlTextWriterPtr xo, char *root);
static void output_filesystems (xmlTextWriterPtr xo, char *root);
static void output_drive_mappings (xmlTextWriterPtr xo, char *root);
static void output_applications (xmlTextWriterPtr xo, char *root);
static size_t count_strings (char *const*argv);
static void do_xpath (const char *query);
static void __attribute__((noreturn))
@@ -547,7 +546,8 @@ output_mountpoints (xmlTextWriterPtr xo, char *root)
/* Sort by key length, shortest key first, and then name, so the
* output is stable.
*/
qsort (mountpoints, count_strings (mountpoints) / 2, 2 * sizeof (char *),
qsort (mountpoints, guestfs___count_strings (mountpoints) / 2,
2 * sizeof (char *),
compare_keys_len);
XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "mountpoints"));
@@ -581,7 +581,7 @@ output_filesystems (xmlTextWriterPtr xo, char *root)
exit (EXIT_FAILURE);
/* Sort by name so the output is stable. */
qsort (filesystems, count_strings (filesystems), sizeof (char *),
qsort (filesystems, guestfs___count_strings (filesystems), sizeof (char *),
compare_keys);
XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "filesystems"));
@@ -645,7 +645,7 @@ output_drive_mappings (xmlTextWriterPtr xo, char *root)
/* Sort by key. */
qsort (drive_mappings,
count_strings (drive_mappings) / 2, 2 * sizeof (char *),
guestfs___count_strings (drive_mappings) / 2, 2 * sizeof (char *),
compare_keys_nocase);
XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "drive_mappings"));
@@ -750,16 +750,6 @@ output_applications (xmlTextWriterPtr xo, char *root)
XMLERROR (-1, xmlTextWriterEndElement (xo));
}
static size_t
count_strings (char *const *argv)
{
size_t c;
for (c = 0; argv[c]; ++c)
;
return c;
}
/* Run an XPath query on XML on stdin, print results to stdout. */
static void
do_xpath (const char *query)

View File

@@ -376,16 +376,6 @@ compare_keys_len (const void *p1, const void *p2)
return strlen (key1) - strlen (key2);
}
static size_t
count_strings (char *const *argv)
{
size_t i;
for (i = 0; argv[i]; ++i)
;
return i;
}
/* virt-rescue --suggest flag does a kind of inspection on the
* drives and suggests mount commands that you should use.
*/
@@ -450,7 +440,7 @@ do_suggestion (struct drv *drvs)
/* Sort by key length, shortest key first, so that we end up
* mounting the filesystems in the correct order.
*/
qsort (mps, count_strings (mps) / 2, 2 * sizeof (char *),
qsort (mps, guestfs___count_strings (mps) / 2, 2 * sizeof (char *),
compare_keys_len);
for (j = 0; mps[j] != NULL; j += 2)

View File

@@ -31,4 +31,7 @@ test_charset_fidelity_CFLAGS = \
$(WARN_CFLAGS) $(WERROR_CFLAGS) \
$(GPROF_CFLAGS) $(GCOV_CFLAGS)
test_charset_fidelity_LDADD = \
$(top_builddir)/src/libguestfs.la
$(top_builddir)/src/libutils.la \
$(top_builddir)/src/libguestfs.la \
$(LIBXML2_LIBS) \
$(LIBVIRT_LIBS)

View File

@@ -68,7 +68,6 @@ static void test_latin1 (guestfs_h *g, const struct filesystem *fs);
static void test_latin2 (guestfs_h *g, const struct filesystem *fs);
static void test_chinese (guestfs_h *g, const struct filesystem *fs);
static void ignore_lost_and_found (char **);
static size_t count_strings (char **);
static int feature_available (guestfs_h *g, const char *feature);
int
@@ -196,7 +195,7 @@ test_ascii (guestfs_h *g, const struct filesystem *fs)
if (files == NULL)
exit (EXIT_FAILURE);
ignore_lost_and_found (files);
count = count_strings (files);
count = guestfs___count_strings (files);
if (fs->fs_case_insensitive) { /* case insensitive */
if (count != 2)
@@ -261,7 +260,7 @@ test_latin1 (guestfs_h *g, const struct filesystem *fs)
if (files == NULL)
exit (EXIT_FAILURE);
ignore_lost_and_found (files);
count = count_strings (files);
count = guestfs___count_strings (files);
if (fs->fs_case_insensitive) { /* case insensitive */
if (count != 1)
@@ -323,7 +322,7 @@ test_latin2 (guestfs_h *g, const struct filesystem *fs)
if (files == NULL)
exit (EXIT_FAILURE);
ignore_lost_and_found (files);
count = count_strings (files);
count = guestfs___count_strings (files);
if (fs->fs_case_insensitive) { /* case insensitive */
if (count != 1)
@@ -388,7 +387,7 @@ test_chinese (guestfs_h *g, const struct filesystem *fs)
if (files == NULL)
exit (EXIT_FAILURE);
ignore_lost_and_found (files);
count = count_strings (files);
count = guestfs___count_strings (files);
if (count != nr_filenames)
error (EXIT_FAILURE, 0,
@@ -429,16 +428,6 @@ ignore_lost_and_found (char **files)
files[j] = NULL;
}
static size_t
count_strings (char **argv)
{
size_t argc;
for (argc = 0; argv[argc] != NULL; ++argc)
;
return argc;
}
static int
feature_available (guestfs_h *g, const char *feature)
{