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 {
00079 ReadOnly,
00081 WriteOnly,
00083 ReadWrite
00084 };
00085
00101 enum OpenOptions {
00103 ModeDefault = -1,
00105 MustExist = 0,
00107 Create = 1,
00109 Truncate = 2,
00111 Exclusive = 4,
00113 Temporary = 8,
00115 DenySharedRead = 16,
00117 DenySharedWrite = 32
00118 };
00119
00128 PFile(
00129 OpenMode mode,
00130 int opts = ModeDefault
00131 );
00132
00139 PFile(
00140 const PFilePath & name,
00141 OpenMode mode = ReadWrite,
00142 int opts = ModeDefault
00143 );
00144
00146 ~PFile();
00148
00149
00158 Comparison Compare(
00159 const PObject & obj
00160 ) const;
00162
00163
00172 virtual PString GetName() const;
00173
00185 virtual PBoolean Read(
00186 void * buf,
00187 PINDEX len
00188 );
00189
00199 virtual PBoolean Write(
00200 const void * buf,
00201 PINDEX len
00202 );
00203
00207 virtual PBoolean Close();
00209
00210
00220 static PBoolean Exists(
00221 const PFilePath & name
00222 );
00223
00231 PBoolean Exists() const;
00232
00242 static PBoolean Access(
00243 const PFilePath & name,
00244 OpenMode mode
00245 );
00246
00257 PBoolean Access(
00258 OpenMode mode
00259 );
00260
00273 static PBoolean Remove(
00274 const PFilePath & name,
00275 PBoolean force = PFalse
00276 );
00277 static PBoolean Remove(
00278 const PString & name,
00279 PBoolean force = PFalse
00280 );
00281
00294 PBoolean Remove(
00295 PBoolean force = PFalse
00296 );
00297
00313 static PBoolean Rename(
00314 const PFilePath & oldname,
00315 const PString & newname,
00316 PBoolean force = PFalse
00318 );
00319
00336 PBoolean Rename(
00337 const PString & newname,
00338 PBoolean force = PFalse
00340 );
00341
00347 static PBoolean Copy(
00348 const PFilePath & oldname,
00349 const PFilePath & newname,
00350 PBoolean force = PFalse
00352 );
00353
00359 PBoolean Copy(
00360 const PFilePath & newname,
00361 PBoolean force = PFalse
00363 );
00364
00374 static PBoolean Move(
00375 const PFilePath & oldname,
00376 const PFilePath & newname,
00377 PBoolean force = PFalse
00379 );
00380
00390 PBoolean Move(
00391 const PFilePath & newname,
00392 PBoolean force = PFalse
00394 );
00396
00405 const PFilePath & GetFilePath() const;
00406
00410 void SetFilePath(
00411 const PString & path
00412 );
00413
00414
00426 virtual PBoolean Open(
00427 OpenMode mode = ReadWrite,
00428 int opts = ModeDefault
00429 );
00430
00441 virtual PBoolean Open(
00442 const PFilePath & name,
00443 OpenMode mode = ReadWrite,
00444 int opts = ModeDefault
00445 );
00446
00452 virtual off_t GetLength() const;
00453
00460 virtual PBoolean SetLength(
00461 off_t len
00462 );
00463
00465 enum FilePositionOrigin {
00467 Start = SEEK_SET,
00469 Current = SEEK_CUR,
00471 End = SEEK_END
00472 };
00473
00484 virtual PBoolean SetPosition(
00485 off_t pos,
00486 FilePositionOrigin origin = Start
00487 );
00488
00495 virtual off_t GetPosition() const;
00496
00503 PBoolean IsEndOfFile() const;
00504
00510 static PBoolean GetInfo(
00511 const PFilePath & name,
00512 PFileInfo & info
00513
00514 );
00515
00521 PBoolean GetInfo(
00522 PFileInfo & info
00523
00524 );
00525
00531 static PBoolean SetPermissions(
00532 const PFilePath & name,
00533 int permissions
00534 );
00540 PBoolean SetPermissions(
00541 int permissions
00542 );
00544
00545 protected:
00546
00548 PFilePath path;
00549
00551 PBoolean removeOnClose;
00552
00553
00554
00555 #ifdef _WIN32
00556 #include "msos/ptlib/file.h"
00557 #else
00558 #include "unix/ptlib/file.h"
00559 #endif
00560 };
00561
00562
00563 #endif // PTLIB_FILE_H
00564
00565
00566