@@ -21,9 +21,11 @@ Date: June 2006
21
21
#include < util/config.h>
22
22
#include < util/file_util.h>
23
23
#include < util/get_base_name.h>
24
+ #include < util/run.h>
24
25
#include < util/suffix.h>
25
26
#include < util/symbol_table_builder.h>
26
27
#include < util/tempdir.h>
28
+ #include < util/tempfile.h>
27
29
#include < util/unicode.h>
28
30
#include < util/version.h>
29
31
@@ -47,19 +49,6 @@ Date: June 2006
47
49
" size=\" 30,40\" ;" \
48
50
" ratio=compress;"
49
51
50
- #ifdef _WIN32
51
- #include < util/pragma_push.def>
52
- #ifdef _MSC_VER
53
- #pragma warning(disable:4668)
54
- // using #if/#elif on undefined macro
55
- #endif
56
- #include < direct.h>
57
- #include < windows.h>
58
- #define popen _popen
59
- #define pclose _pclose
60
- #include < util/pragma_pop.def>
61
- #endif
62
-
63
52
// / reads and source and object files, compiles and links them into goto program
64
53
// / objects.
65
54
// / \return true on error, false otherwise
@@ -219,9 +208,6 @@ bool compilet::add_files_from_archive(
219
208
const std::string &file_name,
220
209
bool thin_archive)
221
210
{
222
- std::stringstream cmd;
223
- FILE *stream;
224
-
225
211
std::string tstr = working_directory;
226
212
227
213
if (!thin_archive)
@@ -232,44 +218,40 @@ bool compilet::add_files_from_archive(
232
218
set_current_path (tmp_dirs.back ());
233
219
234
220
// unpack now
235
- cmd << " ar x " << concat_dir_file (working_directory, file_name);
236
-
237
- stream= popen (cmd. str (). c_str (), " r " );
238
- pclose (stream);
239
-
240
- cmd. clear () ;
241
- cmd. str ( " " );
221
+ int ret =
222
+ run ( " ar " , { " ar " , " x " , concat_dir_file (working_directory, file_name)});
223
+ if (ret != 0 )
224
+ {
225
+ error () << " Failed to extract archive " << file_name << eom;
226
+ return true ;
227
+ }
242
228
}
243
229
244
230
// add the files from "ar t"
245
- cmd << " ar t " << concat_dir_file (working_directory, file_name);
246
-
247
- stream = popen (cmd.str ().c_str (), " r" );
248
-
249
- if (stream != nullptr )
231
+ temporary_filet tmp_file_out (" " , " " );
232
+ int ret = run (
233
+ " ar" ,
234
+ {" ar" , " t" , concat_dir_file (working_directory, file_name)},
235
+ " " ,
236
+ tmp_file_out (),
237
+ " " );
238
+ if (ret != 0 )
250
239
{
251
- std::string line;
252
- int ch; // fgetc returns an int, not char
253
- while ((ch = fgetc (stream)) != EOF)
254
- {
255
- if (ch != ' \n ' )
256
- {
257
- line += static_cast <char >(ch);
258
- }
259
- else
260
- {
261
- std::string t = concat_dir_file (tstr, line);
240
+ error () << " Failed to list archive " << file_name << eom;
241
+ return true ;
242
+ }
262
243
263
- if (is_goto_binary (t))
264
- object_files.push_back (t);
265
- else
266
- debug () << " Object file is not a goto binary: " << line << eom;
244
+ std::ifstream in (tmp_file_out ());
245
+ std::string line;
267
246
268
- line = " " ;
269
- }
270
- }
247
+ while (!in. fail () && std::getline (in, line))
248
+ {
249
+ std::string t = concat_dir_file (tstr, line);
271
250
272
- pclose (stream);
251
+ if (is_goto_binary (t))
252
+ object_files.push_back (t);
253
+ else
254
+ debug () << " Object file is not a goto binary: " << line << eom;
273
255
}
274
256
275
257
if (!thin_archive)
0 commit comments