diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2003-09-15 14:22:37 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2003-09-15 14:22:37 +0000 |
commit | e16ab475ad1ecaad09e714458f441057f7a49ea9 (patch) | |
tree | 80eabc02e35df39454c6c7965169457f005afb50 /miscutils | |
parent | 977451ef446fc27d7d6e40a9ba01fce5ee0e25b6 (diff) | |
download | busybox-w32-e16ab475ad1ecaad09e714458f441057f7a49ea9.tar.gz busybox-w32-e16ab475ad1ecaad09e714458f441057f7a49ea9.tar.bz2 busybox-w32-e16ab475ad1ecaad09e714458f441057f7a49ea9.zip |
Patch from Tito, Reduces the size of busybox's strings applet from 1900 to
1788 bytes (for strings.o).
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/strings.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/miscutils/strings.c b/miscutils/strings.c index 1231a93bd..4778cfb5f 100644 --- a/miscutils/strings.c +++ b/miscutils/strings.c | |||
@@ -37,10 +37,11 @@ | |||
37 | 37 | ||
38 | int strings_main(int argc, char **argv) | 38 | int strings_main(int argc, char **argv) |
39 | { | 39 | { |
40 | int n=4, c, i, opt=0, a=0, status=EXIT_SUCCESS; | 40 | int n=4, c, i, opt=0, status=EXIT_SUCCESS; |
41 | long t=0, count; | 41 | long t=0, count; |
42 | FILE *file; | 42 | FILE *file = stdin; |
43 | char *string=NULL; | 43 | char *string=NULL; |
44 | const char *fmt="%s: "; | ||
44 | 45 | ||
45 | while ((i = getopt(argc, argv, "afon:")) > 0) | 46 | while ((i = getopt(argc, argv, "afon:")) > 0) |
46 | switch(i) | 47 | switch(i) |
@@ -66,18 +67,19 @@ int strings_main(int argc, char **argv) | |||
66 | i=0; | 67 | i=0; |
67 | 68 | ||
68 | string=xmalloc(n+1); | 69 | string=xmalloc(n+1); |
69 | string[n]='\0'; | 70 | /*string[n]='\0';*/ |
70 | n-=1; | 71 | n-=1; |
71 | 72 | ||
72 | if(!argc ) | 73 | if(argc==0) |
73 | { | 74 | { |
74 | file = stdin; | 75 | fmt="{%s}: "; |
76 | *argv=(char *)bb_msg_standard_input; | ||
75 | goto pipe; | 77 | goto pipe; |
76 | } | 78 | } |
77 | 79 | ||
78 | for(a=0;a<argc;a++) | 80 | for( ;*argv!=NULL;*argv++) |
79 | { | 81 | { |
80 | if((file=fopen(argv[a],"r"))) | 82 | if((file=bb_wfopen(*argv,"r"))) |
81 | { | 83 | { |
82 | pipe: | 84 | pipe: |
83 | 85 | ||
@@ -93,7 +95,7 @@ pipe: | |||
93 | if(i==n) | 95 | if(i==n) |
94 | { | 96 | { |
95 | if(opt == 1 || opt == 3 ) | 97 | if(opt == 1 || opt == 3 ) |
96 | printf("%s: ", (!argv[a])? "{stdin}" : argv[a]); | 98 | printf(fmt,*argv); |
97 | if(opt >= 2 ) | 99 | if(opt >= 2 ) |
98 | printf("%7lo ", t); | 100 | printf("%7lo ", t); |
99 | printf("%s", string); | 101 | printf("%s", string); |
@@ -114,12 +116,9 @@ pipe: | |||
114 | bb_fclose_nonstdin(file); | 116 | bb_fclose_nonstdin(file); |
115 | } | 117 | } |
116 | else | 118 | else |
117 | { | ||
118 | bb_perror_msg("%s",argv[a]); | ||
119 | status=EXIT_FAILURE; | 119 | status=EXIT_FAILURE; |
120 | } | ||
121 | } | 120 | } |
122 | free(string); | 121 | /*free(string);*/ |
123 | exit(status); | 122 | exit(status); |
124 | } | 123 | } |
125 | 124 | ||