aboutsummaryrefslogtreecommitdiff
path: root/findutils
diff options
context:
space:
mode:
authormjn3 <mjn3@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-03-19 09:13:01 +0000
committermjn3 <mjn3@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-03-19 09:13:01 +0000
commite901c15d890dbbdce4c086963cb1513653fc46b5 (patch)
treea318d0f03aa076c74b576ea45dc543a5669e8e91 /findutils
parent40758c00616c3b2c85d83eb4afdeb04b1f65c9f1 (diff)
downloadbusybox-w32-e901c15d890dbbdce4c086963cb1513653fc46b5.tar.gz
busybox-w32-e901c15d890dbbdce4c086963cb1513653fc46b5.tar.bz2
busybox-w32-e901c15d890dbbdce4c086963cb1513653fc46b5.zip
Major coreutils update.
git-svn-id: svn://busybox.net/trunk/busybox@6751 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'findutils')
-rw-r--r--findutils/find.c28
-rw-r--r--findutils/grep.c24
-rw-r--r--findutils/xargs.c12
3 files changed, 30 insertions, 34 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 048aac503..58bc8bf9c 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -167,7 +167,7 @@ static int find_type(char *type)
167 } 167 }
168 168
169 if (mask == 0 || type[1] != '\0') 169 if (mask == 0 || type[1] != '\0')
170 error_msg_and_die(msg_invalid_arg, type, "-type"); 170 bb_error_msg_and_die(msg_invalid_arg, type, "-type");
171 171
172 return mask; 172 return mask;
173} 173}
@@ -192,22 +192,22 @@ int find_main(int argc, char **argv)
192 } 192 }
193 else if (strcmp(argv[i], "-name") == 0) { 193 else if (strcmp(argv[i], "-name") == 0) {
194 if (++i == argc) 194 if (++i == argc)
195 error_msg_and_die(msg_req_arg, "-name"); 195 bb_error_msg_and_die(msg_req_arg, "-name");
196 pattern = argv[i]; 196 pattern = argv[i];
197#ifdef CONFIG_FEATURE_FIND_TYPE 197#ifdef CONFIG_FEATURE_FIND_TYPE
198 } else if (strcmp(argv[i], "-type") == 0) { 198 } else if (strcmp(argv[i], "-type") == 0) {
199 if (++i == argc) 199 if (++i == argc)
200 error_msg_and_die(msg_req_arg, "-type"); 200 bb_error_msg_and_die(msg_req_arg, "-type");
201 type_mask = find_type(argv[i]); 201 type_mask = find_type(argv[i]);
202#endif 202#endif
203#ifdef CONFIG_FEATURE_FIND_PERM 203#ifdef CONFIG_FEATURE_FIND_PERM
204 } else if (strcmp(argv[i], "-perm") == 0) { 204 } else if (strcmp(argv[i], "-perm") == 0) {
205 char *end; 205 char *end;
206 if (++i == argc) 206 if (++i == argc)
207 error_msg_and_die(msg_req_arg, "-perm"); 207 bb_error_msg_and_die(msg_req_arg, "-perm");
208 perm_mask = strtol(argv[i], &end, 8); 208 perm_mask = strtol(argv[i], &end, 8);
209 if ((end[0] != '\0') || (perm_mask > 07777)) 209 if ((end[0] != '\0') || (perm_mask > 07777))
210 error_msg_and_die(msg_invalid_arg, argv[i], "-perm"); 210 bb_error_msg_and_die(msg_invalid_arg, argv[i], "-perm");
211 if ((perm_char = argv[i][0]) == '-') 211 if ((perm_char = argv[i][0]) == '-')
212 perm_mask = -perm_mask; 212 perm_mask = -perm_mask;
213#endif 213#endif
@@ -215,10 +215,10 @@ int find_main(int argc, char **argv)
215 } else if (strcmp(argv[i], "-mtime") == 0) { 215 } else if (strcmp(argv[i], "-mtime") == 0) {
216 char *end; 216 char *end;
217 if (++i == argc) 217 if (++i == argc)
218 error_msg_and_die(msg_req_arg, "-mtime"); 218 bb_error_msg_and_die(msg_req_arg, "-mtime");
219 mtime_days = strtol(argv[i], &end, 10); 219 mtime_days = strtol(argv[i], &end, 10);
220 if (end[0] != '\0') 220 if (end[0] != '\0')
221 error_msg_and_die(msg_invalid_arg, argv[i], "-mtime"); 221 bb_error_msg_and_die(msg_invalid_arg, argv[i], "-mtime");
222 if ((mtime_char = argv[i][0]) == '-') 222 if ((mtime_char = argv[i][0]) == '-')
223 mtime_days = -mtime_days; 223 mtime_days = -mtime_days;
224#endif 224#endif
@@ -231,14 +231,14 @@ int find_main(int argc, char **argv)
231 231
232 if ( firstopt == 1 ) { 232 if ( firstopt == 1 ) {
233 if ( stat ( ".", &stbuf ) < 0 ) 233 if ( stat ( ".", &stbuf ) < 0 )
234 error_msg_and_die("could not stat '.'" ); 234 bb_error_msg_and_die("could not stat '.'" );
235 xdev_dev [0] = stbuf. st_dev; 235 xdev_dev [0] = stbuf. st_dev;
236 } 236 }
237 else { 237 else {
238 238
239 for (i = 1; i < firstopt; i++) { 239 for (i = 1; i < firstopt; i++) {
240 if ( stat ( argv [i], &stbuf ) < 0 ) 240 if ( stat ( argv [i], &stbuf ) < 0 )
241 error_msg_and_die("could not stat '%s'", argv [i] ); 241 bb_error_msg_and_die("could not stat '%s'", argv [i] );
242 xdev_dev [i-1] = stbuf. st_dev; 242 xdev_dev [i-1] = stbuf. st_dev;
243 } 243 }
244 } 244 }
@@ -247,22 +247,22 @@ int find_main(int argc, char **argv)
247 } else if (strcmp(argv[i], "-newer") == 0) { 247 } else if (strcmp(argv[i], "-newer") == 0) {
248 struct stat stat_newer; 248 struct stat stat_newer;
249 if (++i == argc) 249 if (++i == argc)
250 error_msg_and_die(msg_req_arg, "-newer"); 250 bb_error_msg_and_die(msg_req_arg, "-newer");
251 if (stat (argv[i], &stat_newer) != 0) 251 if (stat (argv[i], &stat_newer) != 0)
252 error_msg_and_die("file %s not found", argv[i]); 252 bb_error_msg_and_die("file %s not found", argv[i]);
253 newer_mtime = stat_newer.st_mtime; 253 newer_mtime = stat_newer.st_mtime;
254#endif 254#endif
255#ifdef CONFIG_FEATURE_FIND_INUM 255#ifdef CONFIG_FEATURE_FIND_INUM
256 } else if (strcmp(argv[i], "-inum") == 0) { 256 } else if (strcmp(argv[i], "-inum") == 0) {
257 char *end; 257 char *end;
258 if (++i == argc) 258 if (++i == argc)
259 error_msg_and_die(msg_req_arg, "-inum"); 259 bb_error_msg_and_die(msg_req_arg, "-inum");
260 inode_num = strtol(argv[i], &end, 10); 260 inode_num = strtol(argv[i], &end, 10);
261 if (end[0] != '\0') 261 if (end[0] != '\0')
262 error_msg_and_die(msg_invalid_arg, argv[i], "-inum"); 262 bb_error_msg_and_die(msg_invalid_arg, argv[i], "-inum");
263#endif 263#endif
264 } else 264 } else
265 show_usage(); 265 bb_show_usage();
266 } 266 }
267 267
268 if (firstopt == 1) { 268 if (firstopt == 1) {
diff --git a/findutils/grep.c b/findutils/grep.c
index cc2b697e8..b4a25923e 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -88,8 +88,7 @@ static void grep_file(FILE *file)
88 int idx = 0; /* used for iteration through the circular buffer */ 88 int idx = 0; /* used for iteration through the circular buffer */
89#endif /* CONFIG_FEATURE_GREP_CONTEXT */ 89#endif /* CONFIG_FEATURE_GREP_CONTEXT */
90 90
91 while ((line = get_line_from_file(file)) != NULL) { 91 while ((line = bb_get_chomped_line_from_file(file)) != NULL) {
92 chomp(line);
93 linenum++; 92 linenum++;
94 93
95 for (i = 0; i < nregexes; i++) { 94 for (i = 0; i < nregexes; i++) {
@@ -154,7 +153,7 @@ static void grep_file(FILE *file)
154 /* Add the line to the circular 'before' buffer */ 153 /* Add the line to the circular 'before' buffer */
155 if(lines_before) { 154 if(lines_before) {
156 free(before_buf[curpos]); 155 free(before_buf[curpos]);
157 before_buf[curpos] = xstrdup(line); 156 before_buf[curpos] = bb_xstrdup(line);
158 curpos = (curpos + 1) % lines_before; 157 curpos = (curpos + 1) % lines_before;
159 } 158 }
160 } 159 }
@@ -205,9 +204,8 @@ static void add_regex(const char *restr)
205static void load_regexes_from_file(const char *filename) 204static void load_regexes_from_file(const char *filename)
206{ 205{
207 char *line; 206 char *line;
208 FILE *f = xfopen(filename, "r"); 207 FILE *f = bb_xfopen(filename, "r");
209 while ((line = get_line_from_file(f)) != NULL) { 208 while ((line = bb_get_chomped_line_from_file(f)) != NULL) {
210 chomp(line);
211 add_regex(line); 209 add_regex(line);
212 free(line); 210 free(line);
213 } 211 }
@@ -242,7 +240,7 @@ extern int grep_main(int argc, char **argv)
242#endif 240#endif
243 241
244#ifdef CONFIG_FEATURE_GREP_EGREP_ALIAS 242#ifdef CONFIG_FEATURE_GREP_EGREP_ALIAS
245 if (strcmp(get_last_path_component(argv[0]), "egrep") == 0) 243 if (strcmp(bb_get_last_path_component(argv[0]), "egrep") == 0)
246 reflags |= REG_EXTENDED; 244 reflags |= REG_EXTENDED;
247#endif 245#endif
248 246
@@ -298,23 +296,23 @@ extern int grep_main(int argc, char **argv)
298 case 'A': 296 case 'A':
299 lines_after = strtoul(optarg, &junk, 10); 297 lines_after = strtoul(optarg, &junk, 10);
300 if(*junk != '\0') 298 if(*junk != '\0')
301 error_msg_and_die("invalid context length argument"); 299 bb_error_msg_and_die("invalid context length argument");
302 break; 300 break;
303 case 'B': 301 case 'B':
304 lines_before = strtoul(optarg, &junk, 10); 302 lines_before = strtoul(optarg, &junk, 10);
305 if(*junk != '\0') 303 if(*junk != '\0')
306 error_msg_and_die("invalid context length argument"); 304 bb_error_msg_and_die("invalid context length argument");
307 before_buf = (char **)xcalloc(lines_before, sizeof(char *)); 305 before_buf = (char **)xcalloc(lines_before, sizeof(char *));
308 break; 306 break;
309 case 'C': 307 case 'C':
310 lines_after = lines_before = strtoul(optarg, &junk, 10); 308 lines_after = lines_before = strtoul(optarg, &junk, 10);
311 if(*junk != '\0') 309 if(*junk != '\0')
312 error_msg_and_die("invalid context length argument"); 310 bb_error_msg_and_die("invalid context length argument");
313 before_buf = (char **)xcalloc(lines_before, sizeof(char *)); 311 before_buf = (char **)xcalloc(lines_before, sizeof(char *));
314 break; 312 break;
315#endif /* CONFIG_FEATURE_GREP_CONTEXT */ 313#endif /* CONFIG_FEATURE_GREP_CONTEXT */
316 default: 314 default:
317 show_usage(); 315 bb_show_usage();
318 } 316 }
319 } 317 }
320 318
@@ -322,7 +320,7 @@ extern int grep_main(int argc, char **argv)
322 * argv[optind] should be the pattern. no pattern, no worky */ 320 * argv[optind] should be the pattern. no pattern, no worky */
323 if (nregexes == 0) { 321 if (nregexes == 0) {
324 if (argv[optind] == NULL) 322 if (argv[optind] == NULL)
325 show_usage(); 323 bb_show_usage();
326 else { 324 else {
327 add_regex(argv[optind]); 325 add_regex(argv[optind]);
328 optind++; 326 optind++;
@@ -356,7 +354,7 @@ extern int grep_main(int argc, char **argv)
356 file = fopen(cur_file, "r"); 354 file = fopen(cur_file, "r");
357 if (file == NULL) { 355 if (file == NULL) {
358 if (!suppress_err_msgs) 356 if (!suppress_err_msgs)
359 perror_msg("%s", cur_file); 357 bb_perror_msg("%s", cur_file);
360 } 358 }
361 else { 359 else {
362 grep_file(file); 360 grep_file(file);
diff --git a/findutils/xargs.c b/findutils/xargs.c
index 677618dc0..d4bed57f0 100644
--- a/findutils/xargs.c
+++ b/findutils/xargs.c
@@ -53,11 +53,11 @@ static void xargs_exec(char * const * args)
53 wait(NULL); 53 wait(NULL);
54 if(common[0]) { 54 if(common[0]) {
55 errno = common[0]; 55 errno = common[0];
56 perror_msg_and_die("%s", args[0]); 56 bb_perror_msg_and_die("%s", args[0]);
57 } 57 }
58 } 58 }
59 } else { 59 } else {
60 perror_msg_and_die("vfork"); 60 bb_perror_msg_and_die("vfork");
61 } 61 }
62} 62}
63 63
@@ -81,7 +81,7 @@ int xargs_main(int argc, char **argv)
81 flg_no_empty = 1; 81 flg_no_empty = 1;
82 break; 82 break;
83 default: 83 default:
84 show_usage(); 84 bb_show_usage();
85 } 85 }
86 } 86 }
87 87
@@ -101,9 +101,7 @@ int xargs_main(int argc, char **argv)
101 101
102 /* Now, read in one line at a time from stdin, and store this 102 /* Now, read in one line at a time from stdin, and store this
103 * line to be used later as an argument to the command */ 103 * line to be used later as an argument to the command */
104 while ((file_to_act_on = get_line_from_file(stdin)) != NULL) { 104 while ((file_to_act_on = bb_get_chomped_line_from_file(stdin)) != NULL) {
105 /* eat the newline off the filename. */
106 chomp(file_to_act_on);
107 if(file_to_act_on[0] != 0 || flg_no_empty == 0) { 105 if(file_to_act_on[0] != 0 || flg_no_empty == 0) {
108 args[a] = file_to_act_on[0] ? file_to_act_on : NULL; 106 args[a] = file_to_act_on[0] ? file_to_act_on : NULL;
109 if(flg_vi) { 107 if(flg_vi) {
@@ -114,7 +112,7 @@ int xargs_main(int argc, char **argv)
114 } 112 }
115 fprintf(stderr, "%s", ((flg_vi & 2) ? " ?..." : "\n")); 113 fprintf(stderr, "%s", ((flg_vi & 2) ? " ?..." : "\n"));
116 } 114 }
117 if((flg_vi & 2) == 0 || ask_confirmation() != 0 ) { 115 if((flg_vi & 2) == 0 || bb_ask_confirmation() != 0 ) {
118 xargs_exec(args); 116 xargs_exec(args);
119 } 117 }
120 } 118 }