@@ -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,21 +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
- #pragma warning(disable : 5039)
56
- // pointer or reference to potentially throwing function passed to extern C
57
- #endif
58
- #include < direct.h>
59
- #include < windows.h>
60
- #define popen _popen
61
- #define pclose _pclose
62
- #include < util/pragma_pop.def>
63
- #endif
64
-
65
52
// / reads and source and object files, compiles and links them into goto program
66
53
// / objects.
67
54
// / \return true on error, false otherwise
@@ -221,9 +208,6 @@ bool compilet::add_files_from_archive(
221
208
const std::string &file_name,
222
209
bool thin_archive)
223
210
{
224
- std::stringstream cmd;
225
- FILE *stream;
226
-
227
211
std::string tstr = working_directory;
228
212
229
213
if (!thin_archive)
@@ -234,44 +218,40 @@ bool compilet::add_files_from_archive(
234
218
set_current_path (tmp_dirs.back ());
235
219
236
220
// unpack now
237
- cmd << " ar x " << concat_dir_file (working_directory, file_name);
238
-
239
- stream= popen (cmd. str (). c_str (), " r " );
240
- pclose (stream);
241
-
242
- cmd. clear () ;
243
- 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
+ }
244
228
}
245
229
246
230
// add the files from "ar t"
247
- cmd << " ar t " << concat_dir_file (working_directory, file_name);
248
-
249
- stream = popen (cmd.str ().c_str (), " r" );
250
-
251
- 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 )
252
239
{
253
- std::string line;
254
- int ch; // fgetc returns an int, not char
255
- while ((ch = fgetc (stream)) != EOF)
256
- {
257
- if (ch != ' \n ' )
258
- {
259
- line += static_cast <char >(ch);
260
- }
261
- else
262
- {
263
- std::string t = concat_dir_file (tstr, line);
240
+ error () << " Failed to list archive " << file_name << eom;
241
+ return true ;
242
+ }
264
243
265
- if (is_goto_binary (t))
266
- object_files.push_back (t);
267
- else
268
- debug () << " Object file is not a goto binary: " << line << eom;
244
+ std::ifstream in (tmp_file_out ());
245
+ std::string line;
269
246
270
- line = " " ;
271
- }
272
- }
247
+ while (!in. fail () && std::getline (in, line))
248
+ {
249
+ std::string t = concat_dir_file (tstr, line);
273
250
274
- 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;
275
255
}
276
256
277
257
if (!thin_archive)
0 commit comments