CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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=EDM_IOFD_INVALID)
 
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)
 
virtual ~Storage (void)
 

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 61 of file File.h.

61 { 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:72
#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:72
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:72
virtual void abort(void)
Definition: File.cc:292
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:72
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 292 of file File.cc.

References EDM_IOFD_INVALID.

Referenced by RemoteFile::abort().

293 {
294  IOFD fd = this->fd ();
295  if (fd != EDM_IOFD_INVALID)
296  {
297  sysclose (fd);
299  this->fd (EDM_IOFD_INVALID);
300  }
301 }
static bool sysclose(IOFD fd, int *error=0)
Definition: UnixFile.cc:154
unsigned m_flags
Definition: File.h:72
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:72
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, error, and throwStorageError().

Referenced by RemoteFile::close(), LocalCacheFile::close(), python.Vispa.Gui.BoxContentDialog.BoxContentDialog::keyPressEvent(), and python.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("File::sysclose()", "close()", error);
285 
287  this->fd (EDM_IOFD_INVALID);
288 }
static bool sysclose(IOFD fd, int *error=0)
Definition: UnixFile.cc:154
unsigned m_flags
Definition: File.h:72
void throwStorageError(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::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 reco_application_tbsim_DetSim-Digi_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:72
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 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:72
static IOFD sysduplicate(IOFD fd)
Definition: UnixFile.cc:9
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 139 of file UnixFile.cc.

References EDM_IOFD_INVALID, and throwStorageError().

140 {
141  IOFD fd = this->fd ();
142  assert (fd != EDM_IOFD_INVALID);
143 
144 #if _POSIX_SYNCHRONIZED_IO > 0
145  if (fdatasync (fd) == -1)
146  throwStorageError("File::flush()", "fdatasync()", errno);
147 #elif _POSIX_FSYNC > 0
148  if (fsync (fd) == -1)
149  throwStorageError("File::flush()", "fsync()", errno);
150 #endif
151 }
void throwStorageError(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:72
static void sysopen(const char *name, int flags, int perms, IOFD &newfd, unsigned &newflags)
Definition: UnixFile.cc:19
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 112 of file UnixFile.cc.

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

Referenced by LocalCacheFile::position(), LocalCacheFile::read(), and LocalCacheFile::readv().

113 {
114  IOFD fd = this->fd ();
115  assert (fd != EDM_IOFD_INVALID);
116  assert (whence == CURRENT || whence == SET || whence == END);
117 
119  int mywhence = (whence == SET ? SEEK_SET
120  : whence == CURRENT ? SEEK_CUR
121  : SEEK_END);
122  if ((result = ::lseek (fd, offset, mywhence)) == -1)
123  throwStorageError("File::position()", "lseek()", errno);
124 
125  return result;
126 }
void throwStorageError(const char *context, const char *call, int error)
Definition: Throw.cc:7
tuple result
Definition: query.py:137
unsigned int offset(bool)
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 i, info, n, IOPosBuffer::offset(), evf::evtn::offset(), IOPosBuffer::size(), and findQualityFiles::size.

Referenced by LocalCacheFile::prefetch().

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 }
int i
Definition: DBlmapReader.cc:9
virtual IOOffset size(void) const
Definition: UnixFile.cc:99
unsigned int offset(bool)
IOOffset offset(void) const
Definition: IOPosBuffer.h:50
IOSize size(void) const
Definition: IOPosBuffer.h:60
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().

Referenced by LocalCacheFile::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 63 of file UnixFile.cc.

References asciidump::s, and throwStorageError().

64 {
65  assert (pos >= 0);
66 
67  ssize_t s;
68  do
69  s = ::pread (fd (), into, n, pos);
70  while (s == -1 && errno == EINTR);
71 
72  if (s == -1)
73  throwStorageError("File::read()", "pread()", errno);
74 
75  return s;
76 }
void throwStorageError(const char *context, const char *call, int error)
Definition: Throw.cc:7
string s
Definition: asciidump.py:422
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().

Referenced by LocalCacheFile::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 129 of file UnixFile.cc.

References EDM_IOFD_INVALID, and throwStorageError().

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

130 {
131  IOFD fd = this->fd ();
132  assert (fd != EDM_IOFD_INVALID);
133 
134  if (ftruncate (fd, size) == -1)
135  throwStorageError("File::resize()", "ftruncate()", errno);
136 }
void throwStorageError(const char *context, const char *call, int error)
Definition: Throw.cc:7
virtual IOOffset size(void) const
Definition: UnixFile.cc:99
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:72
IOOffset File::size ( void  ) const
virtual

Get the size of the file.

Reimplemented from Storage.

Definition at line 99 of file UnixFile.cc.

References EDM_IOFD_INVALID, and throwStorageError().

100 {
101  IOFD fd = this->fd ();
102  assert (fd != EDM_IOFD_INVALID);
103 
104  struct stat info;
105  if (fstat (fd, &info) == -1)
106  throwStorageError("File::size()", "fstat()", errno);
107 
108  return info.st_size;
109 }
void throwStorageError(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 154 of file UnixFile.cc.

References runTheMatrix::ret.

155 {
156  int ret = ::close (fd);
157  if (error) *error = errno;
158  return ret != -1;
159 }
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 9 of file UnixFile.cc.

References EDM_IOFD_INVALID, and throwStorageError().

10 {
11  IOFD copyfd;
12  if ((copyfd = ::dup (fd)) == EDM_IOFD_INVALID)
13  throwStorageError ("File::sysduplicate()", "dup()", errno);
14 
15  return copyfd;
16 }
void throwStorageError(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 19 of file UnixFile.cc.

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

21 {
22  // Translate our flags to system flags.
23  int openflags = 0;
24 
25  if ((flags & OpenRead) && (flags & OpenWrite))
26  openflags |= O_RDWR;
27  else if (flags & OpenRead)
28  openflags |= O_RDONLY;
29  else if (flags & OpenWrite)
30  openflags |= O_WRONLY;
31 
32  if (flags & OpenNonBlock)
33  openflags |= O_NONBLOCK;
34 
35  if (flags & OpenAppend)
36  openflags |= O_APPEND;
37 
38 #ifdef O_SYNC
39  if (flags & OpenUnbuffered)
40  openflags |= O_SYNC;
41 #else
42  if (flags & OpenUnbuffered)
43  newflags |= OpenUnbuffered;
44 #endif
45 
46  if (flags & OpenCreate)
47  openflags |= O_CREAT;
48 
49  if (flags & OpenExclusive)
50  openflags |= O_EXCL;
51 
52  if (flags & OpenTruncate)
53  openflags |= O_TRUNC;
54 
55  if (flags & OpenNotCTTY)
56  openflags |= O_NOCTTY;
57 
58  if ((newfd = ::open (name, openflags, perms)) == -1)
59  throwStorageError ("File::sysopen()", "open()", errno);
60 }
void throwStorageError(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, asciidump::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 
249 
250  if (m_flags & OpenUnbuffered)
251  // FIXME: Exception handling?
252  flush ();
253 
254  return s;
255 }
unsigned m_flags
Definition: File.h:72
virtual IOSize write(const void *from, IOSize n)
virtual IOOffset position(void) const
Definition: Storage.cc:95
virtual void flush(void)
Definition: UnixFile.cc:139
static std::string from(" from ")
size_t IOSize
Definition: IOTypes.h:14
string s
Definition: asciidump.py:422
IOSize File::write ( const void *  from,
IOSize  n,
IOOffset  pos 
)
virtual

Reimplemented from Storage.

Definition at line 79 of file UnixFile.cc.

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

80 {
81  assert (pos >= 0);
82 
83  ssize_t s;
84  do
85  s = ::pwrite (fd (), from, n, pos);
86  while (s == -1 && errno == EINTR);
87 
88  if (s == -1)
89  throwStorageError("File::write()", "pwrite()", errno);
90 
91  if (m_flags & OpenUnbuffered)
92  // FIXME: Exception handling?
93  flush ();
94 
95  return s;
96 }
unsigned m_flags
Definition: File.h:72
void throwStorageError(const char *context, const char *call, int error)
Definition: Throw.cc:7
virtual void flush(void)
Definition: UnixFile.cc:139
static std::string from(" from ")
string s
Definition: asciidump.py:422
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, asciidump::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:72
virtual IOSize writev(const IOBuffer *from, IOSize buffers)
virtual IOOffset position(void) const
Definition: Storage.cc:95
virtual void flush(void)
Definition: UnixFile.cc:139
size_t IOSize
Definition: IOTypes.h:14
string s
Definition: asciidump.py:422

Member Data Documentation

unsigned File::m_flags
private

Definition at line 72 of file File.h.

Referenced by duplicate().