src/corelib/io/qfile.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
  1018     When a QFile is opened using this function, close() does not actually
  1018     When a QFile is opened using this function, close() does not actually
  1019     close the file, but only flushes it.
  1019     close the file, but only flushes it.
  1020 
  1020 
  1021     \bold{Warning:}
  1021     \bold{Warning:}
  1022     \list 1
  1022     \list 1
  1023         \o If \a fh is \c stdin, \c stdout, or \c stderr, you may not be able
  1023         \o If \a fh does not refer to a regular file, e.g., it is \c stdin,
  1024            to seek(). See QIODevice::isSequential() for more information.
  1024            \c stdout, or \c stderr, you may not be able to seek(). size()
       
  1025            returns \c 0 in those cases. See QIODevice::isSequential() for
       
  1026            more information.
  1025         \o Since this function opens the file without specifying the file name,
  1027         \o Since this function opens the file without specifying the file name,
  1026            you cannot use this QFile with a QFileInfo.
  1028            you cannot use this QFile with a QFileInfo.
  1027     \endlist
  1029     \endlist
  1028 
  1030 
  1029     \note For Windows CE you may not be able to call seek() and resize().
  1031     \note For Windows CE you may not be able to call resize().
  1030     Also, size() is set to \c 0.
       
  1031 
  1032 
  1032     \sa close(), {qmake Variable Reference#CONFIG}{qmake Variable Reference}
  1033     \sa close(), {qmake Variable Reference#CONFIG}{qmake Variable Reference}
  1033 
  1034 
  1034     \bold{Note for the Windows Platform}
  1035     \bold{Note for the Windows Platform}
  1035 
  1036 
  1062     if(d->openExternalFile(mode, fh)) {
  1063     if(d->openExternalFile(mode, fh)) {
  1063         QIODevice::open(mode);
  1064         QIODevice::open(mode);
  1064         if (mode & Append) {
  1065         if (mode & Append) {
  1065             seek(size());
  1066             seek(size());
  1066         } else {
  1067         } else {
  1067             long pos = ftell(fh);
  1068             qint64 pos = (qint64)QT_FTELL(fh);
  1068             if (pos != -1)
  1069             if (pos != -1)
  1069                 seek(pos);
  1070                 seek(pos);
  1070         }
  1071         }
  1071         return true;
  1072         return true;
  1072     }
  1073     }
  1079 */
  1080 */
  1080 
  1081 
  1081 /*!
  1082 /*!
  1082     \overload
  1083     \overload
  1083 
  1084 
  1084     Opens the existing file descripter \a fd in the given \a mode.
  1085     Opens the existing file descriptor \a fd in the given \a mode.
  1085     Returns true if successful; otherwise returns false.
  1086     Returns true if successful; otherwise returns false.
  1086 
  1087 
  1087     When a QFile is opened using this function, close() does not
  1088     When a QFile is opened using this function, close() does not
  1088     actually close the file.
  1089     actually close the file.
  1089 
  1090 
  1090     The QFile that is opened using this function is automatically set
  1091     The QFile that is opened using this function is automatically set
  1091     to be in raw mode; this means that the file input/output functions
  1092     to be in raw mode; this means that the file input/output functions
  1092     are slow. If you run into performance issues, you should try to
  1093     are slow. If you run into performance issues, you should try to
  1093     use one of the other open functions.
  1094     use one of the other open functions.
  1094 
  1095 
  1095     \warning If \a fd is 0 (\c stdin), 1 (\c stdout), or 2 (\c
  1096     \warning If \a fd is not a regular file, e.g, it is 0 (\c stdin),
  1096     stderr), you may not be able to seek(). size() is set to \c
  1097     1 (\c stdout), or 2 (\c stderr), you may not be able to seek(). In
  1097     LLONG_MAX (in \c <climits>).
  1098     those cases, size() returns \c 0.  See QIODevice::isSequential()
       
  1099     for more information.
  1098 
  1100 
  1099     \warning For Windows CE you may not be able to call seek(), setSize(),
  1101     \warning For Windows CE you may not be able to call seek(), setSize(),
  1100     fileTime(). size() is set to \c 0.
  1102     fileTime(). size() returns \c 0.
  1101 
  1103 
  1102     \warning Since this function opens the file without specifying the file name,
  1104     \warning Since this function opens the file without specifying the file name,
  1103              you cannot use this QFile with a QFileInfo.
  1105              you cannot use this QFile with a QFileInfo.
  1104 
  1106 
  1105     \sa close()
  1107     \sa close()
  1118         qWarning("QFile::open: File access not specified");
  1120         qWarning("QFile::open: File access not specified");
  1119         return false;
  1121         return false;
  1120     }
  1122     }
  1121     if(d->openExternalFile(mode, fd)) {
  1123     if(d->openExternalFile(mode, fd)) {
  1122         QIODevice::open(mode);
  1124         QIODevice::open(mode);
  1123         if (mode & Append)
  1125         if (mode & Append) {
  1124             seek(size());
  1126             seek(size());
       
  1127         } else {
       
  1128             qint64 pos = (qint64)QT_LSEEK(fd, QT_OFF_T(0), SEEK_CUR);
       
  1129             if (pos != -1)
       
  1130                 seek(pos);
       
  1131         }
  1125         return true;
  1132         return true;
  1126     }
  1133     }
  1127     return false;
  1134     return false;
  1128 }
  1135 }
  1129 
  1136 
  1330     return QFile(fileName).setPermissions(permissions);
  1337     return QFile(fileName).setPermissions(permissions);
  1331 }
  1338 }
  1332 
  1339 
  1333 static inline qint64 _qfile_writeData(QAbstractFileEngine *engine, QRingBuffer *buffer)
  1340 static inline qint64 _qfile_writeData(QAbstractFileEngine *engine, QRingBuffer *buffer)
  1334 {
  1341 {
  1335     qint64 ret = engine->write(buffer->readPointer(), buffer->size());
  1342     qint64 ret = engine->write(buffer->readPointer(), buffer->nextDataBlockSize());
  1336     if (ret > 0)
  1343     if (ret > 0)
  1337         buffer->free(ret);
  1344         buffer->free(ret);
  1338     return ret;
  1345     return ret;
  1339 }
  1346 }
  1340 
  1347