pipe_stream.cc 931 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (C) 2018 Samuel Newbold
  2. #include <cstdlib>
  3. #include <list>
  4. #include <map>
  5. #include <set>
  6. #include <stdio.h>
  7. #include <string>
  8. #include <vector>
  9. #include "rwsh_stream.h"
  10. #include "variable_map.h"
  11. #include "argm.h"
  12. #include "pipe_stream.h"
  13. Pipe_istream::Pipe_istream(int fd_i) : Rwsh_istream(fd_i) {
  14. if(fd_v < 3) c_style = nullptr;
  15. else {
  16. c_style = fdopen(fd_v, "r");
  17. if (!c_style) throw Exception(Argm::File_open_failure, fd_v);}} // untested
  18. void Pipe_istream::late_init(int fd_i) {
  19. if(fd_v < 3) {
  20. fd_v = fd_i;
  21. c_style = fdopen(fd_v, "r");
  22. if (!c_style) throw Exception(Argm::File_open_failure, fd_v);}
  23. else throw Exception(Argm::Internal_error, fd_v, fd_i);}
  24. Rwsh_istream* Pipe_istream::copy_pointer(void) {std::abort();}; // not needed
  25. Rwsh_istream& Pipe_istream::getline(std::string& dest) {
  26. return read_getline(dest);}
  27. std::string Pipe_istream::str(void) const {return "|";}