#include "shell.hpp" // open a file, and read chunks of data until we reach EOF, // printing the data found to stdout void shell::c_cat (std::string args) { // sanity checks if ( ! cwd_.exists (args) ) { carp ("No such file: " + args); return; } if ( cwd_.is_dir (args) ) { carp ("Cannot cat directory: " + args); return; } // open the current directory as filesystem dir saga::filesystem::directory dir (cwd_.get_url ()); // open the file saga::filesystem::file file = dir.open (args, saga::filesystem::Read); while ( true ) { saga::size_t const n = 1024*64; saga::uint8_t data[n+1]; for ( unsigned int i = 0; i <= n; ++i ) { data[i] = '\0'; } // read a chunk into the buffer if ( file.read (saga::buffer (data, n), n) ) { // show what we found std::cout << data; } else { break; } } // file closes when going out of scope return; }