34#ifndef _QORE_QOREFILE_H
36#define _QORE_QOREFILE_H
38#include <qore/AbstractPollableIoObjectBase.h>
597 DLLLOCAL
void makeSpecial(
int sfd);
607 hashdecl qore_qf_private *
priv;
618DLLEXPORT
extern QoreClass* QC_READONLYFILE;
620class File :
public AbstractPollableIoObjectBase,
public QoreFile {
622 DLLLOCAL
virtual ~File();
627 DLLLOCAL
virtual void deref();
639class QoreFileHelper : QorePrivateObjectAccessHelper {
642 DLLEXPORT ~QoreFileHelper();
643 DLLEXPORT
QoreFile* operator*()
const;
644 DLLEXPORT
QoreFile* operator->()
const;
DLLEXPORT const QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
holds arbitrary binary data
Definition: BinaryNode.h:41
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
defines a Qore-language class
Definition: QoreClass.h:249
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
provides controlled access to file data through Qore data structures
Definition: QoreFile.h:66
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 size_t getPos()
returns the absolute byte position in the file
DLLEXPORT size_t getPos() const
returns the absolute byte position in the file
DLLEXPORT int readu2LSB(unsigned short *val, ExceptionSink *xsink)
reads a 2-byte unsigned integer from the file in LSB (Least Significant Byte first,...
DLLEXPORT int writei8(int64 i, ExceptionSink *xsink)
writes 8-byte (64bit) binary integer data in MSB (Most Significant Byte first, big endian) format to ...
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 QoreHashNode * hstat(ExceptionSink *xsink) const
returns a QoreHashNode with file status information
DLLEXPORT int close()
closes the file
DLLEXPORT int sync()
flushes the write buffer to disk
DLLEXPORT QoreStringNode * readUntil(const char *bytes, bool incl_bytes, ExceptionSink *xsink)
reads string data from the file up to and optionally including the terminating EOL characters passed ...
DLLEXPORT int readLine(QoreString &str, bool incl_eol)
clears the string passed, then reads string data from the file up to and optionally including the ter...
DLLEXPORT void setEncoding(const QoreEncoding *cs)
sets the encoding for the file
DLLEXPORT size_t read(void *ptr, size_t limit, int timeout_ms, ExceptionSink *xsink)
reads data from the file
DLLEXPORT QoreStringNode * readLine(ExceptionSink *xsink)
reads string data from the file up to and including the terminating EOL characters (can be "\n",...
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 ...
DLLEXPORT int readu4(unsigned int *val, ExceptionSink *xsink)
reads a 4-byte unsigned integer from the file in MSB (Most Significant Byte first,...
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 a...
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 lockBlocking(hashdecl flock &fl, ExceptionSink *xsink)
perform a file lock operation
DLLEXPORT int readLine(QoreString &str)
clears the string passed, then reads string data from the file up to and including the terminating EO...
DLLLOCAL QoreFile(const QoreFile &)
this function is not implemented; it is here as a private function in order to prohibit it from being...
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 ...
DLLEXPORT int writei8LSB(int64 i, ExceptionSink *xsink)
writes 8-byte (64bit) binary integer data in LSB (Least Significant Byte first, little endian) format...
DLLLOCAL void setEventQueue(ExceptionSink *xsink, Queue *q, QoreValue arg, bool with_data)
sets the event queue (not part of the library's pubilc API), must be already referenced before call
DLLEXPORT int getFD() const
get file descriptor
DLLEXPORT int read(QoreString &str, qore_offset_t size, ExceptionSink *xsink)
reads string data from the file into a QoreString object (or subclass, such as QoreStringNode) and re...
hashdecl qore_qf_private * priv
private implementation
Definition: QoreFile.h:607
DLLEXPORT int lock(const hashdecl flock &fl, ExceptionSink *xsink)
perform a file lock operation, does not block
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 int readi8LSB(int64 *val, ExceptionSink *xsink)
reads an 8-byte signed integer from the file in LSB (Least Significant Byte first,...
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 ...
DLLEXPORT int writei4LSB(int i, ExceptionSink *xsink)
writes 4-byte (32bit) binary integer data in LSB (Least Significant Byte first, little endian)format ...
DLLEXPORT size_t setPos(size_t pos)
sets the absolute file position to "pos"
DLLEXPORT int getLockInfo(hashdecl flock &fl, ExceptionSink *xsink)
get lock info operation, does not block
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 a...
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 chown(uid_t owner, gid_t group, ExceptionSink *xsink)
changes ownership of the file (if possible)
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 QoreListNode * stat(ExceptionSink *xsink) const
returns a QoreListNode with file status information
DLLEXPORT int writei4(int i, ExceptionSink *xsink)
writes 4-byte (32bit) binary integer data in MSB (Most Significant Byte first, big endian) format to ...
DLLEXPORT int writei2LSB(short i, ExceptionSink *xsink)
writes 2-byte (16bit) binary integer data in LSB (Least Significant Byte first, little endian) format...
DLLEXPORT int write(const BinaryNode *b, ExceptionSink *xsink)
writes binary data to the file and returns the number of bytes written
DLLEXPORT QoreStringNode * getchar()
reads a single byte from the file and returns it as a new string, caller owns the reference count ret...
DLLEXPORT int readu2(unsigned short *val, ExceptionSink *xsink)
reads a 2-byte unsigned integer from the file in MSB (Most Significant Byte first,...
DLLEXPORT int readUntil(char byte, QoreString &str, bool incl_bytes=true)
clears the string passed, then reads string data from the file up to a terminating byte value,...
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 int readUntil(const char *bytes, QoreString &str, bool incl_bytes=true)
clears the string passed, then reads string data from the file up to the given byte string,...
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
DLLLOCAL int getTerminalAttributes(QoreTermIOS *ios, ExceptionSink *xsink) const
gets terminal attributes
DLLEXPORT int writei2(short i, ExceptionSink *xsink)
writes 2-byte (16bit) binary integer data in MSB (Most Significant Byte first, big endian) format to ...
DLLEXPORT QoreStringNode * getchar(ExceptionSink *xsink)
reads a single character from the file and returns it as a new string, caller owns the reference coun...
DLLEXPORT int write(const void *data, size_t len, ExceptionSink *xsink)
writes binary data to the file and returns the number of bytes written
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 int readBinary(BinaryNode &b, qore_offset_t size, ExceptionSink *xsink)
reads binary data from the file into a BinaryNode object and returns 0 for OK or non-zero for error
DLLEXPORT bool isDataAvailable(int timeout_ms, ExceptionSink *xsink) const
returns true if data is available for the file descriptor
DLLEXPORT const QoreEncoding * getEncoding() const
returns the encoding used for the file
DLLLOCAL QoreFile & operator=(const QoreFile &)
this function is not implemented; it is here as a private function in order to prohibit it from being...
DLLLOCAL int setTerminalAttributes(int action, QoreTermIOS *ios, ExceptionSink *xsink) const
sets terminal attributes
DLLEXPORT int readu4LSB(unsigned int *val, ExceptionSink *xsink)
reads a 4-byte unsigned integer from the file in LSB (Least Significant Byte first,...
DLLEXPORT QoreHashNode * statvfs(ExceptionSink *xsink) const
returns a QoreHashNode with filesystem status information
DLLEXPORT int getPollableDescriptor() const
Returns the underlying file descriptor; -1 if not open.
DLLEXPORT QoreStringNode * readLine(bool incl_eol, ExceptionSink *xsink)
reads string data from the file up to and optionally including the terminating EOL characters (can be...
DLLEXPORT QoreFile(const QoreEncoding *cs=QCS_DEFAULT)
creates the object and sets the default encoding
DLLEXPORT QoreStringNode * getFileName() const
returns the filename of the file being read (NULL if no file name is set); caller owns the reference ...
DLLEXPORT std::string getFileNameStr() const
returns the filename of the file being read as a std::string (the string is empty if no file name is ...
DLLLOCAL void cleanup(ExceptionSink *xsink)
internal API, must be called before deleting the object if an event queue is set
DLLEXPORT int redirect(QoreFile &file, ExceptionSink *xsink)
redirects the current file (this) to the argument
DLLEXPORT ~QoreFile()
closes the file and frees all memory allocated to the object
DLLEXPORT bool isOpen() const
returns true if the file is open, false if not
DLLEXPORT bool isTty() const
returns true if the file is a tty
DLLEXPORT int detachFd()
detaches and returns the file descriptor
DLLEXPORT int write(const QoreString *str, ExceptionSink *xsink)
writes string data to the file, character encoding is converted if necessary, and returns the number ...
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
the implementation of Qore's object data type, reference counted, dynamically-allocated only
Definition: QoreObject.h:60
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
unsigned qore_classid_t
used for the unique class ID for QoreClass objects
Definition: common.h:79
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:276