Marine Library
1.0
C++ library for Linux Networking Development
|
Regular file operations. More...
#include <file.hh>
Public Member Functions | |||||||||||||
CFile () | |||||||||||||
Default constructor. | |||||||||||||
int | fdType () const | ||||||||||||
Get type id of this object. More... | |||||||||||||
const char * | fdTypeName () const | ||||||||||||
Get readable description of this object. More... | |||||||||||||
virtual bool | unlink () | ||||||||||||
Remove file. More... | |||||||||||||
bool | rename (const std::string &newfile) | ||||||||||||
Rename file. More... | |||||||||||||
std::string | toString () const | ||||||||||||
Get readable description of this object. More... | |||||||||||||
Open or create a file | |||||||||||||
| |||||||||||||
CFile (const char *pathname, int flags=kFlagsDefault, mode_t mode=kModeDefault) | |||||||||||||
CFile (const std::string &pathname, int flags=kFlagsDefault, mode_t mode=kModeDefault) | |||||||||||||
virtual bool | open (const char *pathname, int flags=kFlagsDefault, mode_t mode=kModeDefault) | ||||||||||||
virtual bool | open (const std::string &pathname, int flags=kFlagsDefault, mode_t mode=kModeDefault) | ||||||||||||
Duplicate file descriptor | |||||||||||||
These functions do NOT copy file content, it only duplicates fd using
| |||||||||||||
CFile (const CFile &other) | |||||||||||||
CFile & | operator= (const CFile &other) | ||||||||||||
Read from file | |||||||||||||
These functions read at most
| |||||||||||||
ssize_t | read (char *buf, size_t size) | ||||||||||||
bool | read (std::vector< char > &buf, size_t size, bool append) | ||||||||||||
bool | read (std::string &buf, size_t size, bool append) | ||||||||||||
Write to file | |||||||||||||
| |||||||||||||
ssize_t | write (const char *buf, size_t size) | ||||||||||||
ssize_t | write (const std::vector< char > &buf) | ||||||||||||
ssize_t | write (const std::string &buf) | ||||||||||||
Set cursor | |||||||||||||
See
| |||||||||||||
bool | seek (off_t offset, int whence) | ||||||||||||
bool | seek64 (off64_t offset, int whence) | ||||||||||||
Get cursor | |||||||||||||
| |||||||||||||
off_t | tell () const | ||||||||||||
off64_t | tell64 () const | ||||||||||||
![]() | |||||||||||||
IFileDesc () | |||||||||||||
Construct a default object. | |||||||||||||
virtual | ~IFileDesc () | ||||||||||||
Destroy this object. More... | |||||||||||||
bool | valid () const | ||||||||||||
Test if this object is a valid file descriptor. More... | |||||||||||||
int | fd () const | ||||||||||||
Get fd (file descriptor). More... | |||||||||||||
std::string | filename () const | ||||||||||||
Get file name opened by this object. More... | |||||||||||||
off_t | length () const | ||||||||||||
Get byte size of file opened by this object. More... | |||||||||||||
bool | deleted () const | ||||||||||||
Test if file is deleted. More... | |||||||||||||
bool | block (bool on) | ||||||||||||
Set block/non-block for operations. More... | |||||||||||||
void | close () | ||||||||||||
Close this fd. | |||||||||||||
Static Public Member Functions | |
static bool | Unlink (const std::string &pathname) |
Remove a file. More... | |
static bool | Rename (const std::string &oldfile, const std::string &newfile) |
Rename a file. More... | |
![]() | |
static std::string | ErrMsg () |
Get latest errno and error message. More... | |
Static Public Attributes | |
static const int | kFdType = 1 |
Type id. | |
![]() | |
static const int | kInvalidFd = -1 |
Regular file operations.
|
inlinevirtual |
Get type id of this object.
Any concrete class derived from IFileDesc shall define a distinct type id named kFdType
, so it's possible to check this id and determine what the object really is.
Currently following kFdType
s are defined:
Type Id | Value |
---|---|
CFile::kFdType | 1 |
CTcpConnSocket::kFdType | 2 |
CListenSocket::kFdType | 3 |
CUdpSocket::kFdType | 4 |
CPosixShmFile::kFdType | 5 |
CEpoll::kFdType | 6 |
Implements IFileDesc.
Reimplemented in CPosixShmFile.
|
inlinevirtual |
Get readable description of this object.
"CFile"
Implements IFileDesc.
Reimplemented in CPosixShmFile.
|
inline |
-1
: Failed 0
: The end of file is reached
|
inline |
true
if succeeded; false
otherwise
|
inline |
true
if succeeded; false
otherwise
|
inlinestatic |
Rename a file.
oldfile | Old pathname |
newfile | New pathname |
true
if succeeded; false
otherwise
|
inline |
Rename file.
newfile | New pathname for the file |
true
if succeeded; false
otherwise
|
inlinevirtual |
Get readable description of this object.
Reimplemented from IFileDesc.
Reimplemented in CPosixShmFile.
|
inlinestatic |
Remove a file.
pathname | File pathname |
true
if succeeded; false
otherwise
|
inlinevirtual |
Remove file.
true
if succeeded; false
otherwise Reimplemented in CPosixShmFile.