libUTL++
FileStream.h
1 #pragma once
2 
4 
5 #include <libutl/FDstream.h>
6 #include <libutl/Pathname.h>
7 
9 
10 UTL_NS_BEGIN;
11 
13 
19 {
20  fs_create = 4,
21  fs_append = 8,
22  fs_trunc = 16,
23  fs_clobber = 32
24 };
25 
27 
35 
37 class FileStream : public FDstream
38 {
41 
42 public:
48  FileStream(int fd, uint_t mode = io_rdwr);
49 
56  FileStream(const Pathname& path, uint_t mode = io_rdwr, uint_t createMode = uint_t_max);
57 
59  ssize_t length() const;
60 
66  void open(int fd, uint_t mode = io_rdwr);
67 
74  void open(const Pathname& path, uint_t mode = io_rdwr, uint_t createMode = uint_t_max);
75 
77  void
79  {
80  seek(0);
81  }
82 
88  ssize_t
89  seek(ssize_t offset)
90  {
91  return seekStart(offset);
92  }
93 
99  ssize_t seekCur(ssize_t offset);
100 
106  ssize_t seekStart(ssize_t offset = 0);
107 
113  ssize_t seekEnd(ssize_t offset = 0);
114 
116  ssize_t tell() const;
117 
123  void truncate(ssize_t length = ssize_t_max);
124 };
125 
127 
128 UTL_NS_END;
#define UTL_CLASS_DEFID
Default init() and deInit() (which are merely place-holders).
Definition: macros.h:532
Filesystem pathname.
Definition: Pathname.h:32
FileStream::open() : open in append mode.
Definition: FileStream.h:21
FileStream::open() : create a new file.
Definition: FileStream.h:20
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
same as io_wr | fs_create | fs_trunc
Definition: FileStream.h:23
read/write
Definition: util.h:60
Disk file stream.
Definition: FileStream.h:37
ssize_t seek(ssize_t offset)
Seek to the given file offset.
Definition: FileStream.h:89
void rewind()
Seek to the start of the file.
Definition: FileStream.h:78
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
const uint_t uint_t_max
Maximum uint_t value.
const ssize_t ssize_t_max
Maximum ssize_t value.
FileStream::open() : truncate existing file.
Definition: FileStream.h:22
Stream with file descriptor.
Definition: FDstream.h:35
fs_flags_t
FileStream flags.
Definition: FileStream.h:18