Qt 4.8
Functions
qfsfileengine_unix.cpp File Reference
#include "qplatformdefs.h"
#include "qabstractfileengine.h"
#include "private/qfsfileengine_p.h"
#include "private/qcore_unix_p.h"
#include "qfilesystementry_p.h"
#include "qfilesystemengine_p.h"
#include "qfile.h"
#include "qdir.h"
#include "qdatetime.h"
#include "qvarlengtharray.h"
#include <sys/mman.h>
#include <stdlib.h>
#include <limits.h>
#include <errno.h>
#include <private/qcore_mac_p.h>

Go to the source code of this file.

Functions

static QByteArray openModeToFopenMode (QIODevice::OpenMode flags, const QFileSystemEntry &fileEntry, QFileSystemMetaData &metaData)
 Returns the stdlib open string corresponding to a QIODevice::OpenMode. More...
 
static int openModeToOpenFlags (QIODevice::OpenMode mode)
 Returns the stdio open flags corresponding to a QIODevice::OpenMode. More...
 
static bool setCloseOnExec (int fd)
 Sets the file descriptor to close on exec. More...
 

Function Documentation

◆ openModeToFopenMode()

static QByteArray openModeToFopenMode ( QIODevice::OpenMode  flags,
const QFileSystemEntry fileEntry,
QFileSystemMetaData metaData 
)
inlinestatic

Returns the stdlib open string corresponding to a QIODevice::OpenMode.

Warning
This function is not part of the public interface.

Definition at line 97 of file qfsfileengine_unix.cpp.

Referenced by QFSFileEnginePrivate::nativeOpen().

99 {
100  QByteArray mode;
101  if ((flags & QIODevice::ReadOnly) && !(flags & QIODevice::Truncate)) {
102  mode = "rb";
103  if (flags & QIODevice::WriteOnly) {
105  if (!fileEntry.isEmpty()
107  && metaData.isFile()) {
108  mode += '+';
109  } else {
110  mode = "wb+";
111  }
112  }
113  } else if (flags & QIODevice::WriteOnly) {
114  mode = "wb";
115  if (flags & QIODevice::ReadOnly)
116  mode += '+';
117  }
118  if (flags & QIODevice::Append) {
119  mode = "ab";
120  if (flags & QIODevice::ReadOnly)
121  mode += '+';
122  }
123 
124 #if defined(__GLIBC__) && (__GLIBC__ * 0x100 + __GLIBC_MINOR__) >= 0x0207
125  // must be glibc >= 2.7
126  mode += 'e';
127 #endif
128 
129  return mode;
130 }
static bool fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void clearFlags(MetaDataFlags flags=AllMetaDataFlags)

◆ openModeToOpenFlags()

static int openModeToOpenFlags ( QIODevice::OpenMode  mode)
inlinestatic

Returns the stdio open flags corresponding to a QIODevice::OpenMode.

Warning
This function is not part of the public interface.

Definition at line 141 of file qfsfileengine_unix.cpp.

Referenced by QFSFileEnginePrivate::nativeHandle(), and QFSFileEnginePrivate::nativeOpen().

142 {
143  int oflags = QT_OPEN_RDONLY;
144 #ifdef QT_LARGEFILE_SUPPORT
145  oflags |= QT_OPEN_LARGEFILE;
146 #endif
147 
148  if ((mode & QFile::ReadWrite) == QFile::ReadWrite) {
149  oflags = QT_OPEN_RDWR | QT_OPEN_CREAT;
150  } else if (mode & QFile::WriteOnly) {
151  oflags = QT_OPEN_WRONLY | QT_OPEN_CREAT;
152  }
153 
154  if (mode & QFile::Append) {
155  oflags |= QT_OPEN_APPEND;
156  } else if (mode & QFile::WriteOnly) {
157  if ((mode & QFile::Truncate) || !(mode & QFile::ReadOnly))
158  oflags |= QT_OPEN_TRUNC;
159  }
160 
161  return oflags;
162 }

◆ setCloseOnExec()

static bool setCloseOnExec ( int  fd)
inlinestatic

Sets the file descriptor to close on exec.

Warning
This function is not part of the public interface.

That is, the file descriptor is not inherited by child processes.

Definition at line 174 of file qfsfileengine_unix.cpp.

Referenced by QFSFileEnginePrivate::nativeOpen().

175 {
176  return fd != -1 && fcntl(fd, F_SETFD, FD_CLOEXEC) != -1;
177 }
int fcntl(int, int,...)