KTempFile Class Reference
The KTempFile class creates and opens a unique file for temporary use. More...
#include <ktempfile.h>
Public Methods | |
KTempFile (QString filePrefix=QString::null, QString fileExtension=QString::null, int mode=0600) | |
Creates a temporary file with the name: <filePrefix><six letters><fileExtension>. | |
~KTempFile () | |
The destructor closes the file. | |
void | setAutoDelete (bool autoDelete) |
Turn automatic deletion on or off. | |
int | status () const |
Returns the status of the file based on errno. | |
QString | name () const |
Returns the full path and name of the file. | |
int | handle () const |
An integer file descriptor open for writing to the file. | |
FILE * | fstream () |
Returns the FILE* of the temporary file. | |
QTextStream * | textStream () |
Returns the QTextStream for writing. | |
QDataStream * | dataStream () |
Returns a QDataStream for writing. | |
QFile * | file () |
Returns a QFile. | |
void | unlink () |
Unlinks the file from the directory. | |
bool | close () |
Closes the file. | |
Protected Methods | |
KTempFile (bool) | |
Constructor used by KSaveFile. |
Detailed Description
The KTempFile class creates and opens a unique file for temporary use.This is especially useful if you need to create a file in a world writable directory like /tmp without being vulnerable to so called symlink attacks.
KDE applications, however, shouldn't create files in /tmp in the first place but use the "tmp" resource instead. The standard KTempFile constructor will do that by default.
To create a temporary file that starts with a certain name in the "tmp" resource, one should use: KTempFile(locateLocal("tmp", prefix), extension);
KTempFile does not create any missing directories, but locateLocal() does.
See also KStandardDirs
- Author:
- Waldo Bastian <bastian@kde.org>
Definition at line 54 of file ktempfile.h.
Constructor & Destructor Documentation
|
Creates a temporary file with the name: <filePrefix><six letters><fileExtension>.
The default
Definition at line 58 of file ktempfile.cpp. References KGlobal::instance(), and QString::isEmpty(). |
|
The destructor closes the file. If autoDelete is enabled the file gets unlinked as well. Definition at line 123 of file ktempfile.cpp. |
|
Constructor used by KSaveFile.
Definition at line 77 of file ktempfile.cpp. |
Member Function Documentation
|
Turn automatic deletion on or off. Automatic deletion is off by default.
Definition at line 85 of file ktempfile.h. |
|
Returns the status of the file based on errno. (see errno.h) 0 means OK. You should check the status after object creation to check whether a file could be created in the first place. You may check the status after closing the file to verify that the file has indeed been written correctly.
Definition at line 131 of file ktempfile.cpp. Referenced by KSaveFile::status(). |
|
Returns the full path and name of the file.
Definition at line 137 of file ktempfile.cpp. Referenced by KSaveFile::close(), and file(). |
|
An integer file descriptor open for writing to the file.
Definition at line 143 of file ktempfile.cpp. Referenced by KSaveFile::handle(). |
|
Returns the FILE* of the temporary file.
Definition at line 149 of file ktempfile.cpp. References QString::latin1(). Referenced by file(), and KSaveFile::fstream(). |
|
Returns the QTextStream for writing.
Definition at line 176 of file ktempfile.cpp. References file(). Referenced by KSaveFile::textStream(). |
|
Returns a QDataStream for writing.
Definition at line 186 of file ktempfile.cpp. References file(). Referenced by KSaveFile::dataStream(). |
|
Returns a QFile.
Definition at line 164 of file ktempfile.cpp. References fstream(), name(), QFile::open(), and QFile::setName(). Referenced by dataStream(), KSaveFile::file(), and textStream(). |
|
Unlinks the file from the directory. The file is deleted once the last reader/writer closes it. Definition at line 196 of file ktempfile.cpp. References QString::isEmpty(), and QFile::remove(). Referenced by KSaveFile::abort(), KSaveFile::close(), and ~KTempFile(). |
|
Closes the file. See status() for details about errors.
Definition at line 204 of file ktempfile.cpp. References QString::latin1(). Referenced by KSaveFile::abort(), KSaveFile::close(), and ~KTempFile(). |
The documentation for this class was generated from the following files: