| 701 | |
| 702 | |
| 703 | static void read_pipe |
| 704 | ( |
| 705 | HANDLE in, /* the pipe to read from */ |
| 706 | string * out |
| 707 | ) |
| 708 | { |
| 709 | DWORD bytesInBuffer = 0; |
| 710 | DWORD bytesAvailable = 0; |
| 711 | |
| 712 | do |
| 713 | { |
| 714 | /* check if we have any data to read */ |
| 715 | if ( !PeekNamedPipe( in, ioBuffer, IO_BUFFER_SIZE, &bytesInBuffer, |
| 716 | &bytesAvailable, NULL ) ) |
| 717 | bytesAvailable = 0; |
| 718 | |
| 719 | /* read in the available data */ |
| 720 | if ( bytesAvailable > 0 ) |
| 721 | { |
| 722 | /* we only read in the available bytes, to avoid blocking */ |
| 723 | if ( ReadFile( in, ioBuffer, bytesAvailable <= IO_BUFFER_SIZE ? |
| 724 | bytesAvailable : IO_BUFFER_SIZE, &bytesInBuffer, NULL ) ) |
| 725 | { |
| 726 | if ( bytesInBuffer > 0 ) |
| 727 | { |
| 728 | /* Clean up some illegal chars. */ |
| 729 | int i; |
| 730 | for ( i = 0; i < bytesInBuffer; ++i ) |
| 731 | { |
| 732 | if ( ( (unsigned char)ioBuffer[ i ] < 1 ) ) |
| 733 | ioBuffer[ i ] = '?'; |
| 734 | } |
| 735 | /* Null, terminate. */ |
| 736 | ioBuffer[ bytesInBuffer ] = '\0'; |
| 737 | /* Append to the output. */ |
| 738 | string_append( out, ioBuffer ); |
| 739 | /* Subtract what we read in. */ |
| 740 | bytesAvailable -= bytesInBuffer; |
| 741 | } |
| 742 | else |
| 743 | { |
| 744 | /* Likely read a error, bail out. */ |
| 745 | bytesAvailable = 0; |
| 746 | } |
| 747 | } |
| 748 | else |
| 749 | { |
| 750 | /* Definitely read a error, bail out. */ |
| 751 | bytesAvailable = 0; |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | while ( bytesAvailable > 0 ); |
| 756 | } |
| 757 | |
| 758 | |
| 759 | static void read_output() |
no test coverage detected