.TH "KTempFile" 3 "28 Jan 2004" "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
.RI "\fICreates a temporary file with the name: . \fP"
.ti -1c
.RI "\fB~KTempFile\fP ()"
.br
.RI "\fIThe destructor closes the file. \fP"
.ti -1c
.RI "void \fBsetAutoDelete\fP (bool autoDelete)"
.br
.RI "\fITurn automatic deletion on or off. \fP"
.ti -1c
.RI "int \fBstatus\fP () const "
.br
.RI "\fIReturns the status of the file based on errno. \fP"
.ti -1c
.RI "\fBQString\fP \fBname\fP () const "
.br
.RI "\fIReturns the full path and name of the file. \fP"
.ti -1c
.RI "int \fBhandle\fP () const "
.br
.RI "\fIAn integer file descriptor open for writing to the file. \fP"
.ti -1c
.RI "FILE * \fBfstream\fP ()"
.br
.RI "\fIReturns the FILE* of the temporary file. \fP"
.ti -1c
.RI "\fBQTextStream\fP * \fBtextStream\fP ()"
.br
.RI "\fIReturns the \fBQTextStream\fP for writing. \fP"
.ti -1c
.RI "\fBQDataStream\fP * \fBdataStream\fP ()"
.br
.RI "\fIReturns a \fBQDataStream\fP for writing. \fP"
.ti -1c
.RI "\fBQFile\fP * \fBfile\fP ()"
.br
.RI "\fIReturns a \fBQFile\fP. \fP"
.ti -1c
.RI "void \fBunlink\fP ()"
.br
.RI "\fIUnlinks the file from the directory. \fP"
.ti -1c
.RI "bool \fBclose\fP ()"
.br
.RI "\fICloses the file. \fP"
.in -1c
.SS "Protected Member Functions"

.in +1c
.ti -1c
.RI "\fBKTempFile\fP (bool)"
.br
.RI "\fIConstructor used by \fBKSaveFile\fP. \fP"
.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 \fBlocateLocal()\fP does.
.PP
See also \fBKStandardDirs\fP
.PP
\fBAuthor:\fP
.RS 4
Waldo Bastian <bastian@kde.org> 
.RE
.PP

.PP
Definition at line 54 of file ktempfile.h.
.SH "Constructor & Destructor Documentation"
.PP 
.SS "KTempFile::KTempFile (\fBQString\fP filePrefix = QString::null, \fBQString\fP fileExtension = QString::null, int mode = 0600)"
.PP
Creates a temporary file with the name: . 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
\fIthe\fP extension of the prefix, or QString::null for the default value 
.RE
.PP
Definition at line 58 of file ktempfile.cpp.
.PP
References KGlobal::instance(), and QString::isEmpty().
.SS "KTempFile::~\fBKTempFile\fP ()"
.PP
The destructor closes the file. If autoDelete is enabled the file gets unlinked as well. Definition at line 123 of file ktempfile.cpp.
.PP
References close(), and unlink().
.SS "KTempFile::KTempFile (bool)\fC [protected]\fP"
.PP
Constructor used by \fBKSaveFile\fP. Definition at line 77 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. Automatic deletion is off by default. 
.PP
\fBParameters:\fP
.RS 4
\fIautoDelete\fP true to turn automatic deletion on 
.RE
.PP
Definition at line 85 of file ktempfile.h.
.SS "int KTempFile::status () const"
.PP
Returns the status of the file based on errno. (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
Definition at line 131 of file ktempfile.cpp.
.PP
Referenced by KSaveFile::status().
.SS "\fBQString\fP KTempFile::name () const"
.PP
Returns the full path and name of the file. \fBReturns:\fP
.RS 4
The name of the file, or QString::null if opening the file has failed or the file has been unlinked 
.RE
.PP
Definition at line 137 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. \fBReturns:\fP
.RS 4
The file descriptor, or a negative number if opening the file failed 
.RE
.PP
Definition at line 143 of file ktempfile.cpp.
.PP
Referenced by KSaveFile::handle().
.SS "FILE * KTempFile::fstream ()"
.PP
Returns the FILE* of the temporary file. \fBReturns:\fP
.RS 4
FILE* stream open for writing to the file, or 0 if opening the file failed 
.RE
.PP
Definition at line 149 of file ktempfile.cpp.
.PP
References QString::latin1().
.PP
Referenced by file(), and KSaveFile::fstream().
.SS "\fBQTextStream\fP * KTempFile::textStream ()"
.PP
Returns the \fBQTextStream\fP for writing. \fBReturns:\fP
.RS 4
\fBQTextStream\fP open for writing to the file, or 0 if opening the file failed 
.RE
.PP
Definition at line 176 of file ktempfile.cpp.
.PP
References file().
.PP
Referenced by KSaveFile::textStream().
.SS "\fBQDataStream\fP * KTempFile::dataStream ()"
.PP
Returns a \fBQDataStream\fP for writing. \fBReturns:\fP
.RS 4
\fBQDataStream\fP open for writing to the file, or 0 if opening the file failed 
.RE
.PP
Definition at line 186 of file ktempfile.cpp.
.PP
References file().
.PP
Referenced by KSaveFile::dataStream().
.SS "\fBQFile\fP * KTempFile::file ()"
.PP
Returns a \fBQFile\fP. \fBReturns:\fP
.RS 4
A \fBQFile\fP open for writing to the file, or 0 if opening the file failed. 
.RE
.PP
Definition at line 164 of file ktempfile.cpp.
.PP
References fstream(), name(), QFile::open(), and QFile::setName().
.PP
Referenced by dataStream(), KSaveFile::file(), and textStream().
.SS "void KTempFile::unlink ()"
.PP
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.
.PP
References QString::isEmpty(), and QFile::remove().
.PP
Referenced by KSaveFile::abort(), KSaveFile::close(), and ~KTempFile().
.SS "bool KTempFile::close ()"
.PP
Closes the file. See \fBstatus\fP() for details about errors. 
.PP
\fBReturns:\fP
.RS 4
true if successful, or false if an error has occured. 
.RE
.PP
Definition at line 204 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.
