class KTempFile

The KTempFile class creates and opens a unique file for temporary use. More...

Definition#include <ktempfile.h>
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Methods

Protected Methods


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

 KTempFile (QString filePrefix=QString::null, QString fileExtension=QString::null, int mode = 0600 )

KTempFile

Creates a temporary file with the name:

The default filePrefix is "$KDEHOME/tmp-$HOST/appname" The default fileExtension is ".tmp"

Parameters:
filePrefixthe prefix of the file name, or QString::null for the default value
theextension of the prefix, or QString::null for the default value

 ~KTempFile ()

~KTempFile

The destructor closes the file. If autoDelete is enabled the file gets unlinked as well.

void  setAutoDelete (bool autoDelete)

setAutoDelete

Turn automatic deletion on or off. Automatic deletion is off by default.

Parameters:
autoDeletetrue to turn automatic deletion on

int  status ()

status

[const]

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.

Returns: the errno status, 0 means ok

QString  name ()

name

[const]

Returns the full path and name of the file.

Returns: The name of the file, or QString::null if opening the file has failed or the file has been unlinked

int  handle ()

handle

[const]

An integer file descriptor open for writing to the file

Returns: The file descriptor, or a negative number if opening the file failed

FILE * fstream ()

fstream

Returns the FILE* of the temporary file.

Returns: FILE* stream open for writing to the file, or 0 if opening the file failed

QTextStreamtextStream ()

textStream

Returns the QTextStream for writing.

Returns: QTextStream open for writing to the file, or 0 if opening the file failed

QDataStreamdataStream ()

dataStream

Returns a QDataStream for writing.

Returns: QDataStream open for writing to the file, or 0 if opening the file failed

QFilefile ()

file

Returns a QFile.

Returns: A QFile open for writing to the file, or 0 if opening the file failed.

void  unlink ()

unlink

Unlinks the file from the directory. The file is deleted once the last reader/writer closes it.

bool  close ()

close

Closes the file.

See status() for details about errors.

Returns: true if successful, or false if an error has occured.

 KTempFile (bool)

KTempFile

[protected]

Constructor used by KSaveFile

bool  create (const QString &filePrefix, const QString &fileExtension, int mode)

create

[protected]

Create function used internally by KTempFile and KSaveFile

void  setError (int error)

setError

[protected]