1 From 16e97e9741a02f6c2c29b3da45b62ac798d76403 Mon Sep 17 00:00:00 2001
2 From: Andreas Bombe <aeb@debian.org>
3 Date: Wed, 28 Jan 2015 15:07:18 +0100
4 Subject: [PATCH 04/14] Make all char* that may take literals const
6 Every char* variable or function argument that may be given a literal
7 string is now made const. Additionally add -Wwrite-strings to CFLAGS to
8 enable a warning where const would be missing.
10 Signed-off-by: Andreas Bombe <aeb@debian.org>
15 src/common.c | 6 +++---
16 src/common.h | 6 +++---
17 src/mkfs.fat.c | 8 +++++---
18 6 files changed, 15 insertions(+), 13 deletions(-)
20 diff --git a/Makefile b/Makefile
21 index 81256ef..3cbdb76 100644
24 @@ -30,7 +30,7 @@ MANDIR = $(PREFIX)/share/man
25 #OPTFLAGS = -O2 -fomit-frame-pointer -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
26 OPTFLAGS = -O2 -fomit-frame-pointer -D_GNU_SOURCE $(shell getconf LFS_CFLAGS)
27 #WARNFLAGS = -Wall -pedantic -std=c99
28 -WARNFLAGS = -Wall -Wextra -Wno-sign-compare -Wno-missing-field-initializers -Wmissing-prototypes -Wstrict-prototypes
29 +WARNFLAGS = -Wall -Wextra -Wno-sign-compare -Wno-missing-field-initializers -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings
31 CFLAGS += $(OPTFLAGS) $(WARNFLAGS) $(DEBUGFLAGS)
33 diff --git a/src/boot.c b/src/boot.c
34 index 5b3825c..be7bfb7 100644
45 0xf0, "5.25\" or 3.5\" HD floppy"}, {
46 @@ -64,7 +64,7 @@ static struct {
47 #define GET_UNALIGNED_W(f) \
48 ( (__u16)f[0] | ((__u16)f[1]<<8) )
50 -static char *get_media_descr(unsigned char media)
51 +static const char *get_media_descr(unsigned char media)
55 diff --git a/src/check.c b/src/check.c
56 index daa6d69..488f715 100644
59 @@ -464,7 +464,7 @@ static void rename_file(DOS_FILE * file)
61 static int handle_dot(DOS_FS * fs, DOS_FILE * file, int dots)
67 strncmp((const char *)file->dir_ent.name, MSDOS_DOT,
68 diff --git a/src/common.c b/src/common.c
69 index af222a2..9d11193 100644
72 @@ -37,7 +37,7 @@ typedef struct _link {
76 -void die(char *msg, ...)
77 +void die(const char *msg, ...)
81 @@ -48,7 +48,7 @@ void die(char *msg, ...)
85 -void pdie(char *msg, ...)
86 +void pdie(const char *msg, ...)
90 @@ -96,7 +96,7 @@ int min(int a, int b)
94 -char get_key(char *valid, char *prompt)
95 +char get_key(const char *valid, const char *prompt)
99 diff --git a/src/common.h b/src/common.h
100 index 8508602..b127f63 100644
107 -void die(char *msg, ...) __attribute((noreturn));
108 +void die(const char *msg, ...) __attribute((noreturn));
110 /* Displays a prinf-style message and terminates the program. */
112 -void pdie(char *msg, ...) __attribute((noreturn));
113 +void pdie(const char *msg, ...) __attribute((noreturn));
115 /* Like die, but appends an error message according to the state of errno. */
117 @@ -50,7 +50,7 @@ int min(int a, int b);
119 /* Returns the smaller integer value of a and b. */
121 -char get_key(char *valid, char *prompt);
122 +char get_key(const char *valid, const char *prompt);
124 /* Displays PROMPT and waits for user input. Only characters in VALID are
125 accepted. Terminates the program on EOF. Returns the character. */
126 diff --git a/src/mkfs.fat.c b/src/mkfs.fat.c
127 index 1f702ad..a3dff54 100644
130 @@ -250,7 +250,7 @@ char dummy_boot_code[BOOTCODE_SIZE] = "\x0e" /* push cs */
132 /* Global variables - the root of all evil :-) - see these and weep! */
134 -static char *program_name = "mkfs.fat"; /* Name of the program */
135 +static const char *program_name = "mkfs.fat"; /* Name of the program */
136 static char *device_name = NULL; /* Name of the device on which to create the filesystem */
137 static int atari_format = 0; /* Use Atari variation of MS-DOS FS format */
138 static int check = FALSE; /* Default to no readablity checking */
139 @@ -1412,6 +1412,7 @@ int main(int argc, char **argv)
141 uint64_t cblocks = 0;
143 + int bad_block_count = 0;
145 if (argc && *argv) { /* What's the program name? */
147 @@ -1653,16 +1654,17 @@ int main(int argc, char **argv)
148 fprintf(stderr, "Warning: block count mismatch: ");
149 fprintf(stderr, "found %llu but assuming %llu.\n", (unsigned long long)cblocks, (unsigned long long)blocks);
152 + bad_block_count = 1;
153 } else if (optind == argc - 1) { /* Or use value found */
155 die("Need intended size with -C.");
159 fprintf(stderr, "No device specified!\n");
163 + if (bad_block_count) {
164 printf("Bad block count : %s\n", argv[optind + 1]);