add chaos_calmer branch
[15.05/openwrt.git] / tools / dosfstools / patches / 0004-Make-all-char-that-may-take-literals-const.patch
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
5
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.
9
10 Signed-off-by: Andreas Bombe <aeb@debian.org>
11 ---
12  Makefile       | 2 +-
13  src/boot.c     | 4 ++--
14  src/check.c    | 2 +-
15  src/common.c   | 6 +++---
16  src/common.h   | 6 +++---
17  src/mkfs.fat.c | 8 +++++---
18  6 files changed, 15 insertions(+), 13 deletions(-)
19
20 diff --git a/Makefile b/Makefile
21 index 81256ef..3cbdb76 100644
22 --- a/Makefile
23 +++ b/Makefile
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
30  DEBUGFLAGS = -g
31  CFLAGS += $(OPTFLAGS) $(WARNFLAGS) $(DEBUGFLAGS)
32  
33 diff --git a/src/boot.c b/src/boot.c
34 index 5b3825c..be7bfb7 100644
35 --- a/src/boot.c
36 +++ b/src/boot.c
37 @@ -46,7 +46,7 @@
38  
39  static struct {
40      __u8 media;
41 -    char *descr;
42 +    const char *descr;
43  } mediabytes[] = {
44      {
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) )
49  
50 -static char *get_media_descr(unsigned char media)
51 +static const char *get_media_descr(unsigned char media)
52  {
53      int i;
54  
55 diff --git a/src/check.c b/src/check.c
56 index daa6d69..488f715 100644
57 --- a/src/check.c
58 +++ b/src/check.c
59 @@ -464,7 +464,7 @@ static void rename_file(DOS_FILE * file)
60  
61  static int handle_dot(DOS_FS * fs, DOS_FILE * file, int dots)
62  {
63 -    char *name;
64 +    const char *name;
65  
66      name =
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
70 --- a/src/common.c
71 +++ b/src/common.c
72 @@ -37,7 +37,7 @@ typedef struct _link {
73      struct _link *next;
74  } LINK;
75  
76 -void die(char *msg, ...)
77 +void die(const char *msg, ...)
78  {
79      va_list args;
80  
81 @@ -48,7 +48,7 @@ void die(char *msg, ...)
82      exit(1);
83  }
84  
85 -void pdie(char *msg, ...)
86 +void pdie(const char *msg, ...)
87  {
88      va_list args;
89  
90 @@ -96,7 +96,7 @@ int min(int a, int b)
91      return a < b ? a : b;
92  }
93  
94 -char get_key(char *valid, char *prompt)
95 +char get_key(const char *valid, const char *prompt)
96  {
97      int ch, okay;
98  
99 diff --git a/src/common.h b/src/common.h
100 index 8508602..b127f63 100644
101 --- a/src/common.h
102 +++ b/src/common.h
103 @@ -25,11 +25,11 @@
104  #ifndef _COMMON_H
105  #define _COMMON_H
106  
107 -void die(char *msg, ...) __attribute((noreturn));
108 +void die(const char *msg, ...) __attribute((noreturn));
109  
110  /* Displays a prinf-style message and terminates the program. */
111  
112 -void pdie(char *msg, ...) __attribute((noreturn));
113 +void pdie(const char *msg, ...) __attribute((noreturn));
114  
115  /* Like die, but appends an error message according to the state of errno. */
116  
117 @@ -50,7 +50,7 @@ int min(int a, int b);
118  
119  /* Returns the smaller integer value of a and b. */
120  
121 -char get_key(char *valid, char *prompt);
122 +char get_key(const char *valid, const char *prompt);
123  
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
128 --- a/src/mkfs.fat.c
129 +++ b/src/mkfs.fat.c
130 @@ -250,7 +250,7 @@ char dummy_boot_code[BOOTCODE_SIZE] = "\x0e"        /* push cs */
131  
132  /* Global variables - the root of all evil :-) - see these and weep! */
133  
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)
140      int create = 0;
141      uint64_t cblocks = 0;
142      int min_sector_size;
143 +    int bad_block_count = 0;
144  
145      if (argc && *argv) {       /* What's the program name? */
146         char *p;
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);
150         }
151 +       if (*tmp)
152 +           bad_block_count = 1;
153      } else if (optind == argc - 1) {   /*  Or use value found */
154         if (create)
155             die("Need intended size with -C.");
156         blocks = cblocks;
157 -       tmp = "";
158      } else {
159         fprintf(stderr, "No device specified!\n");
160         usage();
161      }
162 -    if (*tmp) {
163 +    if (bad_block_count) {
164         printf("Bad block count : %s\n", argv[optind + 1]);
165         usage();
166      }
167 -- 
168 1.9.1
169