FileStream_POSIX.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // FileStream_POSIX.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/FileStream_POSIX.h#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Streams
  8. // Module: FileStream
  9. //
  10. // Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes.
  11. //
  12. // Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
  13. // and Contributors.
  14. //
  15. // SPDX-License-Identifier: BSL-1.0
  16. //
  17. #ifndef Foundation_FileStream_POSIX_INCLUDED
  18. #define Foundation_FileStream_POSIX_INCLUDED
  19. #include "Poco/Foundation.h"
  20. #include "Poco/BufferedBidirectionalStreamBuf.h"
  21. #include <istream>
  22. #include <ostream>
  23. namespace Poco {
  24. class Foundation_API FileStreamBuf: public BufferedBidirectionalStreamBuf
  25. /// This stream buffer handles Fileio
  26. {
  27. public:
  28. FileStreamBuf();
  29. /// Creates a FileStreamBuf.
  30. ~FileStreamBuf();
  31. /// Destroys the FileStream.
  32. void open(const std::string& path, std::ios::openmode mode);
  33. /// Opens the given file in the given mode.
  34. bool close();
  35. /// Closes the File stream buffer. Returns true if successful,
  36. /// false otherwise.
  37. std::streampos seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode = std::ios::in | std::ios::out);
  38. /// Change position by offset, according to way and mode.
  39. std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out);
  40. /// Change to specified position, according to mode.
  41. protected:
  42. enum
  43. {
  44. BUFFER_SIZE = 4096
  45. };
  46. int readFromDevice(char* buffer, std::streamsize length);
  47. int writeToDevice(const char* buffer, std::streamsize length);
  48. private:
  49. std::string _path;
  50. int _fd;
  51. std::streamoff _pos;
  52. };
  53. } // namespace Poco
  54. #endif // Foundation_FileStream_WIN32_INCLUDED