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.
@@ -385,23 +376,20 @@ bool c_preprocess_visual_studio(
385
376
command_file << shell_quote (file) << " \n " ;
386
377
}
387
378
388
- std::string tmpi= get_temporary_file (" tmp.cl" , " " );
379
+ temporary_filet tmpi (" tmp.cl" , " " );
389
380
390
- std::string command= " CL @\" " + command_file_name+ " \" " ;
391
- command+= " > \" " + tmpi+ " \" " ;
392
- command+= " 2> \" " + stderr_file+ " \" " ;
381
+ std::string command = " CL @\" " + command_file_name () + " \" " ;
382
+ command += " > \" " + tmpi () + " \" " ;
383
+ command += " 2> \" " + stderr_file () + " \" " ;
393
384
394
385
// _popen isn't very reliable on WIN32
395
386
// that's why we use system()
396
387
int result=system (command.c_str ());
397
388
398
- std::ifstream instream (tmpi);
389
+ std::ifstream instream (tmpi () );
399
390
400
391
if (!instream)
401
392
{
402
- unlink (tmpi.c_str ());
403
- unlink (stderr_file.c_str ());
404
- unlink (command_file_name.c_str ());
405
393
message.error () << " CL Preprocessing failed (open failed)"
406
394
<< messaget::eom;
407
395
return true ;
@@ -410,15 +398,11 @@ bool c_preprocess_visual_studio(
410
398
outstream << instream.rdbuf (); // copy
411
399
412
400
instream.close ();
413
- unlink (tmpi.c_str ());
414
- unlink (command_file_name.c_str ());
415
401
416
402
// errors/warnings
417
- std::ifstream stderr_stream (stderr_file);
403
+ std::ifstream stderr_stream (stderr_file () );
418
404
error_parse (stderr_stream, result==0 , message);
419
405
420
- unlink (stderr_file.c_str ());
421
-
422
406
if (result!=0 )
423
407
{
424
408
message.error () << " CL Preprocessing failed" << messaget::eom;
@@ -477,7 +461,7 @@ bool c_preprocess_codewarrior(
477
461
// preprocessing
478
462
messaget message (message_handler);
479
463
480
- std::string stderr_file= get_temporary_file (" tmp.stderr" , " " );
464
+ temporary_filet stderr_file (" tmp.stderr" , " " );
481
465
482
466
std::string command;
483
467
@@ -497,37 +481,32 @@ bool c_preprocess_codewarrior(
497
481
498
482
int result;
499
483
500
- std::string tmpi= get_temporary_file (" tmp.cl" , " " );
484
+ temporary_filet tmpi (" tmp.cl" , " " );
501
485
command+=" \" " +file+" \" " ;
502
- command+= " -o \" " + tmpi+ " \" " ;
503
- command+= " 2> \" " + stderr_file+ " \" " ;
486
+ command += " -o \" " + tmpi () + " \" " ;
487
+ command += " 2> \" " + stderr_file () + " \" " ;
504
488
505
489
result=system (command.c_str ());
506
490
507
- std::ifstream stream_i (tmpi);
491
+ std::ifstream stream_i (tmpi () );
508
492
509
493
if (stream_i)
510
494
{
511
495
postprocess_codewarrior (stream_i, outstream);
512
496
513
497
stream_i.close ();
514
- unlink (tmpi.c_str ());
515
498
}
516
499
else
517
500
{
518
- unlink (tmpi.c_str ());
519
- unlink (stderr_file.c_str ());
520
501
message.error () << " Preprocessing failed (fopen failed)"
521
502
<< messaget::eom;
522
503
return true ;
523
504
}
524
505
525
506
// errors/warnings
526
- std::ifstream stderr_stream (stderr_file);
507
+ std::ifstream stderr_stream (stderr_file () );
527
508
error_parse (stderr_stream, result==0 , message);
528
509
529
- unlink (stderr_file.c_str ());
530
-
531
510
if (result!=0 )
532
511
{
533
512
message.error () << " Preprocessing failed" << messaget::eom;
@@ -551,7 +530,7 @@ bool c_preprocess_gcc_clang(
551
530
// preprocessing
552
531
messaget message (message_handler);
553
532
554
- std::string stderr_file= get_temporary_file (" tmp.stderr" , " " );
533
+ temporary_filet stderr_file (" tmp.stderr" , " " );
555
534
556
535
std::string command;
557
536
@@ -651,39 +630,35 @@ bool c_preprocess_gcc_clang(
651
630
#endif
652
631
653
632
#ifdef _WIN32
654
- std::string tmpi= get_temporary_file (" tmp.gcc" , " " );
633
+ temporary_filet tmpi (" tmp.gcc" , " " );
655
634
command+=" \" " +file+" \" " ;
656
- command+= " -o \" " + tmpi+ " \" " ;
657
- command+= " 2> \" " + stderr_file+ " \" " ;
635
+ command += " -o \" " + tmpi () + " \" " ;
636
+ command += " 2> \" " + stderr_file () + " \" " ;
658
637
659
638
// _popen isn't very reliable on WIN32
660
639
// that's why we use system() and a temporary file
661
640
result=system (command.c_str ());
662
641
663
- std::ifstream instream (tmpi);
642
+ std::ifstream instream (tmpi () );
664
643
665
644
// errors/warnings
666
- std::ifstream stderr_stream (stderr_file);
645
+ std::ifstream stderr_stream (stderr_file () );
667
646
error_parse (stderr_stream, result==0 , message);
668
647
669
- unlink (stderr_file.c_str ());
670
-
671
648
if (instream)
672
649
{
673
650
outstream << instream.rdbuf ();
674
651
instream.close ();
675
- unlink (tmpi.c_str ());
676
652
}
677
653
else
678
654
{
679
- unlink (tmpi.c_str ());
680
655
message.error () << " GCC preprocessing failed (open failed)"
681
656
<< messaget::eom;
682
657
result=1 ;
683
658
}
684
659
#else
685
660
command+=" \" " +file+" \" " ;
686
- command+= " 2> \" " + stderr_file+ " \" " ;
661
+ command += " 2> \" " + stderr_file () + " \" " ;
687
662
688
663
FILE *stream=popen (command.c_str (), " r" );
689
664
@@ -703,11 +678,9 @@ bool c_preprocess_gcc_clang(
703
678
}
704
679
705
680
// errors/warnings
706
- std::ifstream stderr_stream (stderr_file);
681
+ std::ifstream stderr_stream (stderr_file () );
707
682
error_parse (stderr_stream, result==0 , message);
708
683
709
- unlink (stderr_file.c_str ());
710
-
711
684
#endif
712
685
713
686
if (result!=0 )
@@ -732,7 +705,7 @@ bool c_preprocess_arm(
732
705
// preprocessing using armcc
733
706
messaget message (message_handler);
734
707
735
- std::string stderr_file= get_temporary_file (" tmp.stderr" , " " );
708
+ temporary_filet stderr_file (" tmp.stderr" , " " );
736
709
737
710
std::string command;
738
711
@@ -770,34 +743,31 @@ bool c_preprocess_arm(
770
743
int result;
771
744
772
745
#ifdef _WIN32
773
- std::string tmpi= get_temporary_file (" tmp.cl" , " " );
746
+ temporary_filet tmpi (" tmp.cl" , " " );
774
747
command+=" \" " +file+" \" " ;
775
- command+= " > \" " + tmpi+ " \" " ;
776
- command+= " 2> \" " + stderr_file+ " \" " ;
748
+ command += " > \" " + tmpi () + " \" " ;
749
+ command += " 2> \" " + stderr_file () + " \" " ;
777
750
778
751
// _popen isn't very reliable on WIN32
779
752
// that's why we use system() and a temporary file
780
753
result=system (command.c_str ());
781
754
782
- std::ifstream instream (tmpi);
755
+ std::ifstream instream (tmpi () );
783
756
784
757
if (!instream)
785
758
{
786
759
outstream << instream.rdbuf (); // copy
787
760
instream.close ();
788
- unlink (tmpi.c_str ());
789
761
}
790
762
else
791
763
{
792
- unlink (tmpi.c_str ());
793
- unlink (stderr_file.c_str ());
794
764
message.error () << " ARMCC preprocessing failed (fopen failed)"
795
765
<< messaget::eom;
796
766
return true ;
797
767
}
798
768
#else
799
769
command+=" \" " +file+" \" " ;
800
- command+= " 2> \" " + stderr_file+ " \" " ;
770
+ command += " 2> \" " + stderr_file () + " \" " ;
801
771
802
772
FILE *stream=popen (command.c_str (), " r" );
803
773
@@ -811,19 +781,16 @@ bool c_preprocess_arm(
811
781
}
812
782
else
813
783
{
814
- unlink (stderr_file.c_str ());
815
784
message.error () << " ARMCC preprocessing failed (popen failed)"
816
785
<< messaget::eom;
817
786
return true ;
818
787
}
819
788
#endif
820
789
821
790
// errors/warnings
822
- std::ifstream stderr_stream (stderr_file);
791
+ std::ifstream stderr_stream (stderr_file () );
823
792
error_parse (stderr_stream, result==0 , message);
824
793
825
- unlink (stderr_file.c_str ());
826
-
827
794
if (result!=0 )
828
795
{
829
796
message.error () << " ARMCC preprocessing failed" << messaget::eom;
0 commit comments