# file.h

Go to the documentation of this file.

    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  * $Revision: 24177 $
    00030  * $Author: rjongbloed $
    00031  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
    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 // Binary Files
    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,   // Name of file to delete.
    00267       PBoolean force = false      // Force deletion even if file is protected.
    00268     );
    00269     static PBoolean Remove(
    00270       const PString & name,   // Name of file to delete.
    00271       PBoolean force = false      // Force deletion even if file is protected.
    00272     );
    00273
    00286     PBoolean Remove(
    00287       PBoolean force = false      // Force deletion even if file is protected.
    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,  // Mode in which to open the file.
    00420       int opts = ModeDefault      // Options for open operation.
    00421     );
    00422
    00433     virtual PBoolean Open(
    00434       const PFilePath & name,    // Name of file to open.
    00435       OpenMode mode = ReadWrite, // Mode in which to open the file.
    00436       int opts = ModeDefault     // <code>OpenOptions</code> enum# for open operation.
    00437     );
    00438
    00444     virtual off_t GetLength() const;
    00445
    00452     virtual PBoolean SetLength(
    00453       off_t len   // New length of file.
    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,  // Name of file to get the information on.
    00504       PFileInfo & info
    00505       // <code>PFileInfo</code> structure to receive the information.
    00506     );
    00507
    00513     PBoolean GetInfo(
    00514       PFileInfo & info
    00515       // <code>PFileInfo</code> structure to receive the information.
    00516     );
    00517
    00523     static PBoolean SetPermissions(
    00524       const PFilePath & name,   // Name of file to change the permission of.
    00525       int permissions           // New permissions mask for the file.
    00526     );
    00532     PBoolean SetPermissions(
    00533       int permissions           // New permissions mask for the file.
    00534     );
    00536
    00537   protected:
    00538     // Member variables
    00539
    00540     PFilePath path;
    00541     PBoolean removeOnClose;
    00542
    00543
    00544 // Include platform dependent part of class
    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 // End Of File ///////////////////////////////////////////////////////////////