ders::fd Class Reference

Provides low level file I/O operations that don't depend on underlining implementation. More...

#include <file.hpp>

List of all members.

Static Public Member Functions

static int open (const char *path, file::mode md, int fls, error &err)
static bool close (int fd, error &err)
static int read (int fd, void *buf, int n, error &err)
static int write (int fd, const void *buf, int n, error &err)
static int seek (int fd, int off, file::whence wh, error &err)

Static Public Attributes

static const int in = 0
static const int out = 1
static const int err = 2


Detailed Description

Provides low level file I/O operations that don't depend on underlining implementation.

Definition at line 160 of file file.hpp.


Member Function Documentation

int ders::fd::open ( const char *  path,
file::mode  md,
int  fls,
error err 
) [static]

Definition at line 35 of file posix/fdimpl.cpp.

00036 {
00037  int m=0;
00038  switch (md) {
00039         case file::rdo:  m=O_RDONLY; break;
00040         case file::wro:  m=O_WRONLY; break;
00041         case file::rdwr: m=O_RDWR;   break;
00042         default:         assert(false);
00043  }
00044 
00045  if (fls&file::app)  m|=O_APPEND;
00046  if (fls&file::crt)  m|=O_CREAT;
00047  if (fls&file::excl) m|=O_EXCL;
00048  if (fls&file::trnc) m|=O_TRUNC;
00049 
00050  return setErr(::open(path, m, S_IREAD|S_IWRITE), err);
00051 }

bool ders::fd::close ( int  fd,
error err 
) [static]

Definition at line 53 of file posix/fdimpl.cpp.

00054 {
00055  return setErr(::close(fd), err)==0;
00056 }

int ders::fd::read ( int  fd,
void *  buf,
int  n,
error err 
) [static]

Definition at line 58 of file posix/fdimpl.cpp.

00059 {
00060  assert(n>0);
00061  int rc=::read(fd, buf, n);
00062  assert(rc<=n);
00063 
00064  return setErr(rc, err);
00065 }

int ders::fd::write ( int  fd,
const void *  buf,
int  n,
error err 
) [static]

Definition at line 67 of file posix/fdimpl.cpp.

00068 {
00069  assert(n>0);
00070  int rc=::write(fd, buf, n);
00071  assert(rc<=n);
00072 
00073  return setErr(rc, err);
00074 }

int ders::fd::seek ( int  fd,
int  off,
file::whence  wh,
error err 
) [static]

Definition at line 76 of file posix/fdimpl.cpp.

00077 {
00078  int w=0;
00079  switch (wh) {
00080         case file::set: w=SEEK_SET; break;
00081         case file::cur: w=SEEK_CUR; break;
00082         case file::end: w=SEEK_END; break;
00083         default:        assert(false);
00084  }
00085 
00086  return setErr(::lseek(fd, off, w), err);
00087 }


Member Data Documentation

const int ders::fd::in = 0 [static]

Definition at line 164 of file file.hpp.

const int ders::fd::out = 1 [static]

Definition at line 165 of file file.hpp.

const int ders::fd::err = 2 [static]

Definition at line 166 of file file.hpp.


The documentation for this class was generated from the following files:

Generated on Tue Dec 8 11:35:33 2009 for derslib by  doxygen 1.5.5