diff options
-rw-r--r-- | coreutils/cut.c | 31 | ||||
-rw-r--r-- | coreutils/sort.c | 4 | ||||
-rw-r--r-- | libbb/get_line_from_file.c | 1 | ||||
-rw-r--r-- | util-linux/mount.c | 23 |
4 files changed, 29 insertions, 30 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c index 7ba947fae..94e12e609 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c | |||
@@ -13,13 +13,11 @@ | |||
13 | 13 | ||
14 | /* option vars */ | 14 | /* option vars */ |
15 | static const char optstring[] = "b:c:f:d:sn"; | 15 | static const char optstring[] = "b:c:f:d:sn"; |
16 | |||
17 | #define CUT_OPT_BYTE_FLGS (1<<0) | 16 | #define CUT_OPT_BYTE_FLGS (1<<0) |
18 | #define CUT_OPT_CHAR_FLGS (1<<1) | 17 | #define CUT_OPT_CHAR_FLGS (1<<1) |
19 | #define CUT_OPT_FIELDS_FLGS (1<<2) | 18 | #define CUT_OPT_FIELDS_FLGS (1<<2) |
20 | #define CUT_OPT_DELIM_FLGS (1<<3) | 19 | #define CUT_OPT_DELIM_FLGS (1<<3) |
21 | #define CUT_OPT_SUPPRESS_FLGS (1<<4) | 20 | #define CUT_OPT_SUPPRESS_FLGS (1<<4) |
22 | static unsigned opt; | ||
23 | 21 | ||
24 | static char delim = '\t'; /* delimiter, default is tab */ | 22 | static char delim = '\t'; /* delimiter, default is tab */ |
25 | 23 | ||
@@ -61,7 +59,7 @@ static void cut_file(FILE * file) | |||
61 | int spos; | 59 | int spos; |
62 | 60 | ||
63 | /* cut based on chars/bytes XXX: only works when sizeof(char) == byte */ | 61 | /* cut based on chars/bytes XXX: only works when sizeof(char) == byte */ |
64 | if ((opt & (CUT_OPT_CHAR_FLGS | CUT_OPT_BYTE_FLGS))) { | 62 | if (option_mask32 & (CUT_OPT_CHAR_FLGS | CUT_OPT_BYTE_FLGS)) { |
65 | /* print the chars specified in each cut list */ | 63 | /* print the chars specified in each cut list */ |
66 | for (; cl_pos < nlists; cl_pos++) { | 64 | for (; cl_pos < nlists; cl_pos++) { |
67 | spos = cut_lists[cl_pos].startpos; | 65 | spos = cut_lists[cl_pos].startpos; |
@@ -115,7 +113,7 @@ static void cut_file(FILE * file) | |||
115 | 113 | ||
116 | /* does this line contain any delimiters? */ | 114 | /* does this line contain any delimiters? */ |
117 | if (strchr(line, delim) == NULL) { | 115 | if (strchr(line, delim) == NULL) { |
118 | if (!(opt & CUT_OPT_SUPPRESS_FLGS)) | 116 | if (!(option_mask32 & CUT_OPT_SUPPRESS_FLGS)) |
119 | puts(line); | 117 | puts(line); |
120 | goto next_line; | 118 | goto next_line; |
121 | } | 119 | } |
@@ -125,7 +123,6 @@ static void cut_file(FILE * file) | |||
125 | for (; cl_pos < nlists && line; cl_pos++) { | 123 | for (; cl_pos < nlists && line; cl_pos++) { |
126 | spos = cut_lists[cl_pos].startpos; | 124 | spos = cut_lists[cl_pos].startpos; |
127 | do { | 125 | do { |
128 | |||
129 | /* find the field we're looking for */ | 126 | /* find the field we're looking for */ |
130 | while (line && ndelim < spos) { | 127 | while (line && ndelim < spos) { |
131 | field = strsep(&line, delimiter); | 128 | field = strsep(&line, delimiter); |
@@ -156,7 +153,7 @@ static void cut_file(FILE * file) | |||
156 | /* if we printed anything at all, we need to finish it with a | 153 | /* if we printed anything at all, we need to finish it with a |
157 | * newline cuz we were handed a chomped line */ | 154 | * newline cuz we were handed a chomped line */ |
158 | putchar('\n'); | 155 | putchar('\n'); |
159 | next_line: | 156 | next_line: |
160 | linenum++; | 157 | linenum++; |
161 | free(printed); | 158 | free(printed); |
162 | free(orig_line); | 159 | free(orig_line); |
@@ -170,14 +167,13 @@ int cut_main(int argc, char **argv) | |||
170 | char *sopt, *ltok; | 167 | char *sopt, *ltok; |
171 | 168 | ||
172 | opt_complementary = "b--bcf:c--bcf:f--bcf"; | 169 | opt_complementary = "b--bcf:c--bcf:f--bcf"; |
173 | opt = getopt32(argc, argv, optstring, &sopt, &sopt, &sopt, <ok); | 170 | getopt32(argc, argv, optstring, &sopt, &sopt, &sopt, <ok); |
174 | if (!(opt & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS))) | 171 | if (!(option_mask32 & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS))) |
175 | bb_error_msg_and_die | 172 | bb_error_msg_and_die("expected a list of bytes, characters, or fields"); |
176 | ("expected a list of bytes, characters, or fields"); | 173 | if (option_mask32 & BB_GETOPT_ERROR) |
177 | if (opt & BB_GETOPT_ERROR) | ||
178 | bb_error_msg_and_die("only one type of list may be specified"); | 174 | bb_error_msg_and_die("only one type of list may be specified"); |
179 | 175 | ||
180 | if ((opt & (CUT_OPT_DELIM_FLGS))) { | 176 | if (option_mask32 & CUT_OPT_DELIM_FLGS) { |
181 | if (strlen(ltok) > 1) { | 177 | if (strlen(ltok) > 1) { |
182 | bb_error_msg_and_die("the delimiter must be a single character"); | 178 | bb_error_msg_and_die("the delimiter must be a single character"); |
183 | } | 179 | } |
@@ -185,8 +181,8 @@ int cut_main(int argc, char **argv) | |||
185 | } | 181 | } |
186 | 182 | ||
187 | /* non-field (char or byte) cutting has some special handling */ | 183 | /* non-field (char or byte) cutting has some special handling */ |
188 | if (!(opt & CUT_OPT_FIELDS_FLGS)) { | 184 | if (!(option_mask32 & CUT_OPT_FIELDS_FLGS)) { |
189 | if (opt & CUT_OPT_SUPPRESS_FLGS) { | 185 | if (option_mask32 & CUT_OPT_SUPPRESS_FLGS) { |
190 | bb_error_msg_and_die | 186 | bb_error_msg_and_die |
191 | ("suppressing non-delimited lines makes sense%s", | 187 | ("suppressing non-delimited lines makes sense%s", |
192 | _op_on_field); | 188 | _op_on_field); |
@@ -251,10 +247,9 @@ int cut_main(int argc, char **argv) | |||
251 | bb_error_msg_and_die("invalid byte or field list"); | 247 | bb_error_msg_and_die("invalid byte or field list"); |
252 | 248 | ||
253 | /* add the new list */ | 249 | /* add the new list */ |
254 | cut_lists = | 250 | cut_lists = xrealloc(cut_lists, sizeof(struct cut_list) * (++nlists)); |
255 | xrealloc(cut_lists, sizeof(struct cut_list) * (++nlists)); | 251 | cut_lists[nlists-1].startpos = s; |
256 | cut_lists[nlists - 1].startpos = s; | 252 | cut_lists[nlists-1].endpos = e; |
257 | cut_lists[nlists - 1].endpos = e; | ||
258 | } | 253 | } |
259 | 254 | ||
260 | /* make sure we got some cut positions out of all that */ | 255 | /* make sure we got some cut positions out of all that */ |
diff --git a/coreutils/sort.c b/coreutils/sort.c index c450cfbe6..e789292b9 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
@@ -124,9 +124,9 @@ static struct sort_key *add_key(void) | |||
124 | } | 124 | } |
125 | 125 | ||
126 | #define GET_LINE(fp) (global_flags&FLAG_z) ? bb_get_chunk_from_file(fp,NULL) \ | 126 | #define GET_LINE(fp) (global_flags&FLAG_z) ? bb_get_chunk_from_file(fp,NULL) \ |
127 | : bb_get_chomped_line_from_file(fp) | 127 | : bb_get_chomped_line_from_file(fp) |
128 | #else | 128 | #else |
129 | #define GET_LINE(fp) bb_get_chomped_line_from_file(fp) | 129 | #define GET_LINE(fp) bb_get_chomped_line_from_file(fp) |
130 | #endif | 130 | #endif |
131 | 131 | ||
132 | /* Iterate through keys list and perform comparisons */ | 132 | /* Iterate through keys list and perform comparisons */ |
diff --git a/libbb/get_line_from_file.c b/libbb/get_line_from_file.c index de49eb51d..722a904b5 100644 --- a/libbb/get_line_from_file.c +++ b/libbb/get_line_from_file.c | |||
@@ -41,6 +41,7 @@ char *bb_get_chunk_from_file(FILE * file, int *end) | |||
41 | free(linebuf); | 41 | free(linebuf); |
42 | return NULL; | 42 | return NULL; |
43 | } | 43 | } |
44 | linebuf = xrealloc(linebuf, idx+1); | ||
44 | linebuf[idx] = 0; | 45 | linebuf[idx] = 0; |
45 | } | 46 | } |
46 | return linebuf; | 47 | return linebuf; |
diff --git a/util-linux/mount.c b/util-linux/mount.c index 531fb4520..5448f1f21 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -172,8 +172,12 @@ static int parse_mount_options(char *options, char **unrecognized) | |||
172 | 172 | ||
173 | static llist_t *get_block_backed_filesystems(void) | 173 | static llist_t *get_block_backed_filesystems(void) |
174 | { | 174 | { |
175 | char *fs, *buf, | 175 | static const char *const filesystems[] = { |
176 | *filesystems[] = {"/etc/filesystems", "/proc/filesystems", 0}; | 176 | "/etc/filesystems", |
177 | "/proc/filesystems", | ||
178 | 0 | ||
179 | }; | ||
180 | char *fs, *buf; | ||
177 | llist_t *list = 0; | 181 | llist_t *list = 0; |
178 | int i; | 182 | int i; |
179 | FILE *f; | 183 | FILE *f; |
@@ -182,16 +186,15 @@ static llist_t *get_block_backed_filesystems(void) | |||
182 | f = fopen(filesystems[i], "r"); | 186 | f = fopen(filesystems[i], "r"); |
183 | if (!f) continue; | 187 | if (!f) continue; |
184 | 188 | ||
185 | for (fs = buf = 0; (fs = buf = bb_get_chomped_line_from_file(f)); | 189 | while ((buf = bb_get_chomped_line_from_file(f)) != 0) { |
186 | free(buf)) | 190 | if (!strncmp(buf, "nodev", 5) && isspace(buf[5])) |
187 | { | 191 | continue; |
188 | if (!strncmp(buf,"nodev",5) && isspace(buf[5])) continue; | 192 | fs = buf; |
189 | |||
190 | while (isspace(*fs)) fs++; | 193 | while (isspace(*fs)) fs++; |
191 | if (*fs=='#' || *fs=='*') continue; | 194 | if (*fs=='#' || *fs=='*' || !*fs) continue; |
192 | if (!*fs) continue; | ||
193 | 195 | ||
194 | llist_add_to_end(&list,xstrdup(fs)); | 196 | llist_add_to_end(&list, xstrdup(fs)); |
197 | free(buf); | ||
195 | } | 198 | } |
196 | if (ENABLE_FEATURE_CLEAN_UP) fclose(f); | 199 | if (ENABLE_FEATURE_CLEAN_UP) fclose(f); |
197 | } | 200 | } |