.TH "KTempFile" kde3 "11 Jun 2005" "Version Version 3.4.1" "kdecore Library" \" -*- nroff -*-
.ad l
.nh
.SH NAME
KTempFile \- The KTempFile class creates and opens a unique file for temporary use.  

.PP
.SH SYNOPSIS
.br
.PP
\fC#include <ktempfile.h>\fP
.PP
.SS "Public Member Functions"

.in +1c
.ti -1c
.RI "\fBKTempFile\fP (\fBQString\fP filePrefix=QString::null, \fBQString\fP fileExtension=QString::null, int mode=0600)"
.br
.ti -1c
.RI "\fB~KTempFile\fP ()"
.br
.ti -1c
.RI "void \fBsetAutoDelete\fP (bool autoDelete)"
.br
.ti -1c
.RI "int \fBstatus\fP () const "
.br
.ti -1c
.RI "\fBQString\fP \fBname\fP () const "
.br
.ti -1c
.RI "int \fBhandle\fP () const "
.br
.ti -1c
.RI "FILE * \fBfstream\fP ()"
.br
.ti -1c
.RI "\fBQTextStream\fP * \fBtextStream\fP ()"
.br
.ti -1c
.RI "\fBQDataStream\fP * \fBdataStream\fP ()"
.br
.ti -1c
.RI "\fBQFile\fP * \fBfile\fP ()"
.br
.ti -1c
.RI "void \fBunlink\fP ()"
.br
.ti -1c
.RI "bool \fBsync\fP ()"
.br
.ti -1c
.RI "bool \fBclose\fP ()"
.br
.in -1c
.SS "Protected Member Functions"

.in +1c
.ti -1c
.RI "\fBKTempFile\fP (bool)"
.br
.ti -1c
.RI "bool \fBcreate\fP (const \fBQString\fP &filePrefix, const \fBQString\fP &fileExtension, int mode)"
.br
.ti -1c
.RI "void \fBsetError\fP (int error)"
.br
.in -1c
.SS "Friends"

.in +1c
.ti -1c
.RI "class \fBKSaveFile\fP"
.br
.in -1c
.SH "Detailed Description"
.PP 
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.
.PP
\fBKDE\fP 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.
.PP
To create a temporary file that starts with a certain name in the 'tmp' resource, one should use: KTempFile(locateLocal('tmp', prefix), extension);
.PP
KTempFile does not create any missing directories, but locateLocal() does.
.PP
See also \fBKStandardDirs\fP
.PP
\fBAuthor:\fP
.RS 4
Waldo Bastian <bastian@kde.org> 
.RE
.PP

.PP
Definition at line 55 of file ktempfile.h.
.SH "Constructor & Destructor Documentation"
.PP 
.SS "KTempFile::KTempFile (\fBQString\fP filePrefix = \fCQString::null\fP, \fBQString\fP fileExtension = \fCQString::null\fP, int mode = \fC0600\fP)"
.PP
Creates a temporary file with the name: <filePrefix><six letters><fileExtension>. 
.PP
The default \fCfilePrefix\fP is '$KDEHOME/tmp-$HOST/appname/' The default \fCfileExtension\fP is '.tmp' 
.PP
\fBParameters:\fP
.RS 4
\fIfilePrefix\fP the prefix of the file name, or QString::null for the default value 
.br
\fIfileExtension\fP the extension of the prefix, or QString::null for the default value 
.br
\fImode\fP the file permissions 
.RE
.PP

.PP
Definition at line 60 of file ktempfile.cpp.
.PP
References QString::isEmpty().
.SS "KTempFile::~\fBKTempFile\fP ()"
.PP
The destructor closes the file. 
.PP
If autoDelete is enabled the file gets unlinked as well. 
.PP
Definition at line 129 of file ktempfile.cpp.
.PP
References close(), and unlink().
.SS "KTempFile::KTempFile (bool)\fC [protected]\fP"
.PP
Constructor used by \fBKSaveFile\fP. 
.PP
Definition at line 79 of file ktempfile.cpp.
.SH "Member Function Documentation"
.PP 
.SS "void KTempFile::setAutoDelete (bool autoDelete)\fC [inline]\fP"
.PP
Turn automatic deletion on or off. 
.PP
Automatic deletion is off by default. 
.PP
\fBParameters:\fP
.RS 4
\fIautoDelete\fP true to turn automatic deletion on 
.RE
.PP

.PP
Definition at line 87 of file ktempfile.h.
.SS "int KTempFile::status () const"
.PP
Returns the status of the file based on errno. 
.PP
(see errno.h) 0 means OK.
.PP
You should check the status after object creation to check whether a file could be created in the first place.
.PP
You may check the status after closing the file to verify that the file has indeed been written correctly. 
.PP
\fBReturns:\fP
.RS 4
the errno status, 0 means ok 
.RE
.PP

.PP
Definition at line 137 of file ktempfile.cpp.
.SS "\fBQString\fP KTempFile::name () const"
.PP
Returns the full path and name of the file. 
.PP
Note that in most circumstances the file needs to be closed before you use it by name.
.PP
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.
.PP
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.
.PP
\fBReturns:\fP
.RS 4
The name of the file, or QString::null if opening the file has failed or the file has been unlinked already. 
.RE
.PP

.PP
Definition at line 143 of file ktempfile.cpp.
.PP
Referenced by KSaveFile::close(), and file().
.SS "int KTempFile::handle () const"
.PP
An integer file descriptor open for writing to the file. 
.PP
\fBReturns:\fP
.RS 4
The file descriptor, or a negative number if opening the file failed 
.RE
.PP

.PP
Definition at line 149 of file ktempfile.cpp.
.PP
Referenced by KSaveFile::close(), and KSaveFile::KSaveFile().
.SS "FILE * KTempFile::fstream ()"
.PP
Returns the FILE* of the temporary file. 
.PP
\fBReturns:\fP
.RS 4
FILE* stream open for writing to the file, or 0 if opening the file failed 
.RE
.PP

.PP
Definition at line 155 of file ktempfile.cpp.
.PP
References QString::latin1().
.PP
Referenced by file().
.SS "\fBQTextStream\fP * KTempFile::textStream ()"
.PP
Returns the \fBQTextStream\fP for writing. 
.PP
\fBReturns:\fP
.RS 4
\fBQTextStream\fP open for writing to the file, or 0 if opening the file failed 
.RE
.PP

.PP
Definition at line 182 of file ktempfile.cpp.
.PP
References file().
.SS "\fBQDataStream\fP * KTempFile::dataStream ()"
.PP
Returns a \fBQDataStream\fP for writing. 
.PP
\fBReturns:\fP
.RS 4
\fBQDataStream\fP open for writing to the file, or 0 if opening the file failed 
.RE
.PP

.PP
Definition at line 192 of file ktempfile.cpp.
.PP
References file().
.SS "\fBQFile\fP * KTempFile::file ()"
.PP
Returns a \fBQFile\fP. 
.PP
\fBReturns:\fP
.RS 4
A \fBQFile\fP open for writing to the file, or 0 if opening the file failed. 
.RE
.PP

.PP
Definition at line 170 of file ktempfile.cpp.
.PP
References fstream(), name(), QFile::open(), and QFile::setName().
.PP
Referenced by dataStream(), and textStream().
.SS "void KTempFile::unlink ()"
.PP
Unlinks the file from the directory. 
.PP
The file is deleted once the last reader/writer closes it. 
.PP
Definition at line 202 of file ktempfile.cpp.
.PP
References QString::isEmpty(), and QFile::remove().
.PP
Referenced by KSaveFile::abort(), KSaveFile::close(), and ~KTempFile().
.SS "bool KTempFile::sync ()"
.PP
Flushes file to disk (fsync). 
.PP
If you want to be as sure as possible that the file data has actually been physically stored on disk you need to call \fBsync()\fP.
.PP
See \fBstatus()\fP for details about errors. 
.PP
\fBReturns:\fP
.RS 4
true if successful, or false if an error has occurred. 
.RE
.PP
\fBSince:\fP
.RS 4
3.3 
.RE
.PP

.PP
Definition at line 216 of file ktempfile.cpp.
.PP
References QString::latin1().
.PP
Referenced by KSaveFile::close().
.SS "bool KTempFile::close ()"
.PP
Closes the file. 
.PP
See \fBstatus()\fP for details about errors. 
.PP
\fBReturns:\fP
.RS 4
true if successful, or false if an error has occurred. 
.RE
.PP

.PP
Definition at line 250 of file ktempfile.cpp.
.PP
References QString::latin1().
.PP
Referenced by KSaveFile::abort(), KSaveFile::close(), and ~KTempFile().

.SH "Author"
.PP 
Generated automatically by Doxygen for kdecore Library from the source code.
