\section{KTemp\-File Class Reference}
\label{classKTempFile}\index{KTempFile@{KTempFile}}
The KTemp\-File class creates and opens a unique file for temporary use.  


{\tt \#include $<$ktempfile.h$>$}

Collaboration diagram for KTemp\-File:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=224pt]{classKTempFile__coll__graph}
\end{center}
\end{figure}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
{\bf KTemp\-File} ({\bf QString} file\-Prefix=QString::null, {\bf QString} file\-Extension=QString::null, int mode=0600)
\begin{CompactList}\small\item\em Creates a temporary file with the name: . \item\end{CompactList}\item 
{\bf $\sim$KTemp\-File} ()
\begin{CompactList}\small\item\em The destructor closes the file. \item\end{CompactList}\item 
void {\bf set\-Auto\-Delete} (bool auto\-Delete)
\begin{CompactList}\small\item\em Turn automatic deletion on or off. \item\end{CompactList}\item 
int {\bf status} () const 
\begin{CompactList}\small\item\em Returns the status of the file based on errno. \item\end{CompactList}\item 
{\bf QString} {\bf name} () const 
\begin{CompactList}\small\item\em Returns the full path and name of the file. \item\end{CompactList}\item 
int {\bf handle} () const 
\begin{CompactList}\small\item\em An integer file descriptor open for writing to the file. \item\end{CompactList}\item 
FILE $\ast$ {\bf fstream} ()
\begin{CompactList}\small\item\em Returns the FILE$\ast$ of the temporary file. \item\end{CompactList}\item 
{\bf QText\-Stream} $\ast$ {\bf text\-Stream} ()
\begin{CompactList}\small\item\em Returns the {\bf QText\-Stream} for writing. \item\end{CompactList}\item 
{\bf QData\-Stream} $\ast$ {\bf data\-Stream} ()
\begin{CompactList}\small\item\em Returns a {\bf QData\-Stream} for writing. \item\end{CompactList}\item 
{\bf QFile} $\ast$ {\bf file} ()
\begin{CompactList}\small\item\em Returns a {\bf QFile}. \item\end{CompactList}\item 
void {\bf unlink} ()
\begin{CompactList}\small\item\em Unlinks the file from the directory. \item\end{CompactList}\item 
bool {\bf close} ()
\begin{CompactList}\small\item\em Closes the file. \item\end{CompactList}\end{CompactItemize}
\subsection*{Protected Member Functions}
\begin{CompactItemize}
\item 
{\bf KTemp\-File} (bool)
\begin{CompactList}\small\item\em Constructor used by {\bf KSave\-File}{\rm (p.\,\pageref{classKSaveFile})}. \item\end{CompactList}\item 
bool {\bf create} (const  {\bf QString} \&file\-Prefix, const  {\bf QString} \&file\-Extension, int mode)\label{classKTempFile_b1}

\item 
void {\bf set\-Error} (int error)\label{classKTempFile_b2}

\end{CompactItemize}
\subsection*{Friends}
\begin{CompactItemize}
\item 
class {\bf KSave\-File}\label{classKTempFile_n0}

\end{CompactItemize}


\subsection{Detailed Description}
The KTemp\-File 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.

{\bf KDE}{\rm (p.\,\pageref{namespaceKDE})} applications, however, shouldn't create files in /tmp in the first place but use the \char`\"{}tmp\char`\"{} resource instead. The standard KTemp\-File constructor will do that by default.

To create a temporary file that starts with a certain name in the \char`\"{}tmp\char`\"{} resource, one should use: KTemp\-File(locate\-Local(\char`\"{}tmp\char`\"{}, prefix), extension);

KTemp\-File does not create any missing directories, but {\bf locate\-Local()}{\rm (p.\,\pageref{kstandarddirs_8cpp_a8})} does.

See also {\bf KStandard\-Dirs}{\rm (p.\,\pageref{classKStandardDirs})}

\begin{Desc}
\item[Author:]Waldo Bastian $<${\tt bastian@kde.org}$>$ \end{Desc}




Definition at line 54 of file ktempfile.h.

\subsection{Constructor \& Destructor Documentation}
\index{KTempFile@{KTemp\-File}!KTempFile@{KTempFile}}
\index{KTempFile@{KTempFile}!KTempFile@{KTemp\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KTemp\-File::KTemp\-File ({\bf QString} {\em file\-Prefix} = QString::null, {\bf QString} {\em file\-Extension} = QString::null, int {\em mode} = 0600)}\label{classKTempFile_a0}


Creates a temporary file with the name: . 

The default {\tt file\-Prefix} is \char`\"{}\$KDEHOME/tmp-\$HOST/appname\char`\"{} The default {\tt file\-Extension} is \char`\"{}.tmp\char`\"{} \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em file\-Prefix}]the prefix of the file name, or QString::null for the default value \item[{\em the}]extension of the prefix, or QString::null for the default value \end{description}
\end{Desc}


Definition at line 58 of file ktempfile.cpp.

References KGlobal::instance(), and QString::is\-Empty().\index{KTempFile@{KTemp\-File}!~KTempFile@{$\sim$KTempFile}}
\index{~KTempFile@{$\sim$KTempFile}!KTempFile@{KTemp\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KTemp\-File::$\sim${\bf KTemp\-File} ()}\label{classKTempFile_a1}


The destructor closes the file. 

If auto\-Delete is enabled the file gets unlinked as well. 

Definition at line 123 of file ktempfile.cpp.

References close(), and unlink().\index{KTempFile@{KTemp\-File}!KTempFile@{KTempFile}}
\index{KTempFile@{KTempFile}!KTempFile@{KTemp\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KTemp\-File::KTemp\-File (bool)\hspace{0.3cm}{\tt  [protected]}}\label{classKTempFile_b0}


Constructor used by {\bf KSave\-File}{\rm (p.\,\pageref{classKSaveFile})}. 



Definition at line 77 of file ktempfile.cpp.

\subsection{Member Function Documentation}
\index{KTempFile@{KTemp\-File}!setAutoDelete@{setAutoDelete}}
\index{setAutoDelete@{setAutoDelete}!KTempFile@{KTemp\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KTemp\-File::set\-Auto\-Delete (bool {\em auto\-Delete})\hspace{0.3cm}{\tt  [inline]}}\label{classKTempFile_a2}


Turn automatic deletion on or off. 

Automatic deletion is off by default. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em auto\-Delete}]true to turn automatic deletion on \end{description}
\end{Desc}


Definition at line 85 of file ktempfile.h.\index{KTempFile@{KTemp\-File}!status@{status}}
\index{status@{status}!KTempFile@{KTemp\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int KTemp\-File::status () const}\label{classKTempFile_a3}


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. \begin{Desc}
\item[Returns:]the errno status, 0 means ok \end{Desc}


Definition at line 131 of file ktempfile.cpp.

Referenced by KSave\-File::status().\index{KTempFile@{KTemp\-File}!name@{name}}
\index{name@{name}!KTempFile@{KTemp\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QString} KTemp\-File::name () const}\label{classKTempFile_a4}


Returns the full path and name of the file. 

\begin{Desc}
\item[Returns:]The name of the file, or QString::null if opening the file has failed or the file has been unlinked \end{Desc}


Definition at line 137 of file ktempfile.cpp.

Referenced by KSave\-File::close(), and file().\index{KTempFile@{KTemp\-File}!handle@{handle}}
\index{handle@{handle}!KTempFile@{KTemp\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int KTemp\-File::handle () const}\label{classKTempFile_a5}


An integer file descriptor open for writing to the file. 

\begin{Desc}
\item[Returns:]The file descriptor, or a negative number if opening the file failed \end{Desc}


Definition at line 143 of file ktempfile.cpp.

Referenced by KSave\-File::handle().\index{KTempFile@{KTemp\-File}!fstream@{fstream}}
\index{fstream@{fstream}!KTempFile@{KTemp\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}FILE $\ast$ KTemp\-File::fstream ()}\label{classKTempFile_a6}


Returns the FILE$\ast$ of the temporary file. 

\begin{Desc}
\item[Returns:]FILE$\ast$ stream open for writing to the file, or 0 if opening the file failed \end{Desc}


Definition at line 149 of file ktempfile.cpp.

References QString::latin1().

Referenced by file(), and KSave\-File::fstream().\index{KTempFile@{KTemp\-File}!textStream@{textStream}}
\index{textStream@{textStream}!KTempFile@{KTemp\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QText\-Stream} $\ast$ KTemp\-File::text\-Stream ()}\label{classKTempFile_a7}


Returns the {\bf QText\-Stream} for writing. 

\begin{Desc}
\item[Returns:]{\bf QText\-Stream} open for writing to the file, or 0 if opening the file failed \end{Desc}


Definition at line 176 of file ktempfile.cpp.

References file().

Referenced by KSave\-File::text\-Stream().\index{KTempFile@{KTemp\-File}!dataStream@{dataStream}}
\index{dataStream@{dataStream}!KTempFile@{KTemp\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QData\-Stream} $\ast$ KTemp\-File::data\-Stream ()}\label{classKTempFile_a8}


Returns a {\bf QData\-Stream} for writing. 

\begin{Desc}
\item[Returns:]{\bf QData\-Stream} open for writing to the file, or 0 if opening the file failed \end{Desc}


Definition at line 186 of file ktempfile.cpp.

References file().

Referenced by KSave\-File::data\-Stream().\index{KTempFile@{KTemp\-File}!file@{file}}
\index{file@{file}!KTempFile@{KTemp\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QFile} $\ast$ KTemp\-File::file ()}\label{classKTempFile_a9}


Returns a {\bf QFile}. 

\begin{Desc}
\item[Returns:]A {\bf QFile} open for writing to the file, or 0 if opening the file failed. \end{Desc}


Definition at line 164 of file ktempfile.cpp.

References fstream(), name(), QFile::open(), and QFile::set\-Name().

Referenced by data\-Stream(), KSave\-File::file(), and text\-Stream().\index{KTempFile@{KTemp\-File}!unlink@{unlink}}
\index{unlink@{unlink}!KTempFile@{KTemp\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KTemp\-File::unlink ()}\label{classKTempFile_a10}


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::is\-Empty(), and QFile::remove().

Referenced by KSave\-File::abort(), KSave\-File::close(), and $\sim$KTemp\-File().\index{KTempFile@{KTemp\-File}!close@{close}}
\index{close@{close}!KTempFile@{KTemp\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KTemp\-File::close ()}\label{classKTempFile_a11}


Closes the file. 

See {\bf status}{\rm (p.\,\pageref{classKTempFile_a3})}() for details about errors. \begin{Desc}
\item[Returns:]true if successful, or false if an error has occured. \end{Desc}


Definition at line 204 of file ktempfile.cpp.

References QString::latin1().

Referenced by KSave\-File::abort(), KSave\-File::close(), and $\sim$KTemp\-File().

The documentation for this class was generated from the following files:\begin{CompactItemize}
\item 
ktempfile.h\item 
ktempfile.cpp\end{CompactItemize}
