@@ -89,7 +89,7 @@ static FILE* create_fopen(char* name, char* mode, int subdirs)
89
89
90
90
static int unzzip_cat (int argc , char * * argv , int extract )
91
91
{
92
- int done ;
92
+ int done = 0 ;
93
93
int argn ;
94
94
ZZIP_MEM_DISK * disk ;
95
95
@@ -116,47 +116,50 @@ static int unzzip_cat (int argc, char ** argv, int extract)
116
116
FILE * out = stdout ;
117
117
if (extract ) out = create_fopen (name , "wb" , 1 );
118
118
if (! out ) {
119
- if (errno != EISDIR ) done = EXIT_ERRORS ;
119
+ if (errno != EISDIR ) {
120
+ DBG3 ("can not open output file %i %s" , errno , strerror (errno ));
121
+ done = EXIT_ERRORS ;
122
+ }
120
123
continue ;
121
124
}
122
125
unzzip_mem_disk_cat_file (disk , name , out );
123
126
if (extract ) fclose (out );
124
127
}
125
- return done ;
126
- }
127
-
128
- if (argc == 3 && !extract )
128
+ }
129
+ else if (argc == 3 && !extract )
129
130
{ /* list from one spec */
130
131
ZZIP_MEM_ENTRY * entry = 0 ;
131
132
while ((entry = zzip_mem_disk_findmatch (disk , argv [2 ], entry , 0 , 0 )))
132
133
{
133
134
unzzip_mem_entry_fprint (disk , entry , stdout );
134
135
}
135
-
136
- return 0 ;
137
- }
138
-
139
- for (argn = 1 ; argn < argc ; argn ++ )
140
- { /* list only the matching entries - each in order of commandline */
141
- ZZIP_MEM_ENTRY * entry = zzip_mem_disk_findfirst (disk );
142
- for (; entry ; entry = zzip_mem_disk_findnext (disk , entry ))
143
- {
144
- char * name = zzip_mem_entry_to_name (entry );
145
- if (! _zzip_fnmatch (argv [argn ], name ,
146
- _zzip_FNM_NOESCAPE |_zzip_FNM_PATHNAME |_zzip_FNM_PERIOD ))
136
+ } else {
137
+ for (argn = 1 ; argn < argc ; argn ++ )
138
+ { /* list only the matching entries - each in order of commandline */
139
+ ZZIP_MEM_ENTRY * entry = zzip_mem_disk_findfirst (disk );
140
+ for (; entry ; entry = zzip_mem_disk_findnext (disk , entry ))
147
141
{
148
- FILE * out = stdout ;
149
- if (extract ) out = create_fopen (name , "wb" , 1 );
150
- if (! out ) {
151
- if (errno != EISDIR ) done = EXIT_ERRORS ;
152
- continue ;
153
- }
154
- unzzip_mem_disk_cat_file (disk , name , out );
155
- if (extract ) fclose (out );
156
- break ; /* match loop */
142
+ char * name = zzip_mem_entry_to_name (entry );
143
+ if (! _zzip_fnmatch (argv [argn ], name ,
144
+ _zzip_FNM_NOESCAPE |_zzip_FNM_PATHNAME |_zzip_FNM_PERIOD ))
145
+ {
146
+ FILE * out = stdout ;
147
+ if (extract ) out = create_fopen (name , "wb" , 1 );
148
+ if (! out ) {
149
+ if (errno != EISDIR ) {
150
+ DBG3 ("can not open output file %i %s" , errno , strerror (errno ));
151
+ done = EXIT_ERRORS ;
152
+ }
153
+ continue ;
154
+ }
155
+ unzzip_mem_disk_cat_file (disk , name , out );
156
+ if (extract ) fclose (out );
157
+ break ; /* match loop */
158
+ }
157
159
}
158
160
}
159
161
}
162
+ zzip_mem_disk_close (disk );
160
163
return done ;
161
164
}
162
165
0 commit comments