CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes
File Class Reference

#include <File.h>

Inheritance diagram for File:
IOChannel Storage IOInput IOOutput IOInput IOOutput RemoteFile

Public Member Functions

virtual void abort (void)
 
virtual void attach (IOFD fd)
 
virtual void close (void)
 
virtual void create (const char *name, bool exclusive=false, int perms=0666)
 
virtual void create (const std::string &name, bool exclusive=false, int perms=0666)
 
 File (void)
 
 File (IOFD fd, bool autoclose=true)
 
 File (const char *name, int flags=IOFlags::OpenRead, int perms=0666)
 
 File (const std::string &name, int flags=IOFlags::OpenRead, int perms=0666)
 
virtual void flush (void)
 
virtual void open (const char *name, int flags=IOFlags::OpenRead, int perms=0666)
 
virtual void open (const std::string &name, int flags=IOFlags::OpenRead, int perms=0666)
 
virtual IOOffset position (IOOffset offset, Relative whence=SET)
 
virtual bool prefetch (const IOPosBuffer *what, IOSize n)
 
virtual IOSize read (void *into, IOSize n)
 
virtual IOSize read (void *into, IOSize n, IOOffset pos)
 
virtual IOSize readv (IOBuffer *into, IOSize length)
 
virtual void resize (IOOffset size)
 
virtual void setAutoClose (bool closeit)
 
virtual IOOffset size (void) const
 
virtual IOSize write (const void *from, IOSize n)
 
virtual IOSize write (const void *from, IOSize n, IOOffset pos)
 
virtual IOSize writev (const IOBuffer *from, IOSize length)
 
 ~File (void)
 
- Public Member Functions inherited from IOChannel
virtual IOFD fd (void) const
 
virtual void fd (IOFD value)
 
 IOChannel (IOFD fd=-1)
 
virtual bool isBlocking (void) const
 
virtual void setBlocking (bool value)
 
virtual ~IOChannel (void)
 
- Public Member Functions inherited from IOInput
int read (void)
 
IOSize read (IOBuffer into)
 
IOSize xread (IOBuffer into)
 
IOSize xread (void *into, IOSize n)
 
IOSize xreadv (IOBuffer *into, IOSize buffers)
 
virtual ~IOInput (void)
 Destruct the stream. A no-op. More...
 
- Public Member Functions inherited from IOOutput
IOSize write (unsigned char byte)
 
IOSize write (IOBuffer from)
 
IOSize xwrite (const void *from, IOSize n)
 
IOSize xwrite (IOBuffer from)
 
IOSize xwritev (const IOBuffer *from, IOSize buffers)
 
virtual ~IOOutput (void)
 Destruct the stream. A no-op. More...
 
- Public Member Functions inherited from Storage
virtual bool eof (void) const
 
virtual IOOffset position (void) const
 
IOSize read (IOBuffer into, IOOffset pos)
 
virtual IOSize readv (IOPosBuffer *into, IOSize buffers)
 
virtual void rewind (void)
 
 Storage (void)
 
IOSize write (IOBuffer from, IOOffset pos)
 
virtual IOSize writev (const IOPosBuffer *from, IOSize buffers)
 
 ~Storage (void) override
 

Private Types

enum  { InternalAutoClose = 4096 }
 

Private Member Functions

Fileduplicate (bool copy) const
 
Fileduplicate (File *child) const
 
 File (IOFD fd, unsigned flags)
 

Static Private Member Functions

static bool sysclose (IOFD fd, int *error=0)
 
static IOFD sysduplicate (IOFD fd)
 
static void sysopen (const char *name, int flags, int perms, IOFD &newfd, unsigned &newflags)
 

Private Attributes

unsigned m_flags
 

Additional Inherited Members

- Public Types inherited from Storage
enum  Relative { SET, CURRENT, END }
 
- Protected Member Functions inherited from IOChannel
bool sysclose (IOFD fd, int *error=0)
 

Detailed Description

Basic file-related functions. Nicked from SEAL.

Definition at line 11 of file File.h.

Member Enumeration Documentation

anonymous enum
private
Enumerator
InternalAutoClose 

Definition at line 63 of file File.h.

63 { InternalAutoClose = 4096 }; //< Close on delete

Constructor & Destructor Documentation

File::File ( void  )

Create a new file object without a file attached to it.

Definition at line 57 of file File.cc.

References EDM_IOFD_INVALID.

58 {
60  m_flags = 0;
61 }
unsigned m_flags
Definition: File.h:74
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
File::File ( IOFD  fd,
bool  autoclose = true 
)

Create a new file object from a file descriptor. The descriptor will be closed automatically when the file object is destructed if autoclose is true (the default).

Definition at line 66 of file File.cc.

67 {
68  this->fd (fd);
69  m_flags = autoclose ? InternalAutoClose : 0;
70 }
unsigned m_flags
Definition: File.h:74
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
File::File ( const char *  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)

Create a new file object by calling open() with the given arguments.

Definition at line 80 of file File.cc.

81 { open (name, flags, perms); }
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: File.cc:177
File::File ( const std::string &  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)

Create a new file object by calling open() with the given arguments.

Definition at line 84 of file File.cc.

References flags.

85 { open (name.c_str (), flags, perms); }
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: File.cc:177
File::~File ( void  )

Release the resources held by the file object. If the object holds a valid file descriptor given to it through the constructor or obtained by calling open(), the descriptor will be closed.

Definition at line 90 of file File.cc.

91 {
93  abort ();
94 }
unsigned m_flags
Definition: File.h:74
virtual void abort(void)
Definition: File.cc:293
File::File ( IOFD  fd,
unsigned  flags 
)
private

Internal function for copying file objects to retain the state flags.

Definition at line 73 of file File.cc.

References flags.

74 {
75  this->fd (fd);
76  m_flags = flags;
77 }
unsigned m_flags
Definition: File.h:74
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
virtual IOFD fd(void) const
Definition: IOChannel.cc:73

Member Function Documentation

void File::abort ( void  )
virtual

Close the file and ignore all errors.

Reimplemented in RemoteFile.

Definition at line 293 of file File.cc.

References EDM_IOFD_INVALID.

Referenced by RemoteFile::abort().

294 {
295  IOFD fd = this->fd ();
296  if (fd != EDM_IOFD_INVALID)
297  {
298  sysclose (fd);
300  this->fd (EDM_IOFD_INVALID);
301  }
302 }
static bool sysclose(IOFD fd, int *error=0)
Definition: UnixFile.cc:155
unsigned m_flags
Definition: File.h:74
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
void File::attach ( IOFD  fd)
virtual

Definition at line 201 of file File.cc.

202 {
203  this->fd (fd);
204  m_flags = 0;
205 }
unsigned m_flags
Definition: File.h:74
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
void File::close ( void  )
virtual

Close the file.

Reimplemented from IOChannel.

Reimplemented in RemoteFile.

Definition at line 277 of file File.cc.

References EDM_IOFD_INVALID, relativeConstraints::error, and throwStorageError().

Referenced by RemoteFile::close(), lumiQTWidget.ApplicationWindow::fileQuit(), esMonitoring.AsyncLineReaderMixin::handle_close(), esMonitoring.FDJsonServer::handle_close(), Vispa.Gui.BoxContentDialog.BoxContentDialog::keyPressEvent(), and Vispa.Gui.FindDialog.FindDialog::keyPressEvent().

278 {
279  IOFD fd = this->fd ();
280  assert (fd != EDM_IOFD_INVALID);
281 
282  int error;
283  if (! sysclose (fd, &error))
284  throwStorageError("FileCloseError", "Calling File::close()",
285  "sysclose", error);
286 
288  this->fd (EDM_IOFD_INVALID);
289 }
static bool sysclose(IOFD fd, int *error=0)
Definition: UnixFile.cc:155
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:7
unsigned m_flags
Definition: File.h:74
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
void File::create ( const char *  name,
bool  exclusive = false,
int  perms = 0666 
)
virtual

Create and open the file name in write mode. If exclusive, the creation fails if the file already exists, otherwise if the file exists, it will be truncated. The new file will have the permissions perms.

Definition at line 142 of file File.cc.

References IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenTruncate, and IOFlags::OpenWrite.

143 {
144  open (name,
146  | (exclusive ? OpenExclusive : 0)),
147  perms);
148 }
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: File.cc:177
void File::create ( const std::string &  name,
bool  exclusive = false,
int  perms = 0666 
)
virtual

Create and open the file name in write mode. If exclusive, the creation fails if the file already exists, otherwise if the file exists, it will be truncated. The new file will have the permissions perms.

Definition at line 155 of file File.cc.

References IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenTruncate, and IOFlags::OpenWrite.

156 {
157  open (name.c_str (),
159  | (exclusive ? OpenExclusive : 0)),
160  perms);
161 }
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: File.cc:177
File * File::duplicate ( bool  copy) const
private

Duplicate the file object. If copy, also duplicates the underlying file descriptor, otherwise the two will point to the same descriptor. If the file descriptor is not copied, the copy will not close its file descriptor on destruction, the original object (this) will.

Definition at line 117 of file File.cc.

References trackingPlots::dup, and ecalTB2006H4_GenSimDigiReco_cfg::File.

118 {
119  File *dup = new File (fd (), copy ? m_flags : 0);
120  return copy ? this->duplicate (dup) : dup;
121 }
unsigned m_flags
Definition: File.h:74
def copy(args, dbName)
File(void)
Definition: File.cc:57
File * duplicate(bool copy) const
Definition: File.cc:117
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
Definition: File.h:11
File * File::duplicate ( File child) const
private

Internal implementation of duplicate() to actually duplicate the file handle into child.

Definition at line 126 of file File.cc.

References class-composition::child, EDM_IOFD_INVALID, IOChannel::fd(), and m_flags.

127 {
128  IOFD fd = this->fd ();
129  assert (fd != EDM_IOFD_INVALID);
130  assert (child);
131  child->fd (sysduplicate (fd));
132  child->m_flags = m_flags;
133  return child;
134 }
unsigned m_flags
Definition: File.h:74
static IOFD sysduplicate(IOFD fd)
Definition: UnixFile.cc:10
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
void File::flush ( void  )
virtual

Flush the system's file system buffers for this file.

Reimplemented from Storage.

Definition at line 140 of file UnixFile.cc.

References EDM_IOFD_INVALID, and throwStorageError().

141 {
142  IOFD fd = this->fd ();
143  assert (fd != EDM_IOFD_INVALID);
144 
145 #if _POSIX_SYNCHRONIZED_IO > 0
146  if (fdatasync (fd) == -1)
147  throwStorageError("FileFlushError", "Calling File::flush()", "fdatasync()", errno);
148 #elif _POSIX_FSYNC > 0
149  if (fsync (fd) == -1)
150  throwStorageError("FileFlushError", "Calling File::flush()", "fsync()", errno);
151 #endif
152 }
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:7
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
void File::open ( const char *  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)
virtual

Open or possibly create the file name with options specified in flags. If the file is to be created, it will be given the permissions perms. If this object already has a file open, it is closed first.

Definition at line 177 of file File.cc.

References EDM_IOFD_INVALID, IOFlags::OpenRead, and IOFlags::OpenWrite.

178 {
179  // is zero and always implied. OTOH, existence check should be
180  // done with Filename::exists() -- see comments there about what
181  // can happen on a WIN32 remote share even if the file doesn't
182  // exist. For now make sure that read or write was asked for.
183 
184  assert (name && *name);
185  assert (flags & (OpenRead | OpenWrite));
186 
187  // If I am already open, close the old file first.
188  if (fd () != EDM_IOFD_INVALID && (m_flags & InternalAutoClose))
189  close ();
190 
191  IOFD newfd = EDM_IOFD_INVALID;
192  unsigned newflags = InternalAutoClose;
193 
194  sysopen (name, flags, perms, newfd, newflags);
195 
196  fd (newfd);
197  m_flags = newflags;
198 }
unsigned m_flags
Definition: File.h:74
static void sysopen(const char *name, int flags, int perms, IOFD &newfd, unsigned &newflags)
Definition: UnixFile.cc:20
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
virtual void close(void)
Definition: File.cc:277
void File::open ( const std::string &  name,
int  flags = IOFlags::OpenRead,
int  perms = 0666 
)
virtual

Open or possibly create the file name with options specified in flags. If the file is to be created, it will be given the permissions perms. If this object already has a file open, it is closed first. Redirected to the overloaded method taking a "const char *" argument.

Definition at line 169 of file File.cc.

References flags.

170 { open (name.c_str (), flags, perms); }
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: File.cc:177
IOOffset File::position ( IOOffset  offset,
Relative  whence = SET 
)
virtual

Return the current file pointer position.

Implements Storage.

Definition at line 113 of file UnixFile.cc.

References EDM_IOFD_INVALID, mps_fire::result, and throwStorageError().

114 {
115  IOFD fd = this->fd ();
116  assert (fd != EDM_IOFD_INVALID);
117  assert (whence == CURRENT || whence == SET || whence == END);
118 
120  int mywhence = (whence == SET ? SEEK_SET
121  : whence == CURRENT ? SEEK_CUR
122  : SEEK_END);
123  if ((result = ::lseek (fd, offset, mywhence)) == -1)
124  throwStorageError("FilePositionError", "Calling File::position()", "lseek()", errno);
125 
126  return result;
127 }
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:7
int64_t IOOffset
Definition: IOTypes.h:19
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
bool File::prefetch ( const IOPosBuffer what,
IOSize  n 
)
virtual

Prefetch data for the file.

Reimplemented from Storage.

Definition at line 210 of file File.cc.

References mps_fire::i, info(), gen::n, IOPosBuffer::offset(), PFRecoTauDiscriminationByIsolation_cfi::offset, IOPosBuffer::size(), and findQualityFiles::size.

211 {
212  IOFD fd = this->fd();
213  for (IOSize i = 0; i < n; ++i)
214  {
215 #if F_RDADVISE
216  radvisory info;
217  info.ra_offset = what[i].offset();
218  info.ra_count = what[i].size();
219  fcntl(fd, F_RDADVISE, &info);
220 #elif _POSIX_ADVISORY_INFO > 0
221  posix_fadvise(fd, what[i].offset(), what[i].size(), POSIX_FADV_WILLNEED);
222 #else
223 # error advisory read ahead not available on this platform
224 #endif
225  }
226  return true;
227 }
static const TGPicture * info(bool iBackgroundIsBlack)
virtual IOOffset size(void) const
Definition: UnixFile.cc:100
IOOffset offset(void) const
Definition: IOPosBuffer.h:54
IOSize size(void) const
Definition: IOPosBuffer.h:64
int IOFD
Definition: IOTypes.h:22
size_t IOSize
Definition: IOTypes.h:14
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
IOSize File::read ( void *  into,
IOSize  n 
)
virtual

Read from the file.

Reimplemented from IOChannel.

Definition at line 231 of file File.cc.

References IOInput::read().

232 { return IOChannel::read (into, n); }
int read(void)
Definition: IOInput.cc:54
IOSize File::read ( void *  into,
IOSize  n,
IOOffset  pos 
)
virtual

Reimplemented from Storage.

Definition at line 64 of file UnixFile.cc.

References edm::errors::FileReadError, alignCSCRings::s, and throwStorageError().

65 {
66  assert (pos >= 0);
67 
68  ssize_t s;
69  do
70  s = ::pread (fd (), into, n, pos);
71  while (s == -1 && errno == EINTR);
72 
73  if (s == -1)
74  throwStorageError(edm::errors::FileReadError, "Calling File::read()", "pread()", errno);
75 
76  return s;
77 }
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:7
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
IOSize File::readv ( IOBuffer into,
IOSize  length 
)
virtual

Read from the file.

Reimplemented from IOChannel.

Definition at line 236 of file File.cc.

References IOChannel::readv().

237 { return IOChannel::readv (into, length); }
virtual IOSize readv(IOBuffer *into, IOSize buffers)
void File::resize ( IOOffset  size)
virtual

Resize to the file to size. If size is less than the file's current size, the file is truncated. If size is larger than the file's current size, the file is extended with zero bytes. Does not change the current file pointer.

Implements Storage.

Definition at line 130 of file UnixFile.cc.

References EDM_IOFD_INVALID, and throwStorageError().

Referenced by Vispa.Gui.TextDialog.TextDialog::__init__(), Vispa.Plugins.ConfigEditor.ToolDialog.ToolDialog::__init__(), Vispa.Main.MainWindow.MainWindow::_loadIni(), and Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

131 {
132  IOFD fd = this->fd ();
133  assert (fd != EDM_IOFD_INVALID);
134 
135  if (ftruncate (fd, size) == -1)
136  throwStorageError("FileResizeError", "Calling File::resize()", "ftruncate()", errno);
137 }
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:7
virtual IOOffset size(void) const
Definition: UnixFile.cc:100
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
void File::setAutoClose ( bool  autoclose)
virtual

Set the autoclose flag of the file. If autoclose is true, the destructor will automatically try to close the underlying file descriptor. Otherwise the file descriptor will be left open. Set the flag off if the file descriptor is originally owned by someone else.

Definition at line 103 of file File.cc.

104 {
106  if (autoclose)
108 }
unsigned m_flags
Definition: File.h:74
IOOffset File::size ( void  ) const
virtual

Get the size of the file.

Reimplemented from Storage.

Definition at line 100 of file UnixFile.cc.

References EDM_IOFD_INVALID, and throwStorageError().

Referenced by ntupleDataFormat._Collection::__iter__(), and ntupleDataFormat._Collection::__len__().

101 {
102  IOFD fd = this->fd ();
103  assert (fd != EDM_IOFD_INVALID);
104 
105  struct stat info;
106  if (fstat (fd, &info) == -1)
107  throwStorageError("FileSizeError", "Calling File::size()", "fstat()", errno);
108 
109  return info.st_size;
110 }
static const TGPicture * info(bool iBackgroundIsBlack)
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:7
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
bool File::sysclose ( IOFD  fd,
int *  error = 0 
)
staticprivate

Actually close a file handle and return error code.

Definition at line 155 of file UnixFile.cc.

156 {
157  int ret = ::close (fd);
158  if (error) *error = errno;
159  return ret != -1;
160 }
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
virtual void close(void)
Definition: File.cc:277
IOFD File::sysduplicate ( IOFD  fd)
staticprivate

Definition at line 10 of file UnixFile.cc.

References trackingPlots::dup, EDM_IOFD_INVALID, and throwStorageError().

11 {
12  IOFD copyfd;
13  if ((copyfd = ::dup (fd)) == EDM_IOFD_INVALID)
14  throwStorageError ("FileDuplicateError", "Calling File::sysduplicate()", "dup()", errno);
15 
16  return copyfd;
17 }
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:7
int IOFD
Definition: IOTypes.h:22
#define EDM_IOFD_INVALID
Definition: IOTypes.h:8
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
void File::sysopen ( const char *  name,
int  flags,
int  perms,
IOFD newfd,
unsigned &  newflags 
)
staticprivate

Definition at line 20 of file UnixFile.cc.

References edm::errors::FileOpenError, O_NONBLOCK, IOFlags::OpenAppend, IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenNonBlock, IOFlags::OpenNotCTTY, IOFlags::OpenRead, IOFlags::OpenTruncate, IOFlags::OpenUnbuffered, IOFlags::OpenWrite, and throwStorageError().

22 {
23  // Translate our flags to system flags.
24  int openflags = 0;
25 
26  if ((flags & OpenRead) && (flags & OpenWrite))
27  openflags |= O_RDWR;
28  else if (flags & OpenRead)
29  openflags |= O_RDONLY;
30  else if (flags & OpenWrite)
31  openflags |= O_WRONLY;
32 
33  if (flags & OpenNonBlock)
34  openflags |= O_NONBLOCK;
35 
36  if (flags & OpenAppend)
37  openflags |= O_APPEND;
38 
39 #ifdef O_SYNC
40  if (flags & OpenUnbuffered)
41  openflags |= O_SYNC;
42 #else
43  if (flags & OpenUnbuffered)
44  newflags |= OpenUnbuffered;
45 #endif
46 
47  if (flags & OpenCreate)
48  openflags |= O_CREAT;
49 
50  if (flags & OpenExclusive)
51  openflags |= O_EXCL;
52 
53  if (flags & OpenTruncate)
54  openflags |= O_TRUNC;
55 
56  if (flags & OpenNotCTTY)
57  openflags |= O_NOCTTY;
58 
59  if ((newfd = ::open (name, openflags, perms)) == -1)
60  throwStorageError (edm::errors::FileOpenError, "Calling File::sysopen()", "open()", errno);
61 }
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:7
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
virtual void open(const char *name, int flags=IOFlags::OpenRead, int perms=0666)
Definition: File.cc:177
#define O_NONBLOCK
Definition: SysFile.h:21
IOSize File::write ( const void *  from,
IOSize  n 
)
virtual

Write to the file.

Reimplemented from IOChannel.

Definition at line 241 of file File.cc.

References IOFlags::OpenAppend, IOFlags::OpenUnbuffered, position, alignCSCRings::s, and IOChannel::write().

242 {
243  // FIXME: This may create a race condition or cause trouble on
244  // remote files. Should be currently needed only on WIN32.
245  if (m_flags & OpenAppend)
246  position (0, END);
247 
248  IOSize s = IOChannel::write (from, n);
249 
250  if (m_flags & OpenUnbuffered)
251  // FIXME: Exception handling?
252  flush ();
253 
254  return s;
255 }
unsigned m_flags
Definition: File.h:74
virtual IOSize write(const void *from, IOSize n)
virtual IOOffset position(void) const
Definition: Storage.cc:95
virtual void flush(void)
Definition: UnixFile.cc:140
size_t IOSize
Definition: IOTypes.h:14
IOSize File::write ( const void *  from,
IOSize  n,
IOOffset  pos 
)
virtual

Reimplemented from Storage.

Definition at line 80 of file UnixFile.cc.

References IOFlags::OpenUnbuffered, alignCSCRings::s, and throwStorageError().

81 {
82  assert (pos >= 0);
83 
84  ssize_t s;
85  do
86  s = ::pwrite (fd (), from, n, pos);
87  while (s == -1 && errno == EINTR);
88 
89  if (s == -1)
90  throwStorageError("FileWriteError", "Calling File::write()", "pwrite()", errno);
91 
92  if (m_flags & OpenUnbuffered)
93  // FIXME: Exception handling?
94  flush ();
95 
96  return s;
97 }
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:7
unsigned m_flags
Definition: File.h:74
virtual void flush(void)
Definition: UnixFile.cc:140
virtual IOFD fd(void) const
Definition: IOChannel.cc:73
IOSize File::writev ( const IOBuffer from,
IOSize  length 
)
virtual

Write to the file.

Reimplemented from IOChannel.

Definition at line 259 of file File.cc.

References IOFlags::OpenAppend, IOFlags::OpenUnbuffered, position, alignCSCRings::s, and IOChannel::writev().

260 {
261  // FIXME: This may create a race condition or cause trouble on
262  // remote files. Should be currently needed only on WIN32.
263  if (m_flags & OpenAppend)
264  position (0, END);
265 
266  IOSize s = IOChannel::writev (from, length);
267 
268  if (m_flags & OpenUnbuffered)
269  // FIXME: Exception handling?
270  flush ();
271 
272  return s;
273 }
unsigned m_flags
Definition: File.h:74
virtual IOSize writev(const IOBuffer *from, IOSize buffers)
virtual IOOffset position(void) const
Definition: Storage.cc:95
virtual void flush(void)
Definition: UnixFile.cc:140
size_t IOSize
Definition: IOTypes.h:14

Member Data Documentation

unsigned File::m_flags
private

Definition at line 74 of file File.h.

Referenced by duplicate().