summaryrefslogtreecommitdiff
path: root/qmake/tools/qfile.cpp
Unidiff
Diffstat (limited to 'qmake/tools/qfile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--qmake/tools/qfile.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/qmake/tools/qfile.cpp b/qmake/tools/qfile.cpp
index a578b49..c088b55 100644
--- a/qmake/tools/qfile.cpp
+++ b/qmake/tools/qfile.cpp
@@ -43,97 +43,97 @@
43#endif 43#endif
44 44
45// POSIX Large File Support redefines truncate -> truncate64 45// POSIX Large File Support redefines truncate -> truncate64
46#if defined(truncate) 46#if defined(truncate)
47# undef truncate 47# undef truncate
48#endif 48#endif
49 49
50#include "qfile.h" 50#include "qfile.h"
51 51
52 52
53extern bool qt_file_access( const QString& fn, int t ); 53extern bool qt_file_access( const QString& fn, int t );
54 54
55/*! 55/*!
56 \class QFile qfile.h 56 \class QFile qfile.h
57 \reentrant 57 \reentrant
58 \brief The QFile class is an I/O device that operates on files. 58 \brief The QFile class is an I/O device that operates on files.
59 59
60 \ingroup io 60 \ingroup io
61 \mainclass 61 \mainclass
62 62
63 QFile is an I/O device for reading and writing binary and text 63 QFile is an I/O device for reading and writing binary and text
64 files. A QFile may be used by itself or more conveniently with a 64 files. A QFile may be used by itself or more conveniently with a
65 QDataStream or QTextStream. 65 QDataStream or QTextStream.
66 66
67 The file name is usually passed in the constructor but can be 67 The file name is usually passed in the constructor but can be
68 changed with setName(). You can check for a file's existence with 68 changed with setName(). You can check for a file's existence with
69 exists() and remove a file with remove(). 69 exists() and remove a file with remove().
70 70
71 The file is opened with open(), closed with close() and flushed 71 The file is opened with open(), closed with close() and flushed
72 with flush(). Data is usually read and written using QDataStream 72 with flush(). Data is usually read and written using QDataStream
73 or QTextStream, but you can read with readBlock() and readLine() 73 or QTextStream, but you can read with readBlock() and readLine()
74 and write with writeBlock(). QFile also supports getch(), 74 and write with writeBlock(). QFile also supports getch(),
75 ungetch() and putch(). 75 ungetch() and putch().
76 76
77 The size of the file is returned by size(). You can get the 77 The size of the file is returned by size(). You can get the
78 current file position or move to a new file position using the 78 current file position or move to a new file position using the
79 at() functions. If you've reached the end of the file, atEnd() 79 at() functions. If you've reached the end of the file, atEnd()
80 returns TRUE. The file handle is returned by handle(). 80 returns TRUE. The file handle is returned by handle().
81 81
82 Here is a code fragment that uses QTextStream to read a text file 82 Here is a code fragment that uses QTextStream to read a text file
83 line by line. It prints each line with a line number. 83 line by line. It prints each line with a line number.
84 \code 84 \code
85 QStringList lines; 85 QStringList lines;
86 QFile file( "file.txt" ); 86 QFile file( "file.txt" );
87 if ( file.open( IO_ReadOnly ) ) { 87 if ( file.open( IO_ReadOnly ) ) {
88 QTextStream stream( &file ); 88 QTextStream stream( &file );
89 QString line; 89 QString line;
90 int i = 1; 90 int i = 1;
91 while ( !stream.eof() ) { 91 while ( !stream.atEnd() ) {
92 line = stream.readLine(); // line of text excluding '\n' 92 line = stream.readLine(); // line of text excluding '\n'
93 printf( "%3d: %s\n", i++, line.latin1() ); 93 printf( "%3d: %s\n", i++, line.latin1() );
94 lines += line; 94 lines += line;
95 } 95 }
96 file.close(); 96 file.close();
97 } 97 }
98 \endcode 98 \endcode
99 99
100 Writing text is just as easy. The following example shows how to 100 Writing text is just as easy. The following example shows how to
101 write the data we read into the string list from the previous 101 write the data we read into the string list from the previous
102 example: 102 example:
103 \code 103 \code
104 QFile file( "file.txt" ); 104 QFile file( "file.txt" );
105 if ( file.open( IO_WriteOnly ) ) { 105 if ( file.open( IO_WriteOnly ) ) {
106 QTextStream stream( &file ); 106 QTextStream stream( &file );
107 for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it ) 107 for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it )
108 stream << *it << "\n"; 108 stream << *it << "\n";
109 file.close(); 109 file.close();
110 } 110 }
111 \endcode 111 \endcode
112 112
113 The QFileInfo class holds detailed information about a file, such 113 The QFileInfo class holds detailed information about a file, such
114 as access permissions, file dates and file types. 114 as access permissions, file dates and file types.
115 115
116 The QDir class manages directories and lists of file names. 116 The QDir class manages directories and lists of file names.
117 117
118 Qt uses Unicode file names. If you want to do your own I/O on Unix 118 Qt uses Unicode file names. If you want to do your own I/O on Unix
119 systems you may want to use encodeName() (and decodeName()) to 119 systems you may want to use encodeName() (and decodeName()) to
120 convert the file name into the local encoding. 120 convert the file name into the local encoding.
121 121
122 \important readAll() 122 \important readAll()
123 123
124 \sa QDataStream, QTextStream 124 \sa QDataStream, QTextStream
125*/ 125*/
126 126
127/*! 127/*!
128 \fn Q_LONG QFile::writeBlock( const QByteArray& data ) 128 \fn Q_LONG QFile::writeBlock( const QByteArray& data )
129 129
130 \overload 130 \overload
131*/ 131*/
132 132
133 133
134/*! 134/*!
135 Constructs a QFile with no name. 135 Constructs a QFile with no name.
136*/ 136*/
137 137
138QFile::QFile() 138QFile::QFile()
139{ 139{
@@ -245,96 +245,97 @@ bool QFile::exists() const
245bool QFile::exists( const QString &fileName ) 245bool QFile::exists( const QString &fileName )
246{ 246{
247 return qt_file_access( fileName, F_OK ); 247 return qt_file_access( fileName, F_OK );
248} 248}
249 249
250 250
251/*! 251/*!
252 Removes the file specified by the file name currently set. Returns 252 Removes the file specified by the file name currently set. Returns
253 TRUE if successful; otherwise returns FALSE. 253 TRUE if successful; otherwise returns FALSE.
254 254
255 The file is closed before it is removed. 255 The file is closed before it is removed.
256*/ 256*/
257 257
258bool QFile::remove() 258bool QFile::remove()
259{ 259{
260 close(); 260 close();
261 return remove( fn ); 261 return remove( fn );
262} 262}
263 263
264#if defined(Q_OS_MAC) || defined(Q_OS_MSDOS) || defined(Q_OS_WIN32) || defined(Q_OS_OS2) 264#if defined(Q_OS_MAC) || defined(Q_OS_MSDOS) || defined(Q_OS_WIN32) || defined(Q_OS_OS2)
265 # define HAS_TEXT_FILEMODE // has translate/text filemode 265 # define HAS_TEXT_FILEMODE // has translate/text filemode
266#endif 266#endif
267#if defined(O_NONBLOCK) 267#if defined(O_NONBLOCK)
268# define HAS_ASYNC_FILEMODE 268# define HAS_ASYNC_FILEMODE
269# define OPEN_ASYNC O_NONBLOCK 269# define OPEN_ASYNC O_NONBLOCK
270#elif defined(O_NDELAY) 270#elif defined(O_NDELAY)
271# define HAS_ASYNC_FILEMODE 271# define HAS_ASYNC_FILEMODE
272# define OPEN_ASYNC O_NDELAY 272# define OPEN_ASYNC O_NDELAY
273#endif 273#endif
274 274
275/*! 275/*!
276 Flushes the file buffer to the disk. 276 Flushes the file buffer to the disk.
277 277
278 close() also flushes the file buffer. 278 close() also flushes the file buffer.
279*/ 279*/
280 280
281void QFile::flush() 281void QFile::flush()
282{ 282{
283 if ( isOpen() && fh ) // can only flush open/buffered 283 if ( isOpen() && fh ) // can only flush open/buffered
284 fflush( fh ); // file 284 fflush( fh ); // file
285} 285}
286 286
287/*! \reimp 287/*! \reimp
288 \fn QIODevice::Offset QFile::at() const 288 \fn QIODevice::Offset QFile::at() const
289*/ 289*/
290 290
291/*! 291/*!
292 Returns TRUE if the end of file has been reached; otherwise returns FALSE. 292 Returns TRUE if the end of file has been reached; otherwise returns FALSE.
293 If QFile has not been open()'d, then the behavior is undefined.
293 294
294 \sa size() 295 \sa size()
295*/ 296*/
296 297
297bool QFile::atEnd() const 298bool QFile::atEnd() const
298{ 299{
299 if ( !isOpen() ) { 300 if ( !isOpen() ) {
300#if defined(QT_CHECK_STATE) 301#if defined(QT_CHECK_STATE)
301 qWarning( "QFile::atEnd: File is not open" ); 302 qWarning( "QFile::atEnd: File is not open" );
302#endif 303#endif
303 return FALSE; 304 return FALSE;
304 } 305 }
305 if ( isDirectAccess() && !isTranslated() ) { 306 if ( isDirectAccess() && !isTranslated() ) {
306 if ( at() < length ) 307 if ( at() < length )
307 return FALSE; 308 return FALSE;
308 } 309 }
309 return QIODevice::atEnd(); 310 return QIODevice::atEnd();
310} 311}
311 312
312/*! 313/*!
313 Reads a line of text. 314 Reads a line of text.
314 315
315 Reads bytes from the file into the char* \a p, until end-of-line 316 Reads bytes from the file into the char* \a p, until end-of-line
316 or \a maxlen bytes have been read, whichever occurs first. Returns 317 or \a maxlen bytes have been read, whichever occurs first. Returns
317 the number of bytes read, or -1 if there was an error. Any 318 the number of bytes read, or -1 if there was an error. Any
318 terminating newline is not stripped. 319 terminating newline is not stripped.
319 320
320 This function is only efficient for buffered files. Avoid 321 This function is only efficient for buffered files. Avoid
321 readLine() for files that have been opened with the \c IO_Raw 322 readLine() for files that have been opened with the \c IO_Raw
322 flag. 323 flag.
323 324
324 \sa readBlock(), QTextStream::readLine() 325 \sa readBlock(), QTextStream::readLine()
325*/ 326*/
326 327
327Q_LONG QFile::readLine( char *p, Q_ULONG maxlen ) 328Q_LONG QFile::readLine( char *p, Q_ULONG maxlen )
328{ 329{
329 if ( maxlen == 0 ) // application bug? 330 if ( maxlen == 0 ) // application bug?
330 return 0; 331 return 0;
331#if defined(QT_CHECK_STATE) 332#if defined(QT_CHECK_STATE)
332 Q_CHECK_PTR( p ); 333 Q_CHECK_PTR( p );
333 if ( !isOpen() ) { // file not open 334 if ( !isOpen() ) { // file not open
334 qWarning( "QFile::readLine: File not open" ); 335 qWarning( "QFile::readLine: File not open" );
335 return -1; 336 return -1;
336 } 337 }
337 if ( !isReadable() ) { // reading not permitted 338 if ( !isReadable() ) { // reading not permitted
338 qWarning( "QFile::readLine: Read operation not permitted" ); 339 qWarning( "QFile::readLine: Read operation not permitted" );
339 return -1; 340 return -1;
340 } 341 }