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