00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef PTLIB_FILE_H
00036 #define PTLIB_FILE_H
00037
00038 #ifdef P_USE_PRAGMA
00039 #pragma interface
00040 #endif
00041
00042 #ifndef _WIN32
00043 #include <sys/stat.h>
00044 #endif
00045
00046
00047
00049
00050
00060 class PFile : public PChannel
00061 {
00062 PCLASSINFO(PFile, PChannel);
00063
00064 public:
00071 PFile();
00072
00077 enum OpenMode {
00078 ReadOnly,
00079 WriteOnly,
00080 ReadWrite
00081 };
00082
00093 enum OpenOptions {
00095 ModeDefault = -1,
00097 MustExist = 0,
00099 Create = 1,
00101 Truncate = 2,
00103 Exclusive = 4,
00105 Temporary = 8,
00107 DenySharedRead = 16,
00109 DenySharedWrite = 32
00110 };
00111
00120 PFile(
00121 OpenMode mode,
00122 int opts = ModeDefault
00123 );
00124
00131 PFile(
00132 const PFilePath & name,
00133 OpenMode mode = ReadWrite,
00134 int opts = ModeDefault
00135 );
00136
00138 ~PFile();
00140
00141
00150 Comparison Compare(
00151 const PObject & obj
00152 ) const;
00154
00155
00164 virtual PString GetName() const;
00165
00177 virtual PBoolean Read(
00178 void * buf,
00179 PINDEX len
00180 );
00181
00191 virtual PBoolean Write(
00192 const void * buf,
00193 PINDEX len
00194 );
00195
00199 virtual PBoolean Close();
00201
00202
00212 static PBoolean Exists(
00213 const PFilePath & name
00214 );
00215
00223 PBoolean Exists() const;
00224
00234 static PBoolean Access(
00235 const PFilePath & name,
00236 OpenMode mode
00237 );
00238
00249 PBoolean Access(
00250 OpenMode mode
00251 );
00252
00265 static PBoolean Remove(
00266 const PFilePath & name,
00267 PBoolean force = false
00268 );
00269 static PBoolean Remove(
00270 const PString & name,
00271 PBoolean force = false
00272 );
00273
00286 PBoolean Remove(
00287 PBoolean force = false
00288 );
00289
00305 static PBoolean Rename(
00306 const PFilePath & oldname,
00307 const PString & newname,
00308 PBoolean force = false
00310 );
00311
00328 PBoolean Rename(
00329 const PString & newname,
00330 PBoolean force = false
00332 );
00333
00339 static PBoolean Copy(
00340 const PFilePath & oldname,
00341 const PFilePath & newname,
00342 PBoolean force = false
00344 );
00345
00351 PBoolean Copy(
00352 const PFilePath & newname,
00353 PBoolean force = false
00355 );
00356
00366 static PBoolean Move(
00367 const PFilePath & oldname,
00368 const PFilePath & newname,
00369 PBoolean force = false
00371 );
00372
00382 PBoolean Move(
00383 const PFilePath & newname,
00384 PBoolean force = false
00386 );
00388
00397 const PFilePath & GetFilePath() const;
00398
00402 void SetFilePath(
00403 const PString & path
00404 );
00405
00406
00418 virtual PBoolean Open(
00419 OpenMode mode = ReadWrite,
00420 int opts = ModeDefault
00421 );
00422
00433 virtual PBoolean Open(
00434 const PFilePath & name,
00435 OpenMode mode = ReadWrite,
00436 int opts = ModeDefault
00437 );
00438
00444 virtual off_t GetLength() const;
00445
00452 virtual PBoolean SetLength(
00453 off_t len
00454 );
00455
00457 enum FilePositionOrigin {
00459 Start = SEEK_SET,
00461 Current = SEEK_CUR,
00463 End = SEEK_END
00464 };
00465
00476 virtual PBoolean SetPosition(
00477 off_t pos,
00478 FilePositionOrigin origin = Start
00479 );
00480
00487 virtual off_t GetPosition() const;
00488
00495 PBoolean IsEndOfFile() const;
00496
00502 static PBoolean GetInfo(
00503 const PFilePath & name,
00504 PFileInfo & info
00505
00506 );
00507
00513 PBoolean GetInfo(
00514 PFileInfo & info
00515
00516 );
00517
00523 static PBoolean SetPermissions(
00524 const PFilePath & name,
00525 int permissions
00526 );
00532 PBoolean SetPermissions(
00533 int permissions
00534 );
00536
00537 protected:
00538
00539
00540 PFilePath path;
00541 PBoolean removeOnClose;
00542
00543
00544
00545 #ifdef _WIN32
00546 #include "msos/ptlib/file.h"
00547 #else
00548 #include "unix/ptlib/file.h"
00549 #endif
00550 };
00551
00552
00553 #endif // PTLIB_FILE_H
00554
00555
00556