file.h
Go to the documentation of this file.
/*
* file.h
*
* Operating System file I/O channel class.
*
* Portable Windows Library
*
* Copyright (c) 1993-1998 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Portions are Copyright (C) 1993 Free Software Foundation, Inc.
* All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
* $Revision: 24177 $
* $Author: rjongbloed $
* $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
*/
#ifndef PTLIB_FILE_H
#define PTLIB_FILE_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#ifndef _WIN32
#include <sys/stat.h>
#endif
// Binary Files
class PFile : public PChannel
{
PCLASSINFO(PFile, PChannel);
public:
PFile();
enum OpenMode {
ReadOnly,
WriteOnly,
ReadWrite
};
enum OpenOptions {
ModeDefault = -1,
MustExist = 0,
Create = 1,
Truncate = 2,
Exclusive = 4,
Temporary = 8,
DenySharedRead = 16,
DenySharedWrite = 32
};
PFile(
OpenMode mode,
int opts = ModeDefault
);
PFile(
const PFilePath & name,
OpenMode mode = ReadWrite,
int opts = ModeDefault
);
~PFile();
Comparison Compare(
const PObject & obj
) const;
virtual PString GetName() const;
virtual PBoolean Read(
void * buf,
PINDEX len
);
virtual PBoolean Write(
const void * buf,
PINDEX len
);
virtual PBoolean Close();
static PBoolean Exists(
const PFilePath & name
);
PBoolean Exists() const;
static PBoolean Access(
const PFilePath & name,
OpenMode mode
);
PBoolean Access(
OpenMode mode
);
static PBoolean Remove(
const PFilePath & name, // Name of file to delete.
PBoolean force = false // Force deletion even if file is protected.
);
static PBoolean Remove(
const PString & name, // Name of file to delete.
PBoolean force = false // Force deletion even if file is protected.
);
PBoolean Remove(
PBoolean force = false // Force deletion even if file is protected.
);
static PBoolean Rename(
const PFilePath & oldname,
const PString & newname,
PBoolean force = false
);
PBoolean Rename(
const PString & newname,
PBoolean force = false
);
static PBoolean Copy(
const PFilePath & oldname,
const PFilePath & newname,
PBoolean force = false
);
PBoolean Copy(
const PFilePath & newname,
PBoolean force = false
);
static PBoolean Move(
const PFilePath & oldname,
const PFilePath & newname,
PBoolean force = false
);
PBoolean Move(
const PFilePath & newname,
PBoolean force = false
);
const PFilePath & GetFilePath() const;
void SetFilePath(
const PString & path
);
virtual PBoolean Open(
OpenMode mode = ReadWrite, // Mode in which to open the file.
int opts = ModeDefault // Options for open operation.
);
virtual PBoolean Open(
const PFilePath & name, // Name of file to open.
OpenMode mode = ReadWrite, // Mode in which to open the file.
int opts = ModeDefault // <code>OpenOptions</code> enum# for open operation.
);
virtual off_t GetLength() const;
virtual PBoolean SetLength(
off_t len // New length of file.
);
enum FilePositionOrigin {
Start = SEEK_SET,
Current = SEEK_CUR,
End = SEEK_END
};
virtual PBoolean SetPosition(
off_t pos,
FilePositionOrigin origin = Start
);
virtual off_t GetPosition() const;
PBoolean IsEndOfFile() const;
static PBoolean GetInfo(
const PFilePath & name, // Name of file to get the information on.
PFileInfo & info
// <code>PFileInfo</code> structure to receive the information.
);
PBoolean GetInfo(
PFileInfo & info
// <code>PFileInfo</code> structure to receive the information.
);
static PBoolean SetPermissions(
const PFilePath & name, // Name of file to change the permission of.
int permissions // New permissions mask for the file.
);
PBoolean SetPermissions(
int permissions // New permissions mask for the file.
);
protected:
// Member variables
PFilePath path;
PBoolean removeOnClose;
// Include platform dependent part of class
#ifdef _WIN32
#include "msos/ptlib/file.h"
#else
#include "unix/ptlib/file.h"
#endif
};
#endif // PTLIB_FILE_H
// End Of File ///////////////////////////////////////////////////////////////
PFile::Close
virtual PBoolean Close()
Close the file channel.
PFile::Read
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the file channel.
PFile::Exclusive
File open fails if file already exists.
Definition: file.h:103
PFile
This class represents a disk file.
Definition: file.h:60
PFile::IsEndOfFile
PBoolean IsEndOfFile() const
Determine if the current file position is at the end of the file.
PFile::Open
virtual PBoolean Open(OpenMode mode=ReadWrite, int opts=ModeDefault)
Open the current file in the specified mode and with the specified options.
PFile::DenySharedRead
File may not be read by another process.
Definition: file.h:107
PFilePath
This class describes a full description for a file on the particular platform.
Definition: filepath.h:65
PFile::DenySharedWrite
File may not be written by another process.
Definition: file.h:109
PFile::ReadWrite
File can be both read and written.
Definition: file.h:80
PObject::Comparison
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:1184
PFile::GetFilePath
const PFilePath & GetFilePath() const
Get the full path name of the file.
PFile::SetPosition
virtual PBoolean SetPosition(off_t pos, FilePositionOrigin origin=Start)
Set the current active position in the file for the next read or write operation. ...
PFile::ReadOnly
File can be read but not written.
Definition: file.h:78
PFile::Access
static PBoolean Access(const PFilePath &name, OpenMode mode)
Check for file access modes.
PFile::removeOnClose
PBoolean removeOnClose
File is to be removed when closed.
Definition: file.h:541
PBoolean
BOOL PBoolean
Definition: object.h:102
PFile::Remove
static PBoolean Remove(const PFilePath &name, PBoolean force=false)
Delete the specified file.
PFile::Copy
static PBoolean Copy(const PFilePath &oldname, const PFilePath &newname, PBoolean force=false)
Make a copy of the specified file.
PFile::Current
Set position relative to current file position.
Definition: file.h:461
PFile::GetPosition
virtual off_t GetPosition() const
Get the current active position in the file for the next read or write operation. ...
PFile::Write
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the file channel.
PChannel
Abstract class defining I/O channel semantics.
Definition: channel.h:107
PFile::FilePositionOrigin
FilePositionOrigin
Options for the origin in setting the file position.
Definition: file.h:457
PFile::Move
static PBoolean Move(const PFilePath &oldname, const PFilePath &newname, PBoolean force=false)
Move the specified file.
PFile::MustExist
File open fails if file does not exist.
Definition: file.h:97
PFile::Compare
Comparison Compare(const PObject &obj) const
Determine the relative rank of the two objects.
PFile::WriteOnly
File can be written but not read.
Definition: file.h:79
PFile::PFile
PFile()
Create a file object but do not open it.
PString
The character string class.
Definition: pstring.h:108
PFile::SetFilePath
void SetFilePath(const PString &path)
Set the full path name of the file.
PFile::ModeDefault
File options depend on the OpenMode parameter.
Definition: file.h:95
PFile::GetInfo
static PBoolean GetInfo(const PFilePath &name, PFileInfo &info)
Get information (eg protection, timestamps) on the specified file.
PFile::End
Set position relative to end of file.
Definition: file.h:463
PFile::path
PFilePath path
The fully qualified path name for the file.
Definition: file.h:540
PFile::GetLength
virtual off_t GetLength() const
Get the current size of the file.
PFile::Rename
static PBoolean Rename(const PFilePath &oldname, const PString &newname, PBoolean force=false)
Change the specified files name.
PFile::Create
File is created if it does not exist.
Definition: file.h:99
PFile::~PFile
~PFile()
Close the file on destruction.
PFile::Start
Set position relative to start of file.
Definition: file.h:459
PFile::SetLength
virtual PBoolean SetLength(off_t len)
Set the size of the file, padding with 0 bytes if it would require expanding the file, or truncating it if being made shorter.
PFile::OpenOptions
OpenOptions
When a file is opened, a number of options may be associated with the open file.
Definition: file.h:93
PFile::Exists
PBoolean Exists() const
Check for file existance.
PFileInfo
Class containing the system information on a file path.
Definition: pdirect.h:63
PFile::SetPermissions
static PBoolean SetPermissions(const PFilePath &name, int permissions)
Set permissions on the specified file.
PFile::Temporary
File is temporary and is to be deleted when closed.
Definition: file.h:105
PObject
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PFile::GetName
virtual PString GetName() const
Get the platform and I/O channel type name of the channel.
PFile::OpenMode
OpenMode
When a file is opened, it may restrict the access available to operations on the object instance...
Definition: file.h:77
PFile::Truncate
File is set to zero length if it already exists.
Definition: file.h:101