KTempFile Class Reference
The KTempFile class creates and opens a unique file for temporary use. More...
#include <ktempfile.h>
Public Member Functions | |
KTempFile (QString filePrefix=QString::null, QString fileExtension=QString::null, int mode=0600) | |
~KTempFile () | |
void | setAutoDelete (bool autoDelete) |
int | status () const |
QString | name () const |
int | handle () const |
FILE * | fstream () |
QTextStream * | textStream () |
QDataStream * | dataStream () |
QFile * | file () |
void | unlink () |
bool | sync () |
bool | close () |
Protected Member Functions | |
KTempFile (bool) | |
bool | create (const QString &filePrefix, const QString &fileExtension, int mode) |
void | setError (int error) |
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
|
|
The destructor closes the file. If autoDelete is enabled the file gets unlinked as well. Definition at line 128 of file ktempfile.cpp. |
|
Constructor used by KSaveFile. Definition at line 78 of file ktempfile.cpp. |
Member Function Documentation
|
Turn automatic deletion on or off. Automatic deletion is off by default.
|
|
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.
Referenced by KSaveFile::status(). |
|
Returns the full path and name of the file. Note that in most circumstances the file needs to be closed before you use it by name. In particular, if another process or software part needs to write data to the file based on the filename, the file should be closed before doing so. Otherwise the act of closing the file later on may cause the file to get truncated to a zero-size, resulting in an unexpected loss of the data. In some cases there is only interest in the filename itself but where the actual presence of a file with such name is a problem. In that case the file should first be both closed and unlinked. Such usage is not recommended since it may lead to the kind of symlink vulnerabilities that the KTempFile design attempts to prevent.
Referenced by KSaveFile::close(), and file(). |
|
An integer file descriptor open for writing to the file.
Referenced by KSaveFile::handle(), and KSaveFile::KSaveFile(). |
|
Returns the FILE* of the temporary file.
Referenced by file(), and KSaveFile::fstream(). |
|
Returns the QTextStream for writing.
References file(). Referenced by KSaveFile::textStream(). |
|
Returns a QDataStream for writing.
References file(). Referenced by KSaveFile::dataStream(). |
|
Returns a QFile.
References fstream(), and name(). 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 201 of file ktempfile.cpp. Referenced by KSaveFile::abort(), KSaveFile::close(), and ~KTempFile(). |
|
Flushes file to disk (fsync). If you want to be as sure as possible that the file data has actually been physically stored on disk you need to call sync(). See status() for details about errors.
Referenced by KSaveFile::close(). |
|
Closes the file. See status() for details about errors.
Referenced by KSaveFile::abort(), KSaveFile::close(), and ~KTempFile(). |
The documentation for this class was generated from the following files: