16
16
17
17
#include < fstream>
18
18
19
- #if defined(__linux__) || \
20
- defined (__FreeBSD_kernel__) || \
21
- defined(__GNU__) || \
22
- defined(__unix__) || \
23
- defined(__CYGWIN__) || \
24
- defined(__MACH__)
25
- #include < unistd.h>
26
- #endif
27
-
28
19
// / quote a string for bash and CMD
29
20
static std::string shell_quote (const std::string &src)
30
21
{
@@ -325,11 +316,11 @@ bool c_preprocess_visual_studio(
325
316
326
317
// use Visual Studio's CL
327
318
328
- std::string stderr_file= get_temporary_file (" tmp.stderr" , " " );
329
- std::string command_file_name= get_temporary_file (" tmp.cl-cmd" , " " );
319
+ temporary_filet stderr_file (" tmp.stderr" , " " );
320
+ temporary_filet command_file_name (" tmp.cl-cmd" , " " );
330
321
331
322
{
332
- std::ofstream command_file (command_file_name);
323
+ std::ofstream command_file (command_file_name () );
333
324
334
325
// This marks the command file as UTF-8, which Visual Studio
335
326
// understands.
@@ -379,23 +370,20 @@ bool c_preprocess_visual_studio(
379
370
command_file << shell_quote (file) << " \n " ;
380
371
}
381
372
382
- std::string tmpi= get_temporary_file (" tmp.cl" , " " );
373
+ temporary_filet tmpi (" tmp.cl" , " " );
383
374
384
- std::string command= " CL @\" " + command_file_name+ " \" " ;
385
- command+= " > \" " + tmpi+ " \" " ;
386
- command+= " 2> \" " + stderr_file+ " \" " ;
375
+ std::string command = " CL @\" " + command_file_name () + " \" " ;
376
+ command += " > \" " + tmpi () + " \" " ;
377
+ command += " 2> \" " + stderr_file () + " \" " ;
387
378
388
379
// _popen isn't very reliable on WIN32
389
380
// that's why we use system()
390
381
int result=system (command.c_str ());
391
382
392
- std::ifstream instream (tmpi);
383
+ std::ifstream instream (tmpi () );
393
384
394
385
if (!instream)
395
386
{
396
- unlink (tmpi.c_str ());
397
- unlink (stderr_file.c_str ());
398
- unlink (command_file_name.c_str ());
399
387
message.error () << " CL Preprocessing failed (open failed)"
400
388
<< messaget::eom;
401
389
return true ;
@@ -404,15 +392,11 @@ bool c_preprocess_visual_studio(
404
392
outstream << instream.rdbuf (); // copy
405
393
406
394
instream.close ();
407
- unlink (tmpi.c_str ());
408
- unlink (command_file_name.c_str ());
409
395
410
396
// errors/warnings
411
- std::ifstream stderr_stream (stderr_file);
397
+ std::ifstream stderr_stream (stderr_file () );
412
398
error_parse (stderr_stream, result==0 , message);
413
399
414
- unlink (stderr_file.c_str ());
415
-
416
400
if (result!=0 )
417
401
{
418
402
message.error () << " CL Preprocessing failed" << messaget::eom;
@@ -471,7 +455,7 @@ bool c_preprocess_codewarrior(
471
455
// preprocessing
472
456
messaget message (message_handler);
473
457
474
- std::string stderr_file= get_temporary_file (" tmp.stderr" , " " );
458
+ temporary_filet stderr_file (" tmp.stderr" , " " );
475
459
476
460
std::string command;
477
461
@@ -491,37 +475,32 @@ bool c_preprocess_codewarrior(
491
475
492
476
int result;
493
477
494
- std::string tmpi= get_temporary_file (" tmp.cl" , " " );
478
+ temporary_filet tmpi (" tmp.cl" , " " );
495
479
command+=" \" " +file+" \" " ;
496
- command+= " -o \" " + tmpi+ " \" " ;
497
- command+= " 2> \" " + stderr_file+ " \" " ;
480
+ command += " -o \" " + tmpi () + " \" " ;
481
+ command += " 2> \" " + stderr_file () + " \" " ;
498
482
499
483
result=system (command.c_str ());
500
484
501
- std::ifstream stream_i (tmpi);
485
+ std::ifstream stream_i (tmpi () );
502
486
503
487
if (stream_i)
504
488
{
505
489
postprocess_codewarrior (stream_i, outstream);
506
490
507
491
stream_i.close ();
508
- unlink (tmpi.c_str ());
509
492
}
510
493
else
511
494
{
512
- unlink (tmpi.c_str ());
513
- unlink (stderr_file.c_str ());
514
495
message.error () << " Preprocessing failed (fopen failed)"
515
496
<< messaget::eom;
516
497
return true ;
517
498
}
518
499
519
500
// errors/warnings
520
- std::ifstream stderr_stream (stderr_file);
501
+ std::ifstream stderr_stream (stderr_file () );
521
502
error_parse (stderr_stream, result==0 , message);
522
503
523
- unlink (stderr_file.c_str ());
524
-
525
504
if (result!=0 )
526
505
{
527
506
message.error () << " Preprocessing failed" << messaget::eom;
@@ -545,7 +524,7 @@ bool c_preprocess_gcc_clang(
545
524
// preprocessing
546
525
messaget message (message_handler);
547
526
548
- std::string stderr_file= get_temporary_file (" tmp.stderr" , " " );
527
+ temporary_filet stderr_file (" tmp.stderr" , " " );
549
528
550
529
std::string command;
551
530
@@ -645,39 +624,35 @@ bool c_preprocess_gcc_clang(
645
624
#endif
646
625
647
626
#ifdef _WIN32
648
- std::string tmpi= get_temporary_file (" tmp.gcc" , " " );
627
+ temporary_filet tmpi (" tmp.gcc" , " " );
649
628
command+=" \" " +file+" \" " ;
650
- command+= " -o \" " + tmpi+ " \" " ;
651
- command+= " 2> \" " + stderr_file+ " \" " ;
629
+ command += " -o \" " + tmpi () + " \" " ;
630
+ command += " 2> \" " + stderr_file () + " \" " ;
652
631
653
632
// _popen isn't very reliable on WIN32
654
633
// that's why we use system() and a temporary file
655
634
result=system (command.c_str ());
656
635
657
- std::ifstream instream (tmpi);
636
+ std::ifstream instream (tmpi () );
658
637
659
638
// errors/warnings
660
- std::ifstream stderr_stream (stderr_file);
639
+ std::ifstream stderr_stream (stderr_file () );
661
640
error_parse (stderr_stream, result==0 , message);
662
641
663
- unlink (stderr_file.c_str ());
664
-
665
642
if (instream)
666
643
{
667
644
outstream << instream.rdbuf ();
668
645
instream.close ();
669
- unlink (tmpi.c_str ());
670
646
}
671
647
else
672
648
{
673
- unlink (tmpi.c_str ());
674
649
message.error () << " GCC preprocessing failed (open failed)"
675
650
<< messaget::eom;
676
651
result=1 ;
677
652
}
678
653
#else
679
654
command+=" \" " +file+" \" " ;
680
- command+= " 2> \" " + stderr_file+ " \" " ;
655
+ command += " 2> \" " + stderr_file () + " \" " ;
681
656
682
657
FILE *stream=popen (command.c_str (), " r" );
683
658
@@ -697,11 +672,9 @@ bool c_preprocess_gcc_clang(
697
672
}
698
673
699
674
// errors/warnings
700
- std::ifstream stderr_stream (stderr_file);
675
+ std::ifstream stderr_stream (stderr_file () );
701
676
error_parse (stderr_stream, result==0 , message);
702
677
703
- unlink (stderr_file.c_str ());
704
-
705
678
#endif
706
679
707
680
if (result!=0 )
@@ -726,7 +699,7 @@ bool c_preprocess_arm(
726
699
// preprocessing using armcc
727
700
messaget message (message_handler);
728
701
729
- std::string stderr_file= get_temporary_file (" tmp.stderr" , " " );
702
+ temporary_filet stderr_file (" tmp.stderr" , " " );
730
703
731
704
std::string command;
732
705
@@ -764,34 +737,31 @@ bool c_preprocess_arm(
764
737
int result;
765
738
766
739
#ifdef _WIN32
767
- std::string tmpi= get_temporary_file (" tmp.cl" , " " );
740
+ temporary_filet tmpi (" tmp.cl" , " " );
768
741
command+=" \" " +file+" \" " ;
769
- command+= " > \" " + tmpi+ " \" " ;
770
- command+= " 2> \" " + stderr_file+ " \" " ;
742
+ command += " > \" " + tmpi () + " \" " ;
743
+ command += " 2> \" " + stderr_file () + " \" " ;
771
744
772
745
// _popen isn't very reliable on WIN32
773
746
// that's why we use system() and a temporary file
774
747
result=system (command.c_str ());
775
748
776
- std::ifstream instream (tmpi);
749
+ std::ifstream instream (tmpi () );
777
750
778
751
if (!instream)
779
752
{
780
753
outstream << instream.rdbuf (); // copy
781
754
instream.close ();
782
- unlink (tmpi.c_str ());
783
755
}
784
756
else
785
757
{
786
- unlink (tmpi.c_str ());
787
- unlink (stderr_file.c_str ());
788
758
message.error () << " ARMCC preprocessing failed (fopen failed)"
789
759
<< messaget::eom;
790
760
return true ;
791
761
}
792
762
#else
793
763
command+=" \" " +file+" \" " ;
794
- command+= " 2> \" " + stderr_file+ " \" " ;
764
+ command += " 2> \" " + stderr_file () + " \" " ;
795
765
796
766
FILE *stream=popen (command.c_str (), " r" );
797
767
@@ -805,19 +775,16 @@ bool c_preprocess_arm(
805
775
}
806
776
else
807
777
{
808
- unlink (stderr_file.c_str ());
809
778
message.error () << " ARMCC preprocessing failed (popen failed)"
810
779
<< messaget::eom;
811
780
return true ;
812
781
}
813
782
#endif
814
783
815
784
// errors/warnings
816
- std::ifstream stderr_stream (stderr_file);
785
+ std::ifstream stderr_stream (stderr_file () );
817
786
error_parse (stderr_stream, result==0 , message);
818
787
819
- unlink (stderr_file.c_str ());
820
-
821
788
if (result!=0 )
822
789
{
823
790
message.error () << " ARMCC preprocessing failed" << messaget::eom;
0 commit comments