summaryrefslogtreecommitdiff
path: root/qmake/tools/qfile_unix.cpp
Unidiff
Diffstat (limited to 'qmake/tools/qfile_unix.cpp') (more/less context) (show whitespace changes)
-rw-r--r--qmake/tools/qfile_unix.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/qmake/tools/qfile_unix.cpp b/qmake/tools/qfile_unix.cpp
index 2d5a856..460bf06 100644
--- a/qmake/tools/qfile_unix.cpp
+++ b/qmake/tools/qfile_unix.cpp
@@ -426,29 +426,32 @@ bool QFile::open( int m, int f )
426 } 426 }
427 return TRUE; 427 return TRUE;
428} 428}
429 429
430/*! 430/*!
431 Returns the file size. 431 Returns the file size.
432 \sa at() 432 \sa at()
433*/ 433*/
434 434
435QIODevice::Offset QFile::size() const 435QIODevice::Offset QFile::size() const
436{ 436{
437 struct stat st; 437 struct stat st;
438 int ret = 0;
438 if ( isOpen() ) { 439 if ( isOpen() ) {
439 ::fstat( fh ? fileno(fh) : fd, &st ); 440 ret = ::fstat( fh ? fileno(fh) : fd, &st );
440 } else { 441 } else {
441 ::stat( QFile::encodeName(fn), &st ); 442 ret = ::stat( QFile::encodeName(fn), &st );
442 } 443 }
444 if ( ret == -1 )
445 return 0;
443#if defined(QT_LARGEFILE_SUPPORT) && !defined(QT_ABI_64BITOFFSET) 446#if defined(QT_LARGEFILE_SUPPORT) && !defined(QT_ABI_64BITOFFSET)
444 return (uint)st.st_size > UINT_MAX ? UINT_MAX : (QIODevice::Offset)st.st_size; 447 return (uint)st.st_size > UINT_MAX ? UINT_MAX : (QIODevice::Offset)st.st_size;
445#else 448#else
446 return st.st_size; 449 return st.st_size;
447#endif 450#endif
448} 451}
449 452
450 453
451/*! 454/*!
452 \overload 455 \overload
453 456
454 Sets the file index to \a pos. Returns TRUE if successful; 457 Sets the file index to \a pos. Returns TRUE if successful;
@@ -529,25 +532,25 @@ Q_LONG QFile::readBlock( char *p, Q_ULONG len )
529 return -1; 532 return -1;
530 } 533 }
531 if ( !isReadable() ) { 534 if ( !isReadable() ) {
532 qWarning( "QFile::readBlock: Read operation not permitted" ); 535 qWarning( "QFile::readBlock: Read operation not permitted" );
533 return -1; 536 return -1;
534 } 537 }
535#endif 538#endif
536 Q_ULONG nread = 0; // number of bytes read 539 Q_ULONG nread = 0; // number of bytes read
537 if ( !ungetchBuffer.isEmpty() ) { 540 if ( !ungetchBuffer.isEmpty() ) {
538 // need to add these to the returned string. 541 // need to add these to the returned string.
539 uint l = ungetchBuffer.length(); 542 uint l = ungetchBuffer.length();
540 while( nread < l ) { 543 while( nread < l ) {
541 *p = ungetchBuffer[ l - nread - 1 ]; 544 *p = ungetchBuffer.at( l - nread - 1 );
542 p++; 545 p++;
543 nread++; 546 nread++;
544 } 547 }
545 ungetchBuffer.truncate( l - nread ); 548 ungetchBuffer.truncate( l - nread );
546 } 549 }
547 550
548 if ( nread < len ) { 551 if ( nread < len ) {
549 if ( isRaw() ) { // raw file 552 if ( isRaw() ) { // raw file
550 nread += ::read( fd, p, len-nread ); 553 nread += ::read( fd, p, len-nread );
551 if ( len && nread <= 0 ) { 554 if ( len && nread <= 0 ) {
552 nread = 0; 555 nread = 0;
553 setStatus(IO_ReadError); 556 setStatus(IO_ReadError);
@@ -620,25 +623,27 @@ Q_LONG QFile::writeBlock( const char *p, Q_ULONG len )
620 if ( !isSequentialAccess() ) 623 if ( !isSequentialAccess() )
621 ioIndex += nwritten; 624 ioIndex += nwritten;
622 } 625 }
623 if ( ioIndex > length ) // update file length 626 if ( ioIndex > length ) // update file length
624 length = ioIndex; 627 length = ioIndex;
625 return nwritten; 628 return nwritten;
626} 629}
627 630
628/*! 631/*!
629 Returns the file handle of the file. 632 Returns the file handle of the file.
630 633
631 This is a small positive integer, suitable for use with C library 634 This is a small positive integer, suitable for use with C library
632 functions such as fdopen() and fcntl(), as well as with QSocketNotifier. 635 functions such as fdopen() and fcntl(). On systems that use file
636 descriptors for sockets (ie. Unix systems, but not Windows) the handle
637 can be used with QSocketNotifier as well.
633 638
634 If the file is not open or there is an error, handle() returns -1. 639 If the file is not open or there is an error, handle() returns -1.
635 640
636 \sa QSocketNotifier 641 \sa QSocketNotifier
637*/ 642*/
638 643
639int QFile::handle() const 644int QFile::handle() const
640{ 645{
641 if ( !isOpen() ) 646 if ( !isOpen() )
642 return -1; 647 return -1;
643 else if ( fh ) 648 else if ( fh )
644 return fileno( fh ); 649 return fileno( fh );