Go to the documentation of this file.
40#define _PATH_TMP "/tmp"
43#include <QtCore/QCharRef>
44#include <QtCore/QDate>
45#include <QtCore/QFile>
46#include <QtCore/QDataStream>
47#include <QtCore/QTextIStream>
56class K3TempFile::Private
60#define mError d->_Error
62#define mTmpName d->_TmpName
66#define mStream d->_Stream
69 QTextStream *_TextStream;
70#define mTextStream d->_TextStream
71 QDataStream *_DataStream;
72#define mDataStream d->_DataStream
76#define bAutoDelete d->_AutoDelete
80 const QString& fileExtension,
int mode)
91 QString extension = fileExtension;
92 QString
prefix = filePrefix;
93 if (extension.isEmpty())
94 extension = QLatin1String(
".tmp");
97 prefix = KStandardDirs::locateLocal(
"tmp", KGlobal::mainComponent().componentName());
121 QByteArray ext = QFile::encodeName(fileExtension);
122 QByteArray nme = QFile::encodeName(filePrefix) +
"XXXXXX" + ext;
123 if((
mFd = mkstemps(nme.data(), ext.length())) < 0)
126 nme = QFile::encodeName(filePrefix) +
"XXXXXX" + ext;
127 kWarning() <<
"K3TempFile: Error trying to create " << nme <<
": " << strerror(errno);
136 mode_t umsk = umask(tmp);
138 fchmod(
mFd, mode&(~umsk));
144 fchown(
mFd, getuid(), getgid());
148 fcntl(
mFd, F_SETFD, FD_CLOEXEC);
183 if (
mFd < 0)
return 0;
188 kWarning() <<
"K3TempFile: Error trying to open " <<
mTmpName <<
": " << strerror(errno);
210 if ( !
file() )
return 0;
220 if ( !
file() )
return 0;
234#if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
235#define FDATASYNC fdatasync
237#define FDATASYNC fsync
250 while ((result == -1) && (errno == EINTR));
254 kWarning() <<
"K3TempFile: Error trying to flush " <<
mTmpName <<
": " << strerror(errno);
261 if( qgetenv(
"KDE_EXTRA_FSYNC" ) ==
"1" )
266 kWarning() <<
"K3TempFile: Error trying to sync " <<
mTmpName <<
": " << strerror(errno);
295 kWarning() <<
"K3TempFile: Error trying to close " <<
mTmpName <<
": " << strerror(errno);
306 kWarning() <<
"K3TempFile: Error trying to close " <<
mTmpName <<
": " << strerror(errno);
FILE * fstream()
Returns the FILE* of the temporary file.
K3TempFile(const QString &filePrefix=QString(), const QString &fileExtension=QString(), int mode=0600)
Creates a temporary file with the name: <filePrefix><six letters><fileExtension>
QTextStream * textStream()
Returns the QTextStream for writing.
QDataStream * dataStream()
Returns a QDataStream for writing.
QString name() const
Returns the full path and name of the file.
bool close()
Closes the file.
void setAutoDelete(bool autoDelete)
Turn automatic deletion on or off.
bool create(const QString &filePrefix, const QString &fileExtension, int mode)
Create function used internally by K3TempFile and KSaveFile.
QFile * file()
Returns a QFile.
bool sync()
Flushes file to disk (fsync).
void unlink()
Unlinks the file from the directory.
int handle() const
An integer file descriptor open for writing to the file.
void setError(int error)
Set the error value (for subclasses).
~K3TempFile()
The destructor closes the file.
int status() const
Returns the status of the file based on errno.
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 17 2025 00:00:00 by
doxygen 1.13.2 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.