projects
/
oweals
/
busybox.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
"insmod caches the symbolname in a variable before modifying it and uses
[oweals/busybox.git]
/
miscutils
/
strings.c
diff --git
a/miscutils/strings.c
b/miscutils/strings.c
index 9d8012aa22f4b76d21d8ad8644419c45d63b923d..1231a93bd05f8999fb25560fae17e7bc1d272a4f 100644
(file)
--- a/
miscutils/strings.c
+++ b/
miscutils/strings.c
@@
-21,7
+21,7
@@
*
* Original copyright notice is retained at the end of this file.
*
*
* Original copyright notice is retained at the end of this file.
*
- * Modified for BusyBox by Erik Andersen <anderse
e@debian
.org>
+ * Modified for BusyBox by Erik Andersen <anderse
n@codepoet
.org>
* Badly hacked by Tito Ragusa <farmatito@tiscali.it>
*/
* Badly hacked by Tito Ragusa <farmatito@tiscali.it>
*/
@@
-37,32
+37,27
@@
int strings_main(int argc, char **argv)
{
int strings_main(int argc, char **argv)
{
- extern char *optarg;
- extern int optind;
- int n=4, c, i, opt=0, a=0;
- long t, count;
+ int n=4, c, i, opt=0, a=0, status=EXIT_SUCCESS;
+ long t=0, count;
FILE *file;
FILE *file;
- char *string;
-
- while ((i = getopt(argc, argv, "a
n:of
")) > 0)
+ char *string
=NULL
;
+
+ while ((i = getopt(argc, argv, "a
fon:
")) > 0)
switch(i)
{
case 'a':
break;
case 'f':
switch(i)
{
case 'a':
break;
case 'f':
- opt++;
- break;
- case 'n':
- n = atoi(optarg);
- if(!(n/1))
- show_usage();
+ opt+=1;
break;
case 'o':
break;
case 'o':
- opt++;
- opt++;
+ opt+=2;
+ break;
+ case 'n':
+ n = bb_xgetlarg(optarg, 10, 1, INT_MAX);
break;
default:
break;
default:
- show_usage();
+
bb_
show_usage();
}
argc -= optind;
}
argc -= optind;
@@
-70,6
+65,10
@@
int strings_main(int argc, char **argv)
i=0;
i=0;
+ string=xmalloc(n+1);
+ string[n]='\0';
+ n-=1;
+
if(!argc )
{
file = stdin;
if(!argc )
{
file = stdin;
@@
-78,50
+77,50
@@
int strings_main(int argc, char **argv)
for(a=0;a<argc;a++)
{
for(a=0;a<argc;a++)
{
- file=xfopen(argv[a],"r");
-
- pipe:
-
- count=0;
- string=xmalloc(n);
- string[n]='\0';
- n--;
- while(1)
+ if((file=fopen(argv[a],"r")))
{
{
- c=fgetc(file);
- if(ISSTR(c))
- {
- if(i==0)
- t=count;
- if(i<=n)
- string[i]=c;
- if(i==n)
+pipe:
+
+ count=0;
+ do{
+ c=fgetc(file);
+ if(ISSTR(c))
{
{
- if(opt == 1 || opt == 3 )
- printf("%s: ",(!argv[a])?"{stdin}":argv[a]);
- if(opt >= 2 )
- printf("%7lo ",t);
- printf("%s",string);
+ if(i==0)
+ t=count;
+ if(i<=n)
+ string[i]=c;
+ if(i==n)
+ {
+ if(opt == 1 || opt == 3 )
+ printf("%s: ", (!argv[a])? "{stdin}" : argv[a]);
+ if(opt >= 2 )
+ printf("%7lo ", t);
+ printf("%s", string);
+ }
+ if(i>n)
+ putchar(c);
+ i++;
}
}
- if(i>n)
- putchar(c);
- i++;
- }
- else
- {
- if(i>n)
- puts("");
- i=0;
- }
- count++;
- if(c==EOF)
- break;
+ else
+ {
+ if(i>n)
+ putchar('\n');
+ i=0;
+ }
+ count++;
+ }while(c!=EOF);
+
+ bb_fclose_nonstdin(file);
+ }
+ else
+ {
+ bb_perror_msg("%s",argv[a]);
+ status=EXIT_FAILURE;
}
}
- if(file!=stdin)
- fclose(file);
}
free(string);
}
free(string);
- exit(
EXIT_SUCCESS
);
+ exit(
status
);
}
/*
}
/*