00001 /* 00002 * file.h 00003 * 00004 * Operating System file I/O channel class. 00005 * 00006 * Portable Windows Library 00007 * 00008 * Copyright (c) 1993-1998 Equivalence Pty. Ltd. 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Portable Windows Library. 00021 * 00022 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00023 * 00024 * Portions are Copyright (C) 1993 Free Software Foundation, Inc. 00025 * All Rights Reserved. 00026 * 00027 * Contributor(s): ______________________________________. 00028 * 00029 * $Log: file.h,v $ 00030 * Revision 1.43 2005/11/25 03:43:47 csoutheren 00031 * Fixed function argument comments to be compatible with Doxygen 00032 * 00033 * Revision 1.42 2003/09/26 09:58:50 rogerhardiman 00034 * Move #include <sys/stat.h> from the unix file.h to the main file.h 00035 * FreeBSD's sys/stat.h includes extern "C" for some prototypes and you 00036 * cannot have an extern "C" in the middle of a C++ class 00037 * 00038 * Revision 1.41 2003/09/17 05:41:58 csoutheren 00039 * Removed recursive includes 00040 * 00041 * Revision 1.40 2003/09/17 01:18:02 csoutheren 00042 * Removed recursive include file system and removed all references 00043 * to deprecated coooperative threading support 00044 * 00045 * Revision 1.39 2002/09/16 01:08:59 robertj 00046 * Added #define so can select if #pragma interface/implementation is used on 00047 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00048 * 00049 * Revision 1.38 2002/07/02 08:00:55 craigs 00050 * Also made GetPosition, SetPosition and SetLength virtual as well 00051 * 00052 * Revision 1.37 2002/07/02 07:59:42 craigs 00053 * Added virtual to GetLength call 00054 * 00055 * Revision 1.36 2002/01/13 20:54:55 rogerh 00056 * Make the other Open() virtual so it can be overridden (eg in PWAVFile) 00057 * 00058 * Revision 1.35 2001/05/22 12:49:32 robertj 00059 * Did some seriously wierd rewrite of platform headers to eliminate the 00060 * stupid GNU compiler warning about braces not matching. 00061 * 00062 * Revision 1.34 2000/09/27 05:58:07 craigs 00063 * Added virtual to PFile::Open to allow overriding in descandant classes 00064 * 00065 * Revision 1.33 2000/07/09 14:05:46 robertj 00066 * Added file share options. 00067 * 00068 * Revision 1.32 1999/06/13 13:54:07 robertj 00069 * Added PConsoleChannel class for access to stdin/stdout/stderr. 00070 * 00071 * Revision 1.31 1999/06/09 02:05:20 robertj 00072 * Added ability to open file as standard input, output and error streams. 00073 * 00074 * Revision 1.30 1999/03/09 02:59:49 robertj 00075 * Changed comments to doc++ compatible documentation. 00076 * 00077 * Revision 1.29 1999/02/16 08:07:11 robertj 00078 * MSVC 6.0 compatibility changes. 00079 * 00080 * Revision 1.28 1998/09/23 06:20:35 robertj 00081 * Added open source copyright license. 00082 * 00083 * Revision 1.27 1995/07/31 12:15:43 robertj 00084 * Removed PContainer from PChannel ancestor. 00085 * 00086 * Revision 1.26 1995/06/17 11:12:33 robertj 00087 * Documentation update. 00088 * 00089 * Revision 1.25 1995/04/22 00:43:57 robertj 00090 * Added Move() function and changed semantics of Rename(). 00091 * Changed all file name strings to PFilePath objects. 00092 * 00093 * Revision 1.24 1995/03/14 12:41:23 robertj 00094 * Updated documentation to use HTML codes. 00095 * 00096 * Revision 1.23 1995/03/12 04:37:13 robertj 00097 * Moved GetHandle() function from PFile to PChannel. 00098 * 00099 * Revision 1.22 1995/01/14 06:22:11 robertj 00100 * Documentation 00101 * 00102 * Revision 1.21 1994/12/21 11:52:54 robertj 00103 * Documentation and variable normalisation. 00104 * 00105 * Revision 1.20 1994/08/23 11:32:52 robertj 00106 * Oops 00107 * 00108 * Revision 1.19 1994/08/22 00:46:48 robertj 00109 * Added pragma fro GNU C++ compiler. 00110 * 00111 * Revision 1.18 1994/08/21 23:43:02 robertj 00112 * Added "remove on close" feature for temporary files. 00113 * Added "force" option to Remove/Rename etc to override write protection. 00114 * Added function to set file permissions. 00115 * 00116 * Revision 1.17 1994/07/17 10:46:06 robertj 00117 * Moved data to platform dependent files. 00118 * 00119 * Revision 1.16 1994/06/25 11:55:15 robertj 00120 * Unix version synchronisation. 00121 * 00122 * Revision 1.15 1994/04/20 12:17:44 robertj 00123 * Split name into PFilePath 00124 * 00125 * Revision 1.14 1994/04/01 14:11:03 robertj 00126 * Added const to functions. 00127 * Added SetName function. 00128 * 00129 * Revision 1.13 1994/03/07 07:38:19 robertj 00130 * Major enhancementsacross the board. 00131 * 00132 * Revision 1.12 1994/01/13 03:40:22 robertj 00133 * Added hidden flag to file info. 00134 * 00135 * Revision 1.12 1994/01/13 03:36:48 robertj 00136 * Created intermediate class PInteractorLayout for dialog-ish windows. 00137 * 00138 * Revision 1.11 1994/01/03 04:42:23 robertj 00139 * Mass changes to common container classes and interactors etc etc etc. 00140 * 00141 * Revision 1.10 1993/12/31 06:45:38 robertj 00142 * Made inlines optional for debugging purposes. 00143 * 00144 * Revision 1.9 1993/09/27 16:35:25 robertj 00145 * Changed GetName() to GetTitle(), better naming convention. 00146 * Moved internal functions to private section. 00147 * 00148 * Revision 1.8 1993/08/31 03:38:02 robertj 00149 * Changed PFile::Status to PFile::Info due to X-Windows compatibility. 00150 * 00151 * Revision 1.7 1993/08/27 18:17:47 robertj 00152 * Moved code from MS-DOS platform to common files. 00153 * 00154 * Revision 1.6 1993/08/21 04:40:19 robertj 00155 * Added Copy() function. 00156 * 00157 * Revision 1.5 1993/08/21 01:50:33 robertj 00158 * Made Clone() function optional, default will assert if called. 00159 * 00160 * Revision 1.4 1993/08/01 14:05:27 robertj 00161 * Added GetFileName() function required for proper portability. 00162 * Improved some comments. 00163 * 00164 * Revision 1.3 1993/07/14 12:49:16 robertj 00165 * Fixed RCS keywords. 00166 * 00167 */ 00168 00169 00170 #ifndef _PFILE 00171 #define _PFILE 00172 00173 #ifdef P_USE_PRAGMA 00174 #pragma interface 00175 #endif 00176 00177 #ifndef _WIN32 00178 #include <sys/stat.h> 00179 #endif 00180 00181 00182 00184 // Binary Files 00185 00195 class PFile : public PChannel 00196 { 00197 PCLASSINFO(PFile, PChannel); 00198 00199 public: 00206 PFile(); 00207 00212 enum OpenMode { 00214 ReadOnly, 00216 WriteOnly, 00218 ReadWrite 00219 }; 00220 00236 enum OpenOptions { 00238 ModeDefault = -1, 00240 MustExist = 0, 00242 Create = 1, 00244 Truncate = 2, 00246 Exclusive = 4, 00248 Temporary = 8, 00250 DenySharedRead = 16, 00252 DenySharedWrite = 32 00253 }; 00254 00263 PFile( 00264 OpenMode mode, 00265 int opts = ModeDefault 00266 ); 00267 00274 PFile( 00275 const PFilePath & name, 00276 OpenMode mode = ReadWrite, 00277 int opts = ModeDefault 00278 ); 00279 00281 ~PFile(); 00283 00284 00293 Comparison Compare( 00294 const PObject & obj 00295 ) const; 00297 00298 00307 virtual PString GetName() const; 00308 00320 virtual BOOL Read( 00321 void * buf, 00322 PINDEX len 00323 ); 00324 00334 virtual BOOL Write( 00335 const void * buf, 00336 PINDEX len 00337 ); 00338 00342 virtual BOOL Close(); 00344 00345 00355 static BOOL Exists( 00356 const PFilePath & name 00357 ); 00358 00366 BOOL Exists() const; 00367 00377 static BOOL Access( 00378 const PFilePath & name, 00379 OpenMode mode 00380 ); 00381 00392 BOOL Access( 00393 OpenMode mode 00394 ); 00395 00408 static BOOL Remove( 00409 const PFilePath & name, // Name of file to delete. 00410 BOOL force = FALSE // Force deletion even if file is protected. 00411 ); 00412 00425 BOOL Remove( 00426 BOOL force = FALSE // Force deletion even if file is protected. 00427 ); 00428 00444 static BOOL Rename( 00445 const PFilePath & oldname, 00446 const PString & newname, 00447 BOOL force = FALSE 00449 ); 00450 00467 BOOL Rename( 00468 const PString & newname, 00469 BOOL force = FALSE 00471 ); 00472 00478 static BOOL Copy( 00479 const PFilePath & oldname, 00480 const PFilePath & newname, 00481 BOOL force = FALSE 00483 ); 00484 00490 BOOL Copy( 00491 const PFilePath & newname, 00492 BOOL force = FALSE 00494 ); 00495 00505 static BOOL Move( 00506 const PFilePath & oldname, 00507 const PFilePath & newname, 00508 BOOL force = FALSE 00510 ); 00511 00521 BOOL Move( 00522 const PFilePath & newname, 00523 BOOL force = FALSE 00525 ); 00527 00536 const PFilePath & GetFilePath() const; 00537 00541 void SetFilePath( 00542 const PString & path 00543 ); 00544 00545 00557 virtual BOOL Open( 00558 OpenMode mode = ReadWrite, // Mode in which to open the file. 00559 int opts = ModeDefault // Options for open operation. 00560 ); 00561 00572 virtual BOOL Open( 00573 const PFilePath & name, // Name of file to open. 00574 OpenMode mode = ReadWrite, // Mode in which to open the file. 00575 int opts = ModeDefault // #OpenOptions enum# for open operation. 00576 ); 00577 00583 virtual off_t GetLength() const; 00584 00591 virtual BOOL SetLength( 00592 off_t len // New length of file. 00593 ); 00594 00596 enum FilePositionOrigin { 00598 Start = SEEK_SET, 00600 Current = SEEK_CUR, 00602 End = SEEK_END 00603 }; 00604 00615 virtual BOOL SetPosition( 00616 off_t pos, 00617 FilePositionOrigin origin = Start 00618 ); 00619 00626 virtual off_t GetPosition() const; 00627 00634 BOOL IsEndOfFile() const; 00635 00641 static BOOL GetInfo( 00642 const PFilePath & name, // Name of file to get the information on. 00643 PFileInfo & info 00644 // #PFileInfo# structure to receive the information. 00645 ); 00646 00652 BOOL GetInfo( 00653 PFileInfo & info 00654 // #PFileInfo# structure to receive the information. 00655 ); 00656 00662 static BOOL SetPermissions( 00663 const PFilePath & name, // Name of file to change the permission of. 00664 int permissions // New permissions mask for the file. 00665 ); 00671 BOOL SetPermissions( 00672 int permissions // New permissions mask for the file. 00673 ); 00675 00676 protected: 00677 // Member variables 00679 PFilePath path; 00680 00682 BOOL removeOnClose; 00683 00684 00685 // Include platform dependent part of class 00686 #ifdef _WIN32 00687 #include "msos/ptlib/file.h" 00688 #else 00689 #include "unix/ptlib/file.h" 00690 #endif 00691 }; 00692 00693 #endif 00694 00695 // End Of File ///////////////////////////////////////////////////////////////