From 42bffcd00aac31f9f844a2a2e9b91faa4509408c Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 1 Feb 2013 14:16:51 +0000 Subject: [PATCH] Remove all occurrences of the bad_cast (lowercase) function. Not to be confused with the libxml2 macro 'BAD_CAST' which converts from 'signed char *' to 'unsigned char *'. The 'bad_cast' function was defined and used all over the place as a replacement for a '(char *)' cast. I think it is better to make these casts explicit, instead of hiding them in an obscure function. --- align/scan.c | 8 +------- cat/virt-cat.c | 8 +------- cat/virt-filesystems.c | 8 +------- cat/virt-ls.c | 8 +------- df/main.c | 8 +------- edit/virt-edit.c | 8 +------- fish/events.c | 2 +- fish/fish.c | 2 +- fish/fish.h | 6 ------ fish/options.h | 2 +- fish/prep.c | 2 +- format/format.c | 8 +------- fuse/Makefile.am | 3 +-- fuse/guestmount.c | 1 - fuse/guestmount.h | 36 ------------------------------------ inspector/virt-inspector.c | 8 +------- rescue/virt-rescue.c | 8 +------- src/private-data.c | 8 +------- 18 files changed, 15 insertions(+), 119 deletions(-) delete mode 100644 fuse/guestmount.h diff --git a/align/scan.c b/align/scan.c index 449d3ff77..8cec33051 100644 --- a/align/scan.c +++ b/align/scan.c @@ -53,12 +53,6 @@ int inspector = 0; static int quiet = 0; /* --quiet */ -static inline char * -bad_cast (char const *s) -{ - return (char *) s; -} - static void __attribute__((noreturn)) usage (int status) { @@ -130,7 +124,7 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } - argv[0] = bad_cast (program_name); + argv[0] = (char *) program_name; for (;;) { c = getopt_long (argc, argv, options, long_options, &option_index); diff --git a/cat/virt-cat.c b/cat/virt-cat.c index 5ea461e90..f8485d00d 100644 --- a/cat/virt-cat.c +++ b/cat/virt-cat.c @@ -48,12 +48,6 @@ int inspector = 1; static int is_windows (guestfs_h *g, const char *root); static char *windows_path (guestfs_h *g, const char *root, const char *filename); -static inline char * -bad_cast (char const *s) -{ - return (char *) s; -} - static void __attribute__((noreturn)) usage (int status) { @@ -122,7 +116,7 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } - argv[0] = bad_cast (program_name); + argv[0] = (char *) program_name; for (;;) { c = getopt_long (argc, argv, options, long_options, &option_index); diff --git a/cat/virt-filesystems.c b/cat/virt-filesystems.c index 9c3701868..09fc39b0f 100644 --- a/cat/virt-filesystems.c +++ b/cat/virt-filesystems.c @@ -80,12 +80,6 @@ static void do_output_end (void); static struct guestfs_lvm_pv_list *get_pvs (void); static void free_pvs (void); -static inline char * -bad_cast (char const *s) -{ - return (char *) s; -} - static void __attribute__((noreturn)) usage (int status) { @@ -197,7 +191,7 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } - argv[0] = bad_cast (program_name); + argv[0] = (char *) program_name; for (;;) { c = getopt_long (argc, argv, options, long_options, &option_index); diff --git a/cat/virt-ls.c b/cat/virt-ls.c index f47cf37b9..107237111 100644 --- a/cat/virt-ls.c +++ b/cat/virt-ls.c @@ -84,12 +84,6 @@ static int is_sock (int64_t mode); static void free_strings (char **); -static inline char * -bad_cast (char const *s) -{ - return (char *) s; -} - static void __attribute__((noreturn)) usage (int status) { @@ -191,7 +185,7 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } - argv[0] = bad_cast (program_name); + argv[0] = (char *) program_name; for (;;) { c = getopt_long (argc, argv, options, long_options, &option_index); diff --git a/df/main.c b/df/main.c index ce32a37a1..6a7c66c3d 100644 --- a/df/main.c +++ b/df/main.c @@ -59,12 +59,6 @@ int uuid = 0; /* --uuid */ static char *make_display_name (struct drv *drvs); -static inline char * -bad_cast (char const *s) -{ - return (char *) s; -} - static void __attribute__((noreturn)) usage (int status) { @@ -139,7 +133,7 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } - argv[0] = bad_cast (program_name); + argv[0] = (char *) program_name; for (;;) { c = getopt_long (argc, argv, options, long_options, &option_index); diff --git a/edit/virt-edit.c b/edit/virt-edit.c index c34f044d4..0ff35e0cd 100644 --- a/edit/virt-edit.c +++ b/edit/virt-edit.c @@ -62,12 +62,6 @@ static char *windows_path (guestfs_h *g, const char *root, const char *filename) static char *generate_random_name (const char *filename); static char *generate_backup_name (const char *filename); -static inline char * -bad_cast (char const *s) -{ - return (char *) s; -} - static void __attribute__((noreturn)) usage (int status) { @@ -144,7 +138,7 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } - argv[0] = bad_cast (program_name); + argv[0] = (char *) program_name; for (;;) { c = getopt_long (argc, argv, options, long_options, &option_index); diff --git a/fish/events.c b/fish/events.c index b98bd589f..b69a7ef91 100644 --- a/fish/events.c +++ b/fish/events.c @@ -222,7 +222,7 @@ run_delete_event (const char *cmd, size_t argc, char *argv[]) return -1; } - const struct entry key = { .name = bad_cast (argv[0]) }; + const struct entry key = { .name = argv[0] }; struct entry *entry, *p; entry = hash_delete (event_handlers, &key); diff --git a/fish/fish.c b/fish/fish.c index 71da49531..bfc08c9cd 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -242,7 +242,7 @@ main (int argc, char *argv[]) * of the original, in case it's needed below. */ //char *real_argv0 = argv[0]; - argv[0] = bad_cast (program_name); + argv[0] = (char *) program_name; for (;;) { c = getopt_long (argc, argv, options, long_options, &option_index); diff --git a/fish/fish.h b/fish/fish.h index b4a14fcfb..617f95bed 100644 --- a/fish/fish.h +++ b/fish/fish.h @@ -116,10 +116,4 @@ extern char *try_tilde_expansion (char *path); "help", \ "quit", "exit", "q" -static inline char * -bad_cast (char const *s) -{ - return (char *) s; -} - #endif /* FISH_H */ diff --git a/fish/options.h b/fish/options.h index d775edd49..41248eb96 100644 --- a/fish/options.h +++ b/fish/options.h @@ -146,7 +146,7 @@ extern int add_libvirt_drives (const char *guest); exit (EXIT_FAILURE); \ } \ mp->options = NULL; \ - mp->mountpoint = bad_cast ("/"); \ + mp->mountpoint = (char *) "/"; \ p = strchr (optarg, ':'); \ if (p) { \ *p = '\0'; \ diff --git a/fish/prep.c b/fish/prep.c index 665a3e9c4..254f33105 100644 --- a/fish/prep.c +++ b/fish/prep.c @@ -117,7 +117,7 @@ Use 'guestfish -N help' to list possible values for the -N parameter.\n"), } for (i = 0; i < data->prep->nr_params; ++i) - data->params[i] = bad_cast (data->prep->params[i].pdefault); + data->params[i] = (char *) data->prep->params[i].pdefault; /* Parse the optional parameters. */ const char *p = type_string + len; diff --git a/format/format.c b/format/format.c index 32b4bdb58..50b1888ca 100644 --- a/format/format.c +++ b/format/format.c @@ -56,12 +56,6 @@ static int do_format (void); static int do_rescan (char **devices); static int feature_available (guestfs_h *g, const char *feature); -static inline char * -bad_cast (char const *s) -{ - return (char *) s; -} - static void __attribute__((noreturn)) usage (int status) { @@ -138,7 +132,7 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } - argv[0] = bad_cast (program_name); + argv[0] = (char *) program_name; for (;;) { c = getopt_long (argc, argv, options, long_options, &option_index); diff --git a/fuse/Makefile.am b/fuse/Makefile.am index 1b1358cbb..4b7df990c 100644 --- a/fuse/Makefile.am +++ b/fuse/Makefile.am @@ -37,8 +37,7 @@ SHARED_SOURCE_FILES = \ guestmount_SOURCES = \ $(SHARED_SOURCE_FILES) \ - guestmount.c \ - guestmount.h + guestmount.c guestmount_CFLAGS = \ -DGUESTFS_WARN_DEPRECATED=1 \ diff --git a/fuse/guestmount.c b/fuse/guestmount.c index 3fa868de7..6f187d2e0 100644 --- a/fuse/guestmount.c +++ b/fuse/guestmount.c @@ -39,7 +39,6 @@ #include "progname.h" #include "ignore-value.h" -#include "guestmount.h" #include "options.h" static int write_pid_file (const char *pid_file, pid_t pid); diff --git a/fuse/guestmount.h b/fuse/guestmount.h deleted file mode 100644 index 6753bb467..000000000 --- a/fuse/guestmount.h +++ /dev/null @@ -1,36 +0,0 @@ -/* guestmount - mount guests using libguestfs and FUSE - * Copyright (C) 2009 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Derived from the example program 'fusexmp.c': - * Copyright (C) 2001-2007 Miklos Szeredi - * - * This program can be distributed under the terms of the GNU GPL. - * See the file COPYING. - */ - -#ifndef GUESTMOUNT_H_ -#define GUESTMOUNT_H_ - -#include "guestfs-internal-frontend.h" - -static inline char * -bad_cast (char const *s) -{ - return (char *) s; -} - -#endif /* GUESTMOUNT_H_ */ diff --git a/inspector/virt-inspector.c b/inspector/virt-inspector.c index 7c43b54ff..d91716022 100644 --- a/inspector/virt-inspector.c +++ b/inspector/virt-inspector.c @@ -63,12 +63,6 @@ static void free_strings (char **argv); static size_t count_strings (char *const*argv); static void do_xpath (const char *query); -static inline char * -bad_cast (char const *s) -{ - return (char *) s; -} - static void __attribute__((noreturn)) usage (int status) { @@ -139,7 +133,7 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } - argv[0] = bad_cast (program_name); + argv[0] = (char *) program_name; for (;;) { c = getopt_long (argc, argv, options, long_options, &option_index); diff --git a/rescue/virt-rescue.c b/rescue/virt-rescue.c index 5de47793d..090839e74 100644 --- a/rescue/virt-rescue.c +++ b/rescue/virt-rescue.c @@ -50,12 +50,6 @@ int echo_keys = 0; const char *libvirt_uri = NULL; int inspector = 0; -static inline char * -bad_cast (char const *s) -{ - return (char *) s; -} - static void __attribute__((noreturn)) usage (int status) { @@ -147,7 +141,7 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } - argv[0] = bad_cast (program_name); + argv[0] = (char *) program_name; for (;;) { c = getopt_long (argc, argv, options, long_options, &option_index); diff --git a/src/private-data.c b/src/private-data.c index 870ec101d..be78e32af 100644 --- a/src/private-data.c +++ b/src/private-data.c @@ -86,19 +86,13 @@ guestfs_set_private (guestfs_h *g, const char *key, void *data) assert (entry == new_entry); } -static inline char * -bad_cast (char const *s) -{ - return (char *) s; -} - void * guestfs_get_private (guestfs_h *g, const char *key) { if (g->pda == NULL) return NULL; /* no keys have been set */ - const struct pda_entry k = { .key = bad_cast (key) }; + const struct pda_entry k = { .key = (char *) key }; struct pda_entry *entry = hash_lookup (g->pda, &k); if (entry) return entry->data;