|
Qore Programming Language
0.8.3
|
00001 /* -*- mode: c++; indent-tabs-mode: nil -*- */ 00002 /* 00003 QoreFile.h 00004 00005 thread-safe File object 00006 00007 Qore Programming Language 00008 00009 Copyright 2003 - 2011 David Nichols 00010 00011 This library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU Lesser General Public 00013 License as published by the Free Software Foundation; either 00014 version 2.1 of the License, or (at your option) any later version. 00015 00016 This library is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 Lesser General Public License for more details. 00020 00021 You should have received a copy of the GNU Lesser General Public 00022 License along with this library; if not, write to the Free Software 00023 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 */ 00025 00026 #ifndef _QORE_QOREFILE_H 00027 00028 #define _QORE_QOREFILE_H 00029 00030 #include <fcntl.h> 00031 00032 #include <sys/file.h> 00033 #include <unistd.h> 00034 00035 class QoreTermIOS; 00036 class Queue; 00037 00039 00044 class QoreFile { 00045 private: 00047 struct qore_qf_private *priv; 00048 00049 protected: 00051 DLLLOCAL QoreFile(const QoreFile&); 00052 00054 DLLLOCAL QoreFile& operator=(const QoreFile&); 00055 00056 public: 00058 DLLEXPORT QoreFile(const QoreEncoding *cs = QCS_DEFAULT); 00059 00061 DLLEXPORT ~QoreFile(); 00062 00064 00073 DLLEXPORT int open(const char *fn, int flags = O_RDONLY, int mode = 0777, const QoreEncoding *cs = QCS_DEFAULT); 00074 00076 00086 DLLEXPORT int open2(ExceptionSink *xsink, const char *fn, int flags = O_RDONLY, int mode = 0777, const QoreEncoding *cs = QCS_DEFAULT); 00087 00089 00092 DLLEXPORT int close(); 00093 00095 DLLEXPORT void setEncoding(const QoreEncoding *cs); 00096 00098 DLLEXPORT const QoreEncoding *getEncoding() const; 00099 00101 DLLEXPORT int sync(); 00102 00104 00108 DLLEXPORT QoreStringNode *readLine(ExceptionSink *xsink); 00109 00111 00114 DLLEXPORT int readLine(QoreString &str); 00115 00117 00122 DLLEXPORT int write(const QoreString *str, ExceptionSink *xsink); 00123 00125 00130 DLLEXPORT int write(const BinaryNode *b, ExceptionSink *xsink); 00131 00133 00139 DLLEXPORT int write(const void *data, qore_size_t len, ExceptionSink *xsink); 00140 00142 00147 DLLEXPORT int writei1(char i, ExceptionSink *xsink); 00148 00150 00156 DLLEXPORT int writei2(short i, ExceptionSink *xsink); 00157 00159 00165 DLLEXPORT int writei4(int i, ExceptionSink *xsink); 00166 00168 00174 DLLEXPORT int writei8(int64 i, ExceptionSink *xsink); 00175 00177 00183 DLLEXPORT int writei2LSB(short i, ExceptionSink *xsink); 00184 00186 00192 DLLEXPORT int writei4LSB(int i, ExceptionSink *xsink); 00193 00195 00201 DLLEXPORT int writei8LSB(int64 i, ExceptionSink *xsink); 00202 00204 00210 DLLEXPORT int readu1(unsigned char *val, ExceptionSink *xsink); 00211 00213 00221 DLLEXPORT int readu2(unsigned short *val, ExceptionSink *xsink); 00222 00224 00232 DLLEXPORT int readu4(unsigned int *val, ExceptionSink *xsink); 00233 00235 00243 DLLEXPORT int readu2LSB(unsigned short *val, ExceptionSink *xsink); 00244 00246 00254 DLLEXPORT int readu4LSB(unsigned int *val, ExceptionSink *xsink); 00255 00257 00263 DLLEXPORT int readi1(char *val, ExceptionSink *xsink); 00264 00266 00274 DLLEXPORT int readi2(short *val, ExceptionSink *xsink); 00275 00277 00285 DLLEXPORT int readi4(int *val, ExceptionSink *xsink); 00286 00288 00294 DLLEXPORT int readi8(int64 *val, ExceptionSink *xsink); 00295 00297 00305 DLLEXPORT int readi2LSB(short *val, ExceptionSink *xsink); 00306 00308 00316 DLLEXPORT int readi4LSB(int *val, ExceptionSink *xsink); 00317 00319 00325 DLLEXPORT int readi8LSB(int64 *val, ExceptionSink *xsink); 00326 00328 00334 DLLEXPORT QoreStringNode *read(qore_offset_t size, ExceptionSink *xsink); 00335 00337 00344 DLLEXPORT int read(QoreString &str, qore_offset_t size, ExceptionSink *xsink); 00345 00347 00352 DLLEXPORT BinaryNode *readBinary(qore_offset_t size, ExceptionSink *xsink); 00353 00355 00361 DLLEXPORT int readBinary(BinaryNode &b, qore_offset_t size, ExceptionSink *xsink); 00362 00364 00371 DLLEXPORT QoreStringNode *read(qore_offset_t size, int timeout_ms, ExceptionSink *xsink); 00372 00374 00380 DLLEXPORT BinaryNode *readBinary(qore_offset_t size, int timeout_ms, ExceptionSink *xsink); 00381 00383 00385 DLLEXPORT qore_size_t setPos(qore_size_t pos); 00386 00388 00390 DLLEXPORT qore_size_t getPos(); 00391 00393 00397 DLLEXPORT QoreStringNode *getchar(); 00398 00400 DLLEXPORT QoreStringNode *getFileName() const; 00401 00402 #if (!defined _WIN32 && !defined __WIN32__) || defined __CYGWIN__ 00403 00404 DLLEXPORT int chown(uid_t owner, gid_t group, ExceptionSink *xsink); 00405 00407 DLLEXPORT int lockBlocking(struct flock &fl, ExceptionSink *xsink); 00408 00410 DLLEXPORT int lock(const struct flock &fl, ExceptionSink *xsink); 00411 00413 DLLEXPORT int getLockInfo(struct flock &fl, ExceptionSink *xsink); 00414 #endif 00415 00417 00421 DLLEXPORT bool isDataAvailable(int timeout_ms, ExceptionSink *xsink) const; 00422 00424 00427 DLLEXPORT QoreListNode *stat(ExceptionSink *xsink) const; 00428 00430 00433 DLLEXPORT QoreHashNode *hstat(ExceptionSink *xsink) const; 00434 00436 00439 DLLEXPORT QoreHashNode *statvfs(ExceptionSink *xsink) const; 00440 00441 #if 0 00442 00443 DLLEXPORT int preallocate(fstore_t &fs, ExceptionSink *xsink); 00444 #endif 00445 00447 DLLEXPORT int getFD() const; 00448 00450 DLLLOCAL int setTerminalAttributes(int action, QoreTermIOS *ios, ExceptionSink *xsink) const; 00451 00453 DLLLOCAL int getTerminalAttributes(QoreTermIOS *ios, ExceptionSink *xsink) const; 00454 00455 // NOTE: QoreFile::makeSpecial() can only be called right after the constructor (private API) 00456 DLLLOCAL void makeSpecial(int sfd); 00457 00459 DLLLOCAL void setEventQueue(Queue *cbq, ExceptionSink *xsink); 00460 00462 DLLLOCAL void cleanup(ExceptionSink *xsink); 00463 }; 00464 00465 #endif // _QORE_QOREFILE_H