[parted-devel] [PATCH] avoid const-related compiler warnings

Jim Meyering jim at meyering.net
Thu May 29 12:38:54 UTC 2008


I noticed a bunch of const-related warnings.
This fixes them.

avoid const-related compiler warnings
* libparted/arch/linux.c (init_dasd, init_generic): Likewise.
* libparted/exception.c (type_strings, option_strings): Likewise.
(ped_exception_get_type_string, ped_exception_get_option_string):
* libparted/fs/ext2/ext2_block_relocator.c (ext2_block_relocator_flush):
* libparted/fs/ext2/ext2_mkfs.c (_set_dirent): Likewise.
* libparted/fs/fat/resize.c (ask_type): Likewise.
* libparted/fs/fat/traverse.c (fat_traverse_begin): Likewise.
* libparted/fs/fat/traverse.h (buffer_size): Likewise.
* libparted/labels/mac.c (_rawpart_cmp_type, _rawpart_cmp_name):
(_rawpart_is_partition_map, _rawpart_is_boot, _rawpart_is_driver):
(_rawpart_has_driver): Likewise.
* parted/parted.c (options, options_help, number_msg): Likewise.
(label_type_msg_start, flag_msg_start, unit_msg_start): Likewise.
(part_type_msg, fs_type_msg_start, start_end_msg, state_msg): Likewise.
(device_msg, name_msg, resize_msg_start, copyright_msg, do_print):
* parted/ui.c (prog_name, banner_msg, usage_msg, bug_msg): Likewise.
(screen_width): Likewise.
* parted/ui.h (prog_name): Likewise.
---
 libparted/arch/linux.c                   |    4 +-
 libparted/exception.c                    |   10 ++++----
 libparted/fs/ext2/ext2_block_relocator.c |    9 ++++---
 libparted/fs/ext2/ext2_mkfs.c            |    4 +-
 libparted/fs/fat/resize.c                |    6 ++--
 libparted/fs/fat/traverse.c              |    2 +-
 libparted/fs/fat/traverse.h              |    3 +-
 libparted/labels/mac.c                   |   14 +++++-----
 parted/parted.c                          |   36 +++++++++++++++---------------
 parted/ui.c                              |   10 ++++----
 parted/ui.h                              |    4 +-
 11 files changed, 52 insertions(+), 50 deletions(-)

diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index c332cf8..545d74c 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -987,7 +987,7 @@ error:
 }

 static int
-init_dasd (PedDevice* dev, char* model_name)
+init_dasd (PedDevice* dev, const char* model_name)
 {
         struct stat             dev_stat;
         struct hd_geometry      geo;
@@ -1043,7 +1043,7 @@ error:
 }

 static int
-init_generic (PedDevice* dev, char* model_name)
+init_generic (PedDevice* dev, const char* model_name)
 {
         struct stat             dev_stat;
         PedExceptionOption      ex_status;
diff --git a/libparted/exception.c b/libparted/exception.c
index 5fb3c79..3980e4e 100644
--- a/libparted/exception.c
+++ b/libparted/exception.c
@@ -1,6 +1,6 @@
 /*
     libparted - a library for manipulating disk partitions
-    Copyright (C) 1999, 2000, 2007 Free Software Foundation, Inc.
+    Copyright (C) 1999, 2000, 2007-2008 Free Software Foundation, 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
@@ -73,7 +73,7 @@ static PedExceptionHandler*	ex_handler = default_handler;
 static PedException*		ex = NULL;
 static int			ex_fetch_count = 0;

-static char*	type_strings [] = {
+static const char *const type_strings [] = {
 	N_("Information"),
 	N_("Warning"),
 	N_("Error"),
@@ -82,7 +82,7 @@ static char*	type_strings [] = {
 	N_("No Implementation")
 };

-static char*	option_strings [] = {
+static const char *const option_strings [] = {
 	N_("Fix"),
 	N_("Yes"),
 	N_("No"),
@@ -98,7 +98,7 @@ static char*	option_strings [] = {
 char*
 ped_exception_get_type_string (PedExceptionType ex_type)
 {
-	return type_strings [ex_type - 1];
+	return (char *) type_strings [ex_type - 1];
 }

 /* FIXME: move this out to the prospective math.c */
@@ -121,7 +121,7 @@ ped_log2 (int n)
 char*
 ped_exception_get_option_string (PedExceptionOption ex_opt)
 {
-	return option_strings [ped_log2 (ex_opt)];
+	return (char *) option_strings [ped_log2 (ex_opt)];
 }

 static PedExceptionOption
diff --git a/libparted/fs/ext2/ext2_block_relocator.c b/libparted/fs/ext2/ext2_block_relocator.c
index b75a4c5..60f3d50 100644
--- a/libparted/fs/ext2/ext2_block_relocator.c
+++ b/libparted/fs/ext2/ext2_block_relocator.c
@@ -691,10 +691,11 @@ static int ext2_block_relocator_flush(struct ext2_fs *fs, struct ext2_block_relo
 		{
 			/* FIXXXME gross hack */
 			fprintf(stderr, "relocating %s blocks",
-				((char *[4]){"direct",
-						     "singly indirect",
-						     "doubly indirect",
-						     "triply indirect"})[i]);
+				((const char *const [4])
+				 {"direct",
+				  "singly indirect",
+				  "doubly indirect",
+				  "triply indirect"})[i]);
 			fflush(stderr);
 		}

diff --git a/libparted/fs/ext2/ext2_mkfs.c b/libparted/fs/ext2/ext2_mkfs.c
index 19931dd..b1a8ce3 100644
--- a/libparted/fs/ext2/ext2_mkfs.c
+++ b/libparted/fs/ext2/ext2_mkfs.c
@@ -1,6 +1,6 @@
 /*
     ext2_mkfs.c -- ext2 fs creator
-    Copyright (C) 1999, 2000, 2001, 2007 Free Software Foundation, Inc.
+    Copyright (C) 1999, 2000, 2001, 2007-2008 Free Software Foundation, 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
@@ -263,7 +263,7 @@ error:

 /* returns the offset into the buffer of the start of the next dir entry */
 static int _set_dirent(void* buf, int offset, int block_size, int is_last,
-		       uint32_t inode, char* name, int file_type)
+		       uint32_t inode, const char* name, int file_type)
 {
 	struct ext2_dir_entry_2 *dirent = (void*) (((char*)buf) + offset);
 	int name_len = strlen(name);
diff --git a/libparted/fs/fat/resize.c b/libparted/fs/fat/resize.c
index 7386948..5f24ec2 100644
--- a/libparted/fs/fat/resize.c
+++ b/libparted/fs/fat/resize.c
@@ -1,6 +1,6 @@
 /*
     libparted
-    Copyright (C) 1998, 1999, 2000, 2007 Free Software Foundation, Inc.
+    Copyright (C) 1998, 1999, 2000, 2007-2008 Free Software Foundation, 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
@@ -481,8 +481,8 @@ ask_type (PedFileSystem* fs, int fat16_ok, int fat32_ok, FatType* out_fat_type)
 {
 	FatSpecific*		fs_info = FAT_SPECIFIC (fs);
 	PedExceptionOption	status;
-	char*			fat16_msg;
-	char*			fat32_msg;
+	const char*		fat16_msg;
+	const char*		fat32_msg;

 	if (fs_info->fat_type == FAT_TYPE_FAT16)
 		fat16_msg = _("If you leave your file system as FAT16, "
diff --git a/libparted/fs/fat/traverse.c b/libparted/fs/fat/traverse.c
index 367f511..c613dab 100644
--- a/libparted/fs/fat/traverse.c
+++ b/libparted/fs/fat/traverse.c
@@ -120,7 +120,7 @@ fat_traverse_mark_dirty (FatTraverseInfo* trav_info)

 FatTraverseInfo*
 fat_traverse_begin (PedFileSystem* fs, FatCluster start_cluster,
-		    char* dir_name)
+		    const char* dir_name)
 {
 	FatSpecific*		fs_info = FAT_SPECIFIC (fs);
 	FatTraverseInfo*	trav_info;
diff --git a/libparted/fs/fat/traverse.h b/libparted/fs/fat/traverse.h
index 17e4580..4fdc90f 100644
--- a/libparted/fs/fat/traverse.h
+++ b/libparted/fs/fat/traverse.h
@@ -42,7 +42,8 @@ extern int fat_traverse_entries_per_buffer (FatTraverseInfo* trav_info);
 /* starts traversal at an arbitary cluster.  if start_cluster==0, then uses
    root directory */
 extern FatTraverseInfo* fat_traverse_begin (PedFileSystem* fs,
-				     FatCluster start_cluster, char* dir_name);
+					    FatCluster start_cluster,
+					    const char* dir_name);

 extern int fat_traverse_complete (FatTraverseInfo* trav_info);

diff --git a/libparted/labels/mac.c b/libparted/labels/mac.c
index ae352aa..2c10e05 100644
--- a/libparted/labels/mac.c
+++ b/libparted/labels/mac.c
@@ -1,6 +1,6 @@
 /*
     libparted - a library for manipulating disk partitions
-    Copyright (C) 2000, 2002, 2004, 2007 Free Software Foundation, Inc.
+    Copyright (C) 2000, 2002, 2004, 2007-2008 Free Software Foundation, 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
@@ -378,19 +378,19 @@ mac_clobber (PedDevice* dev)
 #endif /* !DISCOVER_ONLY */

 static int
-_rawpart_cmp_type (MacRawPartition* raw_part, char* type)
+_rawpart_cmp_type (const MacRawPartition* raw_part, const char* type)
 {
 	return strncasecmp (raw_part->type, type, 32) == 0;
 }

 static int
-_rawpart_cmp_name (MacRawPartition* raw_part, char* name)
+_rawpart_cmp_name (const MacRawPartition* raw_part, const char* name)
 {
 	return strncasecmp (raw_part->name, name, 32) == 0;
 }

 static int
-_rawpart_is_partition_map (MacRawPartition* raw_part)
+_rawpart_is_partition_map (const MacRawPartition* raw_part)
 {
 	return _rawpart_cmp_type (raw_part, "Apple_partition_map");
 }
@@ -410,7 +410,7 @@ strncasestr (const char* haystack, const char* needle, int n)
 }

 static int
-_rawpart_is_boot (MacRawPartition* raw_part)
+_rawpart_is_boot (const MacRawPartition* raw_part)
 {
 	if (!strcasecmp(raw_part->type, "Apple_Bootstrap"))
 		return 1;
@@ -422,7 +422,7 @@ _rawpart_is_boot (MacRawPartition* raw_part)
 }

 static int
-_rawpart_is_driver (MacRawPartition* raw_part)
+_rawpart_is_driver (const MacRawPartition* raw_part)
 {
 	if (strncmp (raw_part->type, "Apple_", 6) != 0)
 		return 0;
@@ -432,7 +432,7 @@ _rawpart_is_driver (MacRawPartition* raw_part)
 }

 static int
-_rawpart_has_driver (MacRawPartition* raw_part, MacDiskData* mac_disk_data)
+_rawpart_has_driver (const MacRawPartition* raw_part, MacDiskData* mac_disk_data)
 {
 	MacDeviceDriver *driverlist;
 	uint16_t i, bsz;
diff --git a/parted/parted.c b/parted/parted.c
index 0f6768b..7acfa2f 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -78,7 +78,7 @@ typedef struct {
         time_t  predicted_time_left;
 } TimerContext;

-static struct option    options[] = {
+static const struct option const options[] = {
         /* name, has-arg, string-return-val, char-return-val */
         {"help",        0, NULL, 'h'},
         {"list",        0, NULL, 'l'},
@@ -89,7 +89,7 @@ static struct option    options[] = {
         {NULL,          0, NULL, 0}
 };

-static char*    options_help [][2] = {
+static const char *const options_help [][2] = {
         {"help",        N_("displays this help message")},
         {"list",        N_("lists partition layout on all block devices")},
         {"machine",     N_("displays machine parseable output")},
@@ -106,26 +106,26 @@ int     opt_machine_mode = 0;
 int     disk_is_modified = 0;
 int     is_toggle_mode = 0;

-static char* number_msg = N_(
+static const char* number_msg = N_(
 "NUMBER is the partition number used by Linux.  On MS-DOS disk labels, the "
 "primary partitions number from 1 to 4, logical partitions from 5 onwards.\n");

-static char* label_type_msg_start = N_("LABEL-TYPE is one of: ");
-static char* flag_msg_start =   N_("FLAG is one of: ");
-static char* unit_msg_start =   N_("UNIT is one of: ");
-static char* part_type_msg =    N_("PART-TYPE is one of: primary, logical, "
+static const char* label_type_msg_start = N_("LABEL-TYPE is one of: ");
+static const char* flag_msg_start =   N_("FLAG is one of: ");
+static const char* unit_msg_start =   N_("UNIT is one of: ");
+static const char* part_type_msg =    N_("PART-TYPE is one of: primary, logical, "
                                    "extended\n");
-static char* fs_type_msg_start = N_("FS-TYPE is one of: ");
-static char* start_end_msg =    N_("START and END are disk locations, such as "
+static const char* fs_type_msg_start = N_("FS-TYPE is one of: ");
+static const char* start_end_msg =    N_("START and END are disk locations, such as "
                 "4GB or 10%.  Negative values count from the end of the disk.  "
                 "For example, -1s specifies exactly the last sector.\n");
-static char* state_msg =        N_("STATE is one of: on, off\n");
-static char* device_msg =       N_("DEVICE is usually /dev/hda or /dev/sda\n");
-static char* name_msg =         N_("NAME is any word you want\n");
-static char* resize_msg_start = N_("The partition must have one of the "
+static const char* state_msg =        N_("STATE is one of: on, off\n");
+static const char* device_msg =       N_("DEVICE is usually /dev/hda or /dev/sda\n");
+static const char* name_msg =         N_("NAME is any word you want\n");
+static const char* resize_msg_start = N_("The partition must have one of the "
                                    "following FS-TYPEs: ");

-static char* copyright_msg = N_(
+static const char* copyright_msg = N_(
 "Copyright (C) 1998 - 2006 Free Software Foundation, Inc.\n"
 "This program is free software, covered by the GNU General Public License.\n"
 "\n"
@@ -1274,10 +1274,10 @@ do_print (PedDevice** dev)
         int             has_free_arg = 0;
         int             has_list_arg = 0;
         int             has_num_arg = 0;
-        char*           transport[14] = {"unknown", "scsi", "ide", "dac960",
-                                         "cpqarray", "file", "ataraid", "i2o",
-                                         "ubd", "dasd", "viodasd", "sx8", "dm",
-                                         "xvd"};
+        const char *const transport[14] = {"unknown", "scsi", "ide", "dac960",
+					   "cpqarray", "file", "ataraid", "i2o",
+					   "ubd", "dasd", "viodasd", "sx8", "dm",
+					   "xvd"};
         char*           peek_word;
         char*           start;
         char*           end;
diff --git a/parted/ui.c b/parted/ui.c
index d9ab107..3d9bd08 100644
--- a/parted/ui.c
+++ b/parted/ui.c
@@ -154,17 +154,17 @@ struct siginfo_t {
 #  define ILL_BADSTK (INTMAX - 8)
 #endif

-char* prog_name = "GNU Parted " VERSION "\n";
+const char* prog_name = "GNU Parted " VERSION "\n";

-static char* banner_msg = N_(
+static const char* banner_msg = N_(
 "Welcome to GNU Parted! Type 'help' to view a list of commands.\n");

-static char* usage_msg = N_(
+static const char* usage_msg = N_(
 "Usage: parted [OPTION]... [DEVICE [COMMAND [PARAMETERS]...]...]\n"
 "Apply COMMANDs with PARAMETERS to DEVICE.  If no COMMAND(s) are given, "
 "run in\ninteractive mode.\n");

-static char* bug_msg = N_(
+static const char* bug_msg = N_(
 "\n\nYou found a bug in GNU Parted! Here's what you have to do:\n\n"
 "Don't panic! The bug has most likely not affected any of your data.\n"
 "Help us to fix this bug by doing the following:\n\n"
@@ -218,7 +218,7 @@ screen_width ()

 /* HACK: don't specify termcap separately - it'll annoy the users. */
 #ifdef HAVE_LIBREADLINE
-        width = tgetnum ("co");
+        width = tgetnum ((char *) "co");
 #endif

         if (width <= 0)
diff --git a/parted/ui.h b/parted/ui.h
index f5cf760..77bb194 100644
--- a/parted/ui.h
+++ b/parted/ui.h
@@ -1,6 +1,6 @@
 /*
     parted - a frontend to libparted
-    Copyright (C) 1999, 2000, 2001, 2007 Free Software Foundation, Inc.
+    Copyright (C) 1999, 2000, 2001, 2007-2008 Free Software Foundation, 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
@@ -21,7 +21,7 @@

 #include "strlist.h"

-extern char*	prog_name;
+extern const char *prog_name;

 extern int init_ui ();
 extern int non_interactive_mode (PedDevice** dev, Command* cmd_list[],
--
1.5.6.rc0.30.g51263



More information about the parted-devel mailing list