fork download
  1. class c_file {
  2. private:
  3. FILE *_c_file;
  4. buffer _buffer; // Buffer object. Handles a surprising amount of underlying logic.
  5. std::string _file;
  6. uint32 _write_from; // What's our real position? this is the start of the current _buffer.
  7. uint32 _size; // What's the size of our file?
  8. uint32 _valid; // Are we invalid for some reason?
  9. uint32 _open; // Is our file open?
  10. uint32 _flush_needed; // How much we've written to _buffer since our last flush()
  11. uint32 _file_buffer_start; // "Virtual" position (where in the file the _buffer is located)
  12.  
  13. // Opening attributes
  14. uint32 _readonly;
  15. uint32 _append;
  16. uint32 _binary;
  17. uint32 _create;
  18. uint32 _write;
  19.  
  20. uint32 _read_fillbuf(); // Fills the rest of the buffer with a read
  21. void _do_seek_needed(); // The macro was killing us! To DEATH!
  22.  
  23. c_file(const c_file& other ); // non construction-copyable
  24. c_file& operator=( const c_file& ); // non copyable
  25.  
  26. public:
  27. explicit c_file();
  28. ~c_file();
  29.  
  30. uint32 open(fattribute const &params); // Opens
  31. uint32 position() { return _file_buffer_start + _buffer.index(); }
  32. uint32 close(); // Closes
  33. uint32 flush();
  34. uint32 set_buffer_size(uint32 size);
  35.  
  36. uint32 is_valid() { return _valid; } // C files are *only* valid when they are open. They can become invalid when certain functions fail like open() (because something is already open)
  37. uint32 is_open() { return _open; } //
  38. uint32 size() { return _size; }
  39.  
  40. uint32 seek(const uint32 whereto);
  41. uint32 write(const void *buf, const uint32 length); // Writes
  42. uint32 read(void *buf, const uint32 length); // Reads
  43.  
  44. // Read a line...The file should still be opened as binary! This is CR/LF neutral.
  45. // NOTE THAT IT RETURNS maxlen IF IT FAILS (since the final byte will always be a c-str terminating NULL. 500 will read 499 bytes max.)
  46. uint32 readline(uint8 *dest,uint32 maxlen);
  47.  
  48. // Write a line. Um, if it fails, well, you know.
  49. uint32 writeline(std::string& line);
  50.  
  51. // Check if we're EOF
  52. uint32 eof() { if (!_valid) return 2; if (_file_buffer_start + _buffer.index() >= _size) return 1; else return 0; }
  53.  
  54. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3: error: ISO C++ forbids declaration of ‘FILE’ with no type
prog.cpp:3: error: expected ‘;’ before ‘*’ token
prog.cpp:4: error: ‘buffer’ does not name a type
prog.cpp:5: error: ‘string’ in namespace ‘std’ does not name a type
prog.cpp:6: error: ‘uint32’ does not name a type
prog.cpp:7: error: ‘uint32’ does not name a type
prog.cpp:8: error: ‘uint32’ does not name a type
prog.cpp:9: error: ‘uint32’ does not name a type
prog.cpp:10: error: ‘uint32’ does not name a type
prog.cpp:11: error: ‘uint32’ does not name a type
prog.cpp:14: error: ‘uint32’ does not name a type
prog.cpp:15: error: ‘uint32’ does not name a type
prog.cpp:16: error: ‘uint32’ does not name a type
prog.cpp:17: error: ‘uint32’ does not name a type
prog.cpp:18: error: ‘uint32’ does not name a type
prog.cpp:20: error: ‘uint32’ does not name a type
prog.cpp:30: error: ‘uint32’ does not name a type
prog.cpp:31: error: ‘uint32’ does not name a type
prog.cpp:32: error: ‘uint32’ does not name a type
prog.cpp:33: error: ‘uint32’ does not name a type
prog.cpp:34: error: ‘uint32’ does not name a type
prog.cpp:36: error: ‘uint32’ does not name a type
prog.cpp:37: error: ‘uint32’ does not name a type
prog.cpp:38: error: ‘uint32’ does not name a type
prog.cpp:40: error: ‘uint32’ does not name a type
prog.cpp:41: error: ‘uint32’ does not name a type
prog.cpp:42: error: ‘uint32’ does not name a type
prog.cpp:46: error: ‘uint32’ does not name a type
prog.cpp:49: error: ‘uint32’ does not name a type
prog.cpp:52: error: ‘uint32’ does not name a type
stdout
Standard output is empty