#include <QoreFile.h>
Public Member Functions | |
DLLEXPORT | QoreFile (const QoreEncoding *cs=QCS_DEFAULT) |
creates the object and sets the default encoding | |
DLLEXPORT | ~QoreFile () |
closes the file and frees all memory allocated to the object | |
DLLEXPORT int | open (const char *fn, int flags=O_RDONLY, int mode=0777, const QoreEncoding *cs=QCS_DEFAULT) |
opens the file and returns 0 for success, non-zero for error | |
DLLEXPORT int | open2 (ExceptionSink *xsink, const char *fn, int flags=O_RDONLY, int mode=0777, const QoreEncoding *cs=QCS_DEFAULT) |
opens the file and raises a Qore-language exception if an error occurs | |
DLLEXPORT int | close () |
closes the file | |
DLLEXPORT void | setEncoding (const QoreEncoding *cs) |
sets the encoding for the file | |
DLLEXPORT const QoreEncoding * | getEncoding () const |
returns the encoding used for the file | |
DLLEXPORT int | sync () |
flushes the write buffer to disk | |
DLLEXPORT QoreStringNode * | readLine (ExceptionSink *xsink) |
reads string data from the file up to a terminating '\n' character and returns the string read | |
DLLEXPORT int | write (const QoreString *str, ExceptionSink *xsink) |
writes string data to the file, character encoding is converted if necessary, and returns the number of bytes written | |
DLLEXPORT int | write (const BinaryNode *b, ExceptionSink *xsink) |
writes binary data to the file and returns the number of bytes written | |
DLLEXPORT int | write (const void *data, qore_size_t len, ExceptionSink *xsink) |
writes binary data to the file and returns the number of bytes written | |
DLLEXPORT int | writei1 (char i, ExceptionSink *xsink) |
writes 1-byte binary integer data to the file and returns the number of bytes written (normally 1) | |
DLLEXPORT int | writei2 (short i, ExceptionSink *xsink) |
writes 2-byte (16bit) binary integer data in MSB (Most Significant Byte first, big endian) format to the file and returns the number of bytes written (normally 2) | |
DLLEXPORT int | writei4 (int i, ExceptionSink *xsink) |
writes 4-byte (32bit) binary integer data in MSB (Most Significant Byte first, big endian) format to the file and returns the number of bytes written (normally 4) | |
DLLEXPORT int | writei8 (int64 i, ExceptionSink *xsink) |
writes 8-byte (64bit) binary integer data in MSB (Most Significant Byte first, big endian) format to the file and returns the number of bytes written (normally 8) | |
DLLEXPORT int | writei2LSB (short i, ExceptionSink *xsink) |
writes 2-byte (16bit) binary integer data in LSB (Least Significant Byte first, little endian) format to the file and returns the number of bytes written (normally 2) | |
DLLEXPORT int | writei4LSB (int i, ExceptionSink *xsink) |
writes 4-byte (32bit) binary integer data in LSB (Least Significant Byte first, little endian)format to the file and returns the number of bytes written (normally 4) | |
DLLEXPORT int | writei8LSB (int64 i, ExceptionSink *xsink) |
writes 8-byte (64bit) binary integer data in LSB (Least Significant Byte first, little endian) format to the file and returns the number of bytes written (normally 8) | |
DLLEXPORT int | readu1 (unsigned char *val, ExceptionSink *xsink) |
reads a 1-byte unsigned integer from the file and returns the value read as an output parameter | |
DLLEXPORT int | readu2 (unsigned short *val, ExceptionSink *xsink) |
reads a 2-byte unsigned integer from the file in MSB (Most Significant Byte first, big endian) format and returns the value read as an output parameter | |
DLLEXPORT int | readu4 (unsigned int *val, ExceptionSink *xsink) |
reads a 4-byte unsigned integer from the file in MSB (Most Significant Byte first, big endian) format and returns the value read as an output parameter | |
DLLEXPORT int | readu2LSB (unsigned short *val, ExceptionSink *xsink) |
reads a 2-byte unsigned integer from the file in LSB (Least Significant Byte first, big endian) format and returns the value read as an output parameter | |
DLLEXPORT int | readu4LSB (unsigned int *val, ExceptionSink *xsink) |
reads a 4-byte unsigned integer from the file in LSB (Least Significant Byte first, big endian) format and returns the value read as an output parameter | |
DLLEXPORT int | readi1 (char *val, ExceptionSink *xsink) |
reads a 1-byte signed integer from the file and returns the value read as an output parameter | |
DLLEXPORT int | readi2 (short *val, ExceptionSink *xsink) |
reads a 2-byte signed integer from the file in MSB (Most Significant Byte first, big endian) format and returns the value read as an output parameter | |
DLLEXPORT int | readi4 (int *val, ExceptionSink *xsink) |
reads a 4-byte signed integer from the file in MSB (Most Significant Byte first, big endian) format and returns the value read as an output parameter | |
DLLEXPORT int | readi8 (int64 *val, ExceptionSink *xsink) |
reads an 8-byte signed integer from the file in MSB (Most Significant Byte first, big endian) format and returns the value read as an output parameter | |
DLLEXPORT int | readi2LSB (short *val, ExceptionSink *xsink) |
reads a 2-byte signed integer from the file in LSB (Least Significant Byte first, big endian) format and returns the value read as an output parameter | |
DLLEXPORT int | readi4LSB (int *val, ExceptionSink *xsink) |
reads a 4-byte signed integer from the file in LSB (Least Significant Byte first, big endian) format and returns the value read as an output parameter | |
DLLEXPORT int | readi8LSB (int64 *val, ExceptionSink *xsink) |
reads an 8-byte signed integer from the file in LSB (Least Significant Byte first, big endian) format and returns the value read as an output parameter | |
DLLEXPORT QoreStringNode * | read (qore_offset_t size, ExceptionSink *xsink) |
reads string data from the file and returns the string read (caller owns the reference count returned) | |
DLLEXPORT BinaryNode * | readBinary (qore_offset_t size, ExceptionSink *xsink) |
reads binary data from the file and returns the data read (caller owns the reference count returned) | |
DLLEXPORT QoreStringNode * | read (qore_offset_t size, int timeout_ms, ExceptionSink *xsink) |
reads string data from the file and returns the string read (caller owns the reference count returned) | |
DLLEXPORT BinaryNode * | readBinary (qore_offset_t size, int timeout_ms, ExceptionSink *xsink) |
reads binary data from the file and returns the data read (caller owns the reference count returned) | |
DLLEXPORT qore_size_t | setPos (qore_size_t pos) |
sets the absolute file position to "pos" | |
DLLEXPORT qore_size_t | getPos () |
returns the absolute byte position in the file | |
DLLEXPORT QoreStringNode * | getchar () |
reads a single character from the file and returns it as a new string, caller owns the reference count returned | |
DLLEXPORT QoreStringNode * | getFileName () const |
returns the filename of the file being read | |
DLLEXPORT int | chown (uid_t owner, gid_t group, ExceptionSink *xsink) |
changes ownership of the file (if possible) | |
DLLEXPORT int | lockBlocking (struct flock &fl, ExceptionSink *xsink) |
perform a file lock operation | |
DLLEXPORT int | lock (const struct flock &fl, ExceptionSink *xsink) |
perform a file lock operation, does not block | |
DLLEXPORT int | getLockInfo (struct flock &fl, ExceptionSink *xsink) |
get lock info operation, does not block | |
DLLEXPORT bool | isDataAvailable (int timeout_ms, ExceptionSink *xsink) const |
returns true if data is available for the file descriptor | |
DLLEXPORT int | getFD () const |
get file descriptor | |
DLLLOCAL int | setTerminalAttributes (int action, QoreTermIOS *ios, ExceptionSink *xsink) const |
sets terminal attributes | |
DLLLOCAL int | getTerminalAttributes (QoreTermIOS *ios, ExceptionSink *xsink) const |
gets terminal attributes | |
DLLLOCAL void | setEventQueue (Queue *cbq, ExceptionSink *xsink) |
sets the event queue (not part of the library's pubilc API), must be already referenced before call | |
DLLLOCAL void | cleanup (ExceptionSink *xsink) |
internal API, must be called before deleting the object if an event queue is set | |
Protected Member Functions | |
DLLLOCAL | QoreFile (const QoreFile &) |
this function is not implemented; it is here as a private function in order to prohibit it from being used | |
DLLLOCAL QoreFile & | operator= (const QoreFile &) |
this function is not implemented; it is here as a private function in order to prohibit it from being used |
Each file has a default character encoding associated with it. String data read from the file will be tagged with this encoding. String data written to the file will be converted to this encoding if necessary before written.
DLLEXPORT int QoreFile::close | ( | ) |
closes the file
DLLEXPORT QoreStringNode* QoreFile::getchar | ( | ) |
reads a single character from the file and returns it as a new string, caller owns the reference count returned
can returns 0 if an error occurs FIXME: reads a single byte, not a character
DLLEXPORT qore_size_t QoreFile::getPos | ( | ) |
returns the absolute byte position in the file
DLLEXPORT bool QoreFile::isDataAvailable | ( | int | timeout_ms, | |
ExceptionSink * | xsink | |||
) | const |
returns true if data is available for the file descriptor
timeout_ms | the maximum time to read a single block from the file; -1 = never timeout, 0 timeout immediately if no data is available | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::open | ( | const char * | fn, | |
int | flags = O_RDONLY , |
|||
int | mode = 0777 , |
|||
const QoreEncoding * | cs = QCS_DEFAULT | |||
) |
opens the file and returns 0 for success, non-zero for error
fn | the file name to open | |
flags | the flags to use when opening the file | |
mode | the mode mask to use when opening the file | |
cs | the encoding to use for the file |
DLLEXPORT int QoreFile::open2 | ( | ExceptionSink * | xsink, | |
const char * | fn, | |||
int | flags = O_RDONLY , |
|||
int | mode = 0777 , |
|||
const QoreEncoding * | cs = QCS_DEFAULT | |||
) |
opens the file and raises a Qore-language exception if an error occurs
xsink | if an error occurs when opening the file, the Qore-language exception info will be added here | |
fn | the file name to open | |
flags | the flags to use when opening the file | |
mode | the mode mask to use when opening the file | |
cs | the encoding to use for the file |
DLLEXPORT QoreStringNode* QoreFile::read | ( | qore_offset_t | size, | |
int | timeout_ms, | |||
ExceptionSink * | xsink | |||
) |
reads string data from the file and returns the string read (caller owns the reference count returned)
A Qore-language exception can be thrown if the file is not opened
size | the number of bytes to read from the file, use -1 to read all data from the file | |
timeout_ms | the maximum time to read a single block from the file; -1 = never timeout, 0 timeout immediately if no data is available | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT QoreStringNode* QoreFile::read | ( | qore_offset_t | size, | |
ExceptionSink * | xsink | |||
) |
reads string data from the file and returns the string read (caller owns the reference count returned)
A Qore-language exception can be thrown if the file is not opened
size | the number of bytes to read from the file, use -1 to read all data from the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT BinaryNode* QoreFile::readBinary | ( | qore_offset_t | size, | |
int | timeout_ms, | |||
ExceptionSink * | xsink | |||
) |
reads binary data from the file and returns the data read (caller owns the reference count returned)
A Qore-language exception can be thrown if the file is not opened
size | the number of bytes to read from the file, use -1 to read all data from the file | |
timeout_ms | the maximum time to read a single block from the file; -1 = never timeout, 0 timeout immediately if no data is available | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT BinaryNode* QoreFile::readBinary | ( | qore_offset_t | size, | |
ExceptionSink * | xsink | |||
) |
reads binary data from the file and returns the data read (caller owns the reference count returned)
A Qore-language exception can be thrown if the file is not opened
size | the number of bytes to read from the file, use -1 to read all data from the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::readi1 | ( | char * | val, | |
ExceptionSink * | xsink | |||
) |
reads a 1-byte signed integer from the file and returns the value read as an output parameter
A Qore-language exception can be thrown if the file is not opened
val | output parameter: the integer value read from the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::readi2 | ( | short * | val, | |
ExceptionSink * | xsink | |||
) |
reads a 2-byte signed integer from the file in MSB (Most Significant Byte first, big endian) format and returns the value read as an output parameter
A Qore-language exception can be thrown if the file is not opened
val | output parameter: the integer value read from the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::readi2LSB | ( | short * | val, | |
ExceptionSink * | xsink | |||
) |
reads a 2-byte signed integer from the file in LSB (Least Significant Byte first, big endian) format and returns the value read as an output parameter
A Qore-language exception can be thrown if the file is not opened
val | output parameter: the integer value read from the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::readi4 | ( | int * | val, | |
ExceptionSink * | xsink | |||
) |
reads a 4-byte signed integer from the file in MSB (Most Significant Byte first, big endian) format and returns the value read as an output parameter
A Qore-language exception can be thrown if the file is not opened
val | output parameter: the integer value read from the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::readi4LSB | ( | int * | val, | |
ExceptionSink * | xsink | |||
) |
reads a 4-byte signed integer from the file in LSB (Least Significant Byte first, big endian) format and returns the value read as an output parameter
A Qore-language exception can be thrown if the file is not opened
val | output parameter: the integer value read from the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::readi8 | ( | int64 * | val, | |
ExceptionSink * | xsink | |||
) |
reads an 8-byte signed integer from the file in MSB (Most Significant Byte first, big endian) format and returns the value read as an output parameter
A Qore-language exception can be thrown if the file is not opened
val | output parameter: the integer value read from the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::readi8LSB | ( | int64 * | val, | |
ExceptionSink * | xsink | |||
) |
reads an 8-byte signed integer from the file in LSB (Least Significant Byte first, big endian) format and returns the value read as an output parameter
A Qore-language exception can be thrown if the file is not opened
val | output parameter: the integer value read from the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT QoreStringNode* QoreFile::readLine | ( | ExceptionSink * | xsink | ) |
reads string data from the file up to a terminating '\n' character and returns the string read
if an error occurs (file is not open), a Qore-language exception is raised
xsink | if an error occurs when opening the file, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::readu1 | ( | unsigned char * | val, | |
ExceptionSink * | xsink | |||
) |
reads a 1-byte unsigned integer from the file and returns the value read as an output parameter
A Qore-language exception can be thrown if the file is not opened
val | output parameter: the integer value read from the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::readu2 | ( | unsigned short * | val, | |
ExceptionSink * | xsink | |||
) |
reads a 2-byte unsigned integer from the file in MSB (Most Significant Byte first, big endian) format and returns the value read as an output parameter
A Qore-language exception can be thrown if the file is not opened
val | output parameter: the integer value read from the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::readu2LSB | ( | unsigned short * | val, | |
ExceptionSink * | xsink | |||
) |
reads a 2-byte unsigned integer from the file in LSB (Least Significant Byte first, big endian) format and returns the value read as an output parameter
A Qore-language exception can be thrown if the file is not opened
val | output parameter: the integer value read from the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::readu4 | ( | unsigned int * | val, | |
ExceptionSink * | xsink | |||
) |
reads a 4-byte unsigned integer from the file in MSB (Most Significant Byte first, big endian) format and returns the value read as an output parameter
A Qore-language exception can be thrown if the file is not opened
val | output parameter: the integer value read from the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::readu4LSB | ( | unsigned int * | val, | |
ExceptionSink * | xsink | |||
) |
reads a 4-byte unsigned integer from the file in LSB (Least Significant Byte first, big endian) format and returns the value read as an output parameter
A Qore-language exception can be thrown if the file is not opened
val | output parameter: the integer value read from the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT qore_size_t QoreFile::setPos | ( | qore_size_t | pos | ) |
sets the absolute file position to "pos"
pos | the file position in bytes to set (starting with byte position 0) |
DLLEXPORT int QoreFile::write | ( | const void * | data, | |
qore_size_t | len, | |||
ExceptionSink * | xsink | |||
) |
writes binary data to the file and returns the number of bytes written
Qore-language exceptions can be thrown if the file is not opened
data | the data to write to the file | |
len | the length of data to write to the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::write | ( | const BinaryNode * | b, | |
ExceptionSink * | xsink | |||
) |
writes binary data to the file and returns the number of bytes written
Qore-language exceptions can be thrown if the file is not opened
b | the binary data to write the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::write | ( | const QoreString * | str, | |
ExceptionSink * | xsink | |||
) |
writes string data to the file, character encoding is converted if necessary, and returns the number of bytes written
Qore-language exceptions can be thrown if the file is not opened or if encoding conversion fails
str | the string to write to the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::writei1 | ( | char | i, | |
ExceptionSink * | xsink | |||
) |
writes 1-byte binary integer data to the file and returns the number of bytes written (normally 1)
Qore-language exceptions can be thrown if the file is not opened
i | the 1-byte integer to write to the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::writei2 | ( | short | i, | |
ExceptionSink * | xsink | |||
) |
writes 2-byte (16bit) binary integer data in MSB (Most Significant Byte first, big endian) format to the file and returns the number of bytes written (normally 2)
Qore-language exceptions can be thrown if the file is not opened
i | the integer to write to the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::writei2LSB | ( | short | i, | |
ExceptionSink * | xsink | |||
) |
writes 2-byte (16bit) binary integer data in LSB (Least Significant Byte first, little endian) format to the file and returns the number of bytes written (normally 2)
Qore-language exceptions can be thrown if the file is not opened
i | the integer to write to the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::writei4 | ( | int | i, | |
ExceptionSink * | xsink | |||
) |
writes 4-byte (32bit) binary integer data in MSB (Most Significant Byte first, big endian) format to the file and returns the number of bytes written (normally 4)
Qore-language exceptions can be thrown if the file is not opened
i | the integer to write to the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::writei4LSB | ( | int | i, | |
ExceptionSink * | xsink | |||
) |
writes 4-byte (32bit) binary integer data in LSB (Least Significant Byte first, little endian)format to the file and returns the number of bytes written (normally 4)
Qore-language exceptions can be thrown if the file is not opened
i | the integer to write to the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::writei8 | ( | int64 | i, | |
ExceptionSink * | xsink | |||
) |
writes 8-byte (64bit) binary integer data in MSB (Most Significant Byte first, big endian) format to the file and returns the number of bytes written (normally 8)
Qore-language exceptions can be thrown if the file is not opened
i | the integer to write to the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |
DLLEXPORT int QoreFile::writei8LSB | ( | int64 | i, | |
ExceptionSink * | xsink | |||
) |
writes 8-byte (64bit) binary integer data in LSB (Least Significant Byte first, little endian) format to the file and returns the number of bytes written (normally 8)
Qore-language exceptions can be thrown if the file is not opened
i | the integer to write to the file | |
xsink | if an error occurs, the Qore-language exception info will be added here |