Blame qtools/qfile.cpp

Packit Service 50c9f2
/****************************************************************************
Packit Service 50c9f2
** 
Packit Service 50c9f2
**
Packit Service 50c9f2
** Implementation of QFile class
Packit Service 50c9f2
**
Packit Service 50c9f2
** Created : 930812
Packit Service 50c9f2
**
Packit Service 50c9f2
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file is part of the tools module of the Qt GUI Toolkit.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file may be distributed under the terms of the Q Public License
Packit Service 50c9f2
** as defined by Trolltech AS of Norway and appearing in the file
Packit Service 50c9f2
** LICENSE.QPL included in the packaging of this file.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file may be distributed and/or modified under the terms of the
Packit Service 50c9f2
** GNU General Public License version 2 as published by the Free Software
Packit Service 50c9f2
** Foundation and appearing in the file LICENSE.GPL included in the
Packit Service 50c9f2
** packaging of this file.
Packit Service 50c9f2
**
Packit Service 50c9f2
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
Packit Service 50c9f2
** licenses may use this file in accordance with the Qt Commercial License
Packit Service 50c9f2
** Agreement provided with the Software.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
Packit Service 50c9f2
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Packit Service 50c9f2
**
Packit Service 50c9f2
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
Packit Service 50c9f2
**   information about Qt Commercial License Agreements.
Packit Service 50c9f2
** See http://www.trolltech.com/qpl/ for QPL licensing information.
Packit Service 50c9f2
** See http://www.trolltech.com/gpl/ for GPL licensing information.
Packit Service 50c9f2
**
Packit Service 50c9f2
** Contact info@trolltech.com if any conditions of this licensing are
Packit Service 50c9f2
** not clear to you.
Packit Service 50c9f2
**
Packit Service 50c9f2
**********************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
#include "qglobal.h"
Packit Service 50c9f2
#if defined(_OS_WIN32_)
Packit Service 50c9f2
#ifdef UNICODE
Packit Service 50c9f2
#ifndef _UNICODE
Packit Service 50c9f2
#define _UNICODE
Packit Service 50c9f2
#endif
Packit Service 50c9f2
#endif
Packit Service 50c9f2
#endif
Packit Service 50c9f2
Packit Service 50c9f2
#include "qfile.h"
Packit Service 50c9f2
#include "qfiledefs_p.h"
Packit Service 50c9f2
Packit Service 50c9f2
extern bool qt_file_access( const QString& fn, int t );
Packit Service 50c9f2
Packit Service 50c9f2
// NOT REVISED
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \class QFile qfile.h
Packit Service 50c9f2
  \brief The QFile class is an I/O device that operates on files.
Packit Service 50c9f2
Packit Service 50c9f2
  \ingroup io
Packit Service 50c9f2
Packit Service 50c9f2
  QFile is an I/O device for reading and writing binary and text files.	A
Packit Service 50c9f2
  QFile may be used by itself (readBlock and writeBlock) or by more
Packit Service 50c9f2
  conveniently using QDataStream or QTextStream.
Packit Service 50c9f2
Packit Service 50c9f2
  Here is a code fragment that uses QTextStream to read a text
Packit Service 50c9f2
  file line by line. It prints each line with a line number.
Packit Service 50c9f2
  \code
Packit Service 50c9f2
    QFile f("file.txt");
Packit Service 50c9f2
    if ( f.open(IO_ReadOnly) ) {    // file opened successfully
Packit Service 50c9f2
	QTextStream t( &f );	    // use a text stream
Packit Service 50c9f2
	QString s;
Packit Service 50c9f2
	int n = 1;
Packit Service 50c9f2
	while ( !t.eof() ) {	    // until end of file...
Packit Service 50c9f2
	    s = t.readLine();	    // line of text excluding '\n'
Packit Service 50c9f2
	    printf( "%3d: %s\n", n++, (const char *)s );
Packit Service 50c9f2
	}
Packit Service 50c9f2
	f.close();
Packit Service 50c9f2
    }
Packit Service 50c9f2
  \endcode
Packit Service 50c9f2
Packit Service 50c9f2
  The QFileInfo class holds detailed information about a file, such as
Packit Service 50c9f2
  access permissions, file dates and file types.
Packit Service 50c9f2
Packit Service 50c9f2
  The QDir class manages directories and lists of file names.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa QDataStream, QTextStream
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Constructs a QFile with no name.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QFile::QFile()
Packit Service 50c9f2
{
Packit Service 50c9f2
    init();
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Constructs a QFile with a file name \e name.
Packit Service 50c9f2
  \sa setName()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QFile::QFile( const QString &name )
Packit Service 50c9f2
    : fn(name)
Packit Service 50c9f2
{
Packit Service 50c9f2
    init();
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Destructs a QFile.  Calls close().
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QFile::~QFile()
Packit Service 50c9f2
{
Packit Service 50c9f2
    close();
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \internal
Packit Service 50c9f2
  Initialize internal data.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
void QFile::init()
Packit Service 50c9f2
{
Packit Service 50c9f2
    setFlags( IO_Direct );
Packit Service 50c9f2
    setStatus( IO_Ok );
Packit Service 50c9f2
    fh	   = 0;
Packit Service 50c9f2
    fd	   = 0;
Packit Service 50c9f2
    length = 0;
Packit Service 50c9f2
    ioIndex = 0;
Packit Service 50c9f2
    ext_f  = FALSE;				// not an external file handle
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QString QFile::name() const
Packit Service 50c9f2
  Returns the name set by setName().
Packit Service 50c9f2
  \sa setName(), QFileInfo::fileName()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Sets the name of the file. The name can include an absolute directory
Packit Service 50c9f2
  path or it can be a name or a path relative to the current directory.
Packit Service 50c9f2
Packit Service 50c9f2
  Do not call this function if the file has already been opened.
Packit Service 50c9f2
Packit Service 50c9f2
  Note that if the name is relative QFile does not associate it with the
Packit Service 50c9f2
  current directory.  If you change directory before calling open(), open
Packit Service 50c9f2
  uses the new current directory.
Packit Service 50c9f2
Packit Service 50c9f2
  Example:
Packit Service 50c9f2
  \code
Packit Service 50c9f2
     QFile f;
Packit Service 50c9f2
     QDir::setCurrent( "/tmp" );
Packit Service 50c9f2
     f.setName( "readme.txt" );
Packit Service 50c9f2
     QDir::setCurrent( "/home" );
Packit Service 50c9f2
     f.open( IO_ReadOnly );	   // opens "/home/readme.txt" under UNIX
Packit Service 50c9f2
  \endcode
Packit Service 50c9f2
Packit Service 50c9f2
  Also note that the directory separator '/' works for all operating
Packit Service 50c9f2
  systems supported by Qt.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa name(), QFileInfo, QDir
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
void QFile::setName( const QString &name )
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( isOpen() ) {
Packit Service 50c9f2
#if defined(CHECK_STATE)
Packit Service 50c9f2
	qWarning( "QFile::setName: File is open" );
Packit Service 50c9f2
#endif
Packit Service 50c9f2
	close();
Packit Service 50c9f2
    }
Packit Service 50c9f2
    fn = name;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns TRUE if this file exists, otherwise FALSE.
Packit Service 50c9f2
  \sa name()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QFile::exists() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return qt_file_access( fn, F_OK );
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns TRUE if the file given by \e fileName exists, otherwise FALSE.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QFile::exists( const QString &fileName )
Packit Service 50c9f2
{
Packit Service 50c9f2
    return qt_file_access( fileName, F_OK );
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Removes the file specified by the file name currently set.
Packit Service 50c9f2
  Returns TRUE if successful, otherwise FALSE.
Packit Service 50c9f2
Packit Service 50c9f2
  The file is closed before it is removed.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QFile::remove()
Packit Service 50c9f2
{
Packit Service 50c9f2
    close();
Packit Service 50c9f2
    return remove( fn );
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
#if defined(_OS_MAC_) || defined(_OS_MSDOS_) || defined(_OS_WIN32_) || defined(_OS_OS2_) || defined(_OS_CYGWIN_)
Packit Service 50c9f2
# define HAS_TEXT_FILEMODE			// has translate/text filemode
Packit Service 50c9f2
#endif
Packit Service 50c9f2
#if defined(O_NONBLOCK)
Packit Service 50c9f2
# define HAS_ASYNC_FILEMODE
Packit Service 50c9f2
# define OPEN_ASYNC O_NONBLOCK
Packit Service 50c9f2
#elif defined(O_NDELAY)
Packit Service 50c9f2
# define HAS_ASYNC_FILEMODE
Packit Service 50c9f2
# define OPEN_ASYNC O_NDELAY
Packit Service 50c9f2
#endif
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Flushes the file buffer to the disk.
Packit Service 50c9f2
Packit Service 50c9f2
  close() also flushes the file buffer.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
void QFile::flush()
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( isOpen() && fh )			// can only flush open/buffered
Packit Service 50c9f2
	fflush( fh );				//   file
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Returns TRUE if the end of file has been reached, otherwise FALSE.
Packit Service 50c9f2
  \sa size()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
bool QFile::atEnd() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( !isOpen() ) {
Packit Service 50c9f2
#if defined(CHECK_STATE)
Packit Service 50c9f2
	qWarning( "QFile::atEnd: File is not open" );
Packit Service 50c9f2
#endif
Packit Service 50c9f2
	return FALSE;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    if ( isDirectAccess() && !isTranslated() ) {
Packit Service 50c9f2
	if ( at() < length )
Packit Service 50c9f2
	    return FALSE;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return QIODevice::atEnd();
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Reads a line of text.
Packit Service 50c9f2
Packit Service 50c9f2
  Reads bytes from the file until end-of-line is reached, or up to \a
Packit Service 50c9f2
  maxlen bytes, and returns the number of bytes read, or -1 in case of
Packit Service 50c9f2
  error.  The terminating newline is not stripped.
Packit Service 50c9f2
Packit Service 50c9f2
  This function is efficient only for buffered files.  Avoid
Packit Service 50c9f2
  readLine() for files that have been opened with the \c IO_Raw
Packit Service 50c9f2
  flag.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa readBlock(), QTextStream::readLine()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QFile::readLine( char *p, uint maxlen )
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( maxlen == 0 )				// application bug?
Packit Service 50c9f2
	return 0;
Packit Service 50c9f2
#if defined(CHECK_STATE)
Packit Service 50c9f2
    CHECK_PTR( p );
Packit Service 50c9f2
    if ( !isOpen() ) {				// file not open
Packit Service 50c9f2
	qWarning( "QFile::readLine: File not open" );
Packit Service 50c9f2
	return -1;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    if ( !isReadable() ) {			// reading not permitted
Packit Service 50c9f2
	qWarning( "QFile::readLine: Read operation not permitted" );
Packit Service 50c9f2
	return -1;
Packit Service 50c9f2
    }
Packit Service 50c9f2
#endif
Packit Service 50c9f2
    int nread;					// number of bytes read
Packit Service 50c9f2
    if ( isRaw() ) {				// raw file
Packit Service 50c9f2
	nread = QIODevice::readLine( p, maxlen );
Packit Service 50c9f2
    } else {					// buffered file
Packit Service 50c9f2
	p = fgets( p, maxlen, fh );
Packit Service 50c9f2
	if ( p ) {
Packit Service 50c9f2
	    nread = qstrlen( p );
Packit Service 50c9f2
	    ioIndex += nread;
Packit Service 50c9f2
	} else {
Packit Service 50c9f2
	    nread = -1;
Packit Service 50c9f2
	    setStatus(IO_ReadError);
Packit Service 50c9f2
	}
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return nread;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Reads a line of text.
Packit Service 50c9f2
Packit Service 50c9f2
  Reads bytes from the file until end-of-line is reached, or up to \a
Packit Service 50c9f2
  maxlen bytes, and returns the number of bytes read, or -1 in case of
Packit Service 50c9f2
  error.  The terminating newline is not stripped.
Packit Service 50c9f2
Packit Service 50c9f2
  This function is efficient only for buffered files.  Avoid
Packit Service 50c9f2
  readLine() for files that have been opened with the \c IO_Raw
Packit Service 50c9f2
  flag.
Packit Service 50c9f2
Packit Service 50c9f2
  Note that the string is read as plain Latin1 bytes, not Unicode.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa readBlock(), QTextStream::readLine()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QFile::readLine( QString& s, uint maxlen )
Packit Service 50c9f2
{
Packit Service 50c9f2
    QByteArray ba(maxlen);
Packit Service 50c9f2
    int l = readLine(ba.data(),maxlen);
Packit Service 50c9f2
    if ( l >= 0 ) {
Packit Service 50c9f2
	ba.truncate(l);
Packit Service 50c9f2
	s = QString(ba);
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return l;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Reads a single byte/character from the file.
Packit Service 50c9f2
Packit Service 50c9f2
  Returns the byte/character read, or -1 if the end of the file has been
Packit Service 50c9f2
  reached.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa putch(), ungetch()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QFile::getch()
Packit Service 50c9f2
{
Packit Service 50c9f2
#if defined(CHECK_STATE)
Packit Service 50c9f2
    if ( !isOpen() ) {				// file not open
Packit Service 50c9f2
	qWarning( "QFile::getch: File not open" );
Packit Service 50c9f2
	return EOF;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    if ( !isReadable() ) {			// reading not permitted
Packit Service 50c9f2
	qWarning( "QFile::getch: Read operation not permitted" );
Packit Service 50c9f2
	return EOF;
Packit Service 50c9f2
    }
Packit Service 50c9f2
#endif
Packit Service 50c9f2
Packit Service 50c9f2
    int ch;
Packit Service 50c9f2
Packit Service 50c9f2
    if ( !ungetchBuffer.isEmpty() ) {
Packit Service 50c9f2
	int len = ungetchBuffer.length();
Packit Service 50c9f2
	ch = ungetchBuffer[ len-1 ];
Packit Service 50c9f2
	ungetchBuffer.truncate( len - 1 );
Packit Service 50c9f2
	return ch;
Packit Service 50c9f2
    }
Packit Service 50c9f2
Packit Service 50c9f2
    if ( isRaw() ) {				// raw file (inefficient)
Packit Service 50c9f2
	char buf[1];
Packit Service 50c9f2
	ch = readBlock( buf, 1 ) == 1 ? buf[0] : EOF;
Packit Service 50c9f2
    } else {					// buffered file
Packit Service 50c9f2
	if ( (ch = getc( fh )) != EOF )
Packit Service 50c9f2
	    ioIndex++;
Packit Service 50c9f2
	else
Packit Service 50c9f2
	    setStatus(IO_ReadError);
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return ch;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn int QFile::writeBlock( const QByteArray& data )
Packit Service 50c9f2
  \reimp
Packit Service 50c9f2
  \internal
Packit Service 50c9f2
  Should be removed in 3.0
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Writes the character \e ch to the file.
Packit Service 50c9f2
Packit Service 50c9f2
  Returns \e ch, or -1 if some error occurred.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa getch(), ungetch()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QFile::putch( int ch )
Packit Service 50c9f2
{
Packit Service 50c9f2
#if defined(CHECK_STATE)
Packit Service 50c9f2
    if ( !isOpen() ) {				// file not open
Packit Service 50c9f2
	qWarning( "QFile::putch: File not open" );
Packit Service 50c9f2
	return EOF;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    if ( !isWritable() ) {			// writing not permitted
Packit Service 50c9f2
	qWarning( "QFile::putch: Write operation not permitted" );
Packit Service 50c9f2
	return EOF;
Packit Service 50c9f2
    }
Packit Service 50c9f2
#endif
Packit Service 50c9f2
    if ( isRaw() ) {				// raw file (inefficient)
Packit Service 50c9f2
	char buf[1];
Packit Service 50c9f2
	buf[0] = ch;
Packit Service 50c9f2
	ch = writeBlock( buf, 1 ) == 1 ? ch : EOF;
Packit Service 50c9f2
    } else {					// buffered file
Packit Service 50c9f2
	if ( (ch = putc( ch, fh )) != EOF ) {
Packit Service 50c9f2
	    ioIndex++;
Packit Service 50c9f2
	    if ( ioIndex > length )		// update file length
Packit Service 50c9f2
		length = ioIndex;
Packit Service 50c9f2
	} else {
Packit Service 50c9f2
	    setStatus(IO_WriteError);
Packit Service 50c9f2
	}
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return ch;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Puts the character \e ch back into the file and decrements the index if it
Packit Service 50c9f2
  is not zero.
Packit Service 50c9f2
Packit Service 50c9f2
  This function is normally called to "undo" a getch() operation.
Packit Service 50c9f2
Packit Service 50c9f2
  Returns \e ch, or -1 if some error occurred.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa getch(), putch()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
int QFile::ungetch( int ch )
Packit Service 50c9f2
{
Packit Service 50c9f2
#if defined(CHECK_STATE)
Packit Service 50c9f2
    if ( !isOpen() ) {				// file not open
Packit Service 50c9f2
	qWarning( "QFile::ungetch: File not open" );
Packit Service 50c9f2
	return EOF;
Packit Service 50c9f2
    }
Packit Service 50c9f2
    if ( !isReadable() ) {			// reading not permitted
Packit Service 50c9f2
	qWarning( "QFile::ungetch: Read operation not permitted" );
Packit Service 50c9f2
	return EOF;
Packit Service 50c9f2
    }
Packit Service 50c9f2
#endif
Packit Service 50c9f2
    if ( ch == EOF )				// cannot unget EOF
Packit Service 50c9f2
	return ch;
Packit Service 50c9f2
Packit Service 50c9f2
    if ( isSequentialAccess() && !fh) {
Packit Service 50c9f2
	// pipe or similar => we cannot ungetch, so do it manually
Packit Service 50c9f2
	ungetchBuffer +=ch;
Packit Service 50c9f2
	return ch;
Packit Service 50c9f2
    }
Packit Service 50c9f2
Packit Service 50c9f2
    if ( isRaw() ) {				// raw file (very inefficient)
Packit Service 50c9f2
	char buf[1];
Packit Service 50c9f2
	at( ioIndex-1 );
Packit Service 50c9f2
	buf[0] = ch;
Packit Service 50c9f2
	if ( writeBlock(buf, 1) == 1 )
Packit Service 50c9f2
	    at ( ioIndex-1 );
Packit Service 50c9f2
	else
Packit Service 50c9f2
	    ch = EOF;
Packit Service 50c9f2
    } else {					// buffered file
Packit Service 50c9f2
	if ( (ch = ungetc(ch, fh)) != EOF )
Packit Service 50c9f2
	    ioIndex--;
Packit Service 50c9f2
	else
Packit Service 50c9f2
	    setStatus( IO_ReadError );
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return ch;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
static QCString locale_encoder( const QString &fileName )
Packit Service 50c9f2
{
Packit Service 50c9f2
    return fileName.local8Bit();
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
static QFile::EncoderFn encoder = locale_encoder;
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  When you use QFile, QFileInfo, and QDir to access the filesystem
Packit Service 50c9f2
  with Qt, you can use Unicode filenames.  On Unix, these filenames
Packit Service 50c9f2
  are converted to an 8-bit encoding.  If you want to do your own
Packit Service 50c9f2
  file I/O on Unix, you should convert the filename using this
Packit Service 50c9f2
  function.  On Windows NT, Unicode filenames are supported directly
Packit Service 50c9f2
  in the filesystem and this function should be avoided. On Windows 95,
Packit Service 50c9f2
  non-Latin1 locales are not supported at this time.
Packit Service 50c9f2
Packit Service 50c9f2
  By default, this function converts to the local 8-bit encoding
Packit Service 50c9f2
  determined by the user's locale.  This is sufficient for
Packit Service 50c9f2
  filenames that the user chooses.  Filenames hard-coded into the
Packit Service 50c9f2
  application should only use 7-bit ASCII filename characters.
Packit Service 50c9f2
Packit Service 50c9f2
  The conversion scheme can be changed using setEncodingFunction().
Packit Service 50c9f2
  This might be useful if you wish to give the user an option to
Packit Service 50c9f2
  store in filenames in UTF-8, etc., but beware that such filenames
Packit Service 50c9f2
  would probably then be unrecognizable when seen by other programs.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa decodeName()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QCString QFile::encodeName( const QString &fileName )
Packit Service 50c9f2
{
Packit Service 50c9f2
    return (*encoder)(fileName);
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \enum QFile::EncoderFn
Packit Service 50c9f2
Packit Service 50c9f2
  This is used by QFile::setEncodingFunction().
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Sets the function for encoding Unicode filenames.
Packit Service 50c9f2
  The default encodes in the locale-specific 8-bit encoding.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa encodeName()
Packit Service 50c9f2
*/
Packit Service 50c9f2
void QFile::setEncodingFunction( EncoderFn f )
Packit Service 50c9f2
{
Packit Service 50c9f2
    encoder = f;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
static
Packit Service 50c9f2
QString locale_decoder( const QCString &localFileName )
Packit Service 50c9f2
{
Packit Service 50c9f2
    return QString::fromLocal8Bit(localFileName);
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
static QFile::DecoderFn decoder = locale_decoder;
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  This does the reverse of QFile::encodeName().
Packit Service 50c9f2
Packit Service 50c9f2
  \sa setDecodingFunction()
Packit Service 50c9f2
*/
Packit Service 50c9f2
QString QFile::decodeName( const QCString &localFileName )
Packit Service 50c9f2
{
Packit Service 50c9f2
    return (*decoder)(localFileName);
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \enum QFile::DecoderFn
Packit Service 50c9f2
Packit Service 50c9f2
  This is used by QFile::setDecodingFunction().
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Sets the function for decoding 8-bit filenames.
Packit Service 50c9f2
  The default uses the locale-specific 8-bit encoding.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa encodeName(), decodeName()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
void QFile::setDecodingFunction( DecoderFn f )
Packit Service 50c9f2
{
Packit Service 50c9f2
    decoder = f;
Packit Service 50c9f2
}