Set _LARGEFILE_SOURCE; use O_NONBLOCK where available, in case of file-to-fifo switch or mandatory file locking

This commit is contained in:
Brian Cox 2016-04-07 18:56:39 -07:00
parent 4af1a707ef
commit c41aba17db
7 changed files with 27 additions and 21 deletions

4
configure vendored
View File

@ -3251,8 +3251,8 @@ ac_config_headers="$ac_config_headers config.h"
rm -f src/tripwire/syslog.h 2> /dev/null
chmod 755 install-sh 2> /dev/null
CFLAGS=${CFLAGS:-"-O -pipe -Wall -Wno-non-virtual-dtor"}
CXXFLAGS=${CXXFLAGS:-"-O -pipe -Wall -Wno-non-virtual-dtor"}
CFLAGS=${CFLAGS:-"-O -pipe -Wall -Wno-non-virtual-dtor -D_LARGEFILE_SOURCE"}
CXXFLAGS=${CXXFLAGS:-"-O -pipe -Wall -Wno-non-virtual-dtor -D_LARGEFILE_SOURCE"}
# Check whether --enable-static was given.
if test "${enable_static+set}" = set; then :

View File

@ -17,8 +17,8 @@ chmod 755 install-sh 2> /dev/null
dnl ###############
dnl Setup defaults
dnl ###############
CFLAGS=${CFLAGS:-"-O -pipe -Wall -Wno-non-virtual-dtor"}
CXXFLAGS=${CXXFLAGS:-"-O -pipe -Wall -Wno-non-virtual-dtor"}
CFLAGS=${CFLAGS:-"-O -pipe -Wall -Wno-non-virtual-dtor -D_LARGEFILE_SOURCE"}
CXXFLAGS=${CXXFLAGS:-"-O -pipe -Wall -Wno-non-virtual-dtor -D_LARGEFILE_SOURCE"}
dnl #####################
dnl Configuration options

2
src/core/archive.cpp Normal file → Executable file
View File

@ -678,6 +678,7 @@ void cFileArchive::OpenRead(const TCHAR* filename, uint32 openFlags)
uint32 flags = cFile::OPEN_READ;
flags |= ( ( openFlags & FA_OPEN_TRUNCATE ) ? cFile::OPEN_TRUNCATE : 0 );
flags |= ( ( openFlags & FA_OPEN_TEXT ) ? cFile::OPEN_TEXT : 0 );
flags |= ( ( openFlags & FA_NONBLOCKING ) ? cFile::OPEN_NONBLOCKING :0 );
mCurrentFilename = filename;
mCurrentFile.Open( filename, flags );
@ -703,6 +704,7 @@ void cFileArchive::OpenReadWrite(const TCHAR* filename, uint32 openFlags)
uint32 flags = cFile::OPEN_WRITE;
flags |= ( ( openFlags & FA_OPEN_TRUNCATE ) ? cFile::OPEN_TRUNCATE : 0 );
flags |= ( ( openFlags & FA_OPEN_TEXT ) ? cFile::OPEN_TEXT : 0 );
flags |= ( ( openFlags & FA_NONBLOCKING ) ? cFile::OPEN_NONBLOCKING :0 );
mCurrentFilename = filename;
mCurrentFile.Open( filename, flags );

3
src/core/archive.h Normal file → Executable file
View File

@ -259,7 +259,8 @@ public:
enum OpenFlags
{
FA_OPEN_TEXT = 0x1,
FA_OPEN_TRUNCATE = 0x2
FA_OPEN_TRUNCATE = 0x2,
FA_NONBLOCKING = 0x4
};
// TODO: Open should throw

24
src/core/file.h Normal file → Executable file
View File

@ -81,22 +81,22 @@ public:
enum SeekFrom
{
SEEK_BEGIN = 0,
SEEK_CURRENT,
SEEK_EOF
SEEK_BEGIN = 0,
SEEK_CURRENT,
SEEK_EOF
};
enum OpenFlags
{
// note that reading from the file is implicit
//
OPEN_READ = 0x00000001, // not needed, but makes calls nice...
OPEN_WRITE = 0x00000002, // we will be writing to the file
OPEN_LOCKED_TEMP = 0x00000004, // the file should not be readable by other processes and should be removed when closed
OPEN_TRUNCATE = 0x00000008, // opens an empty file. creates it if it doesn't exist. Doesn't make much sense without OF_WRITE
OPEN_CREATE = 0x00000010, // create the file if it doesn't exist; this is implicit if OF_TRUNCATE is set
OPEN_TEXT = 0x00000020,
OPEN_EXCLUSIVE = 0x00000040 // Use O_CREAT | O_EXCL
// note that reading from the file is implicit
OPEN_READ = 0x00000001, // not needed, but makes calls nice...
OPEN_WRITE = 0x00000002, // we will be writing to the file
OPEN_LOCKED_TEMP = 0x00000004, // the file should not be readable by other processes and should be removed when closed
OPEN_TRUNCATE = 0x00000008, // opens an empty file. creates it if it doesn't exist. Doesn't make much sense without OF_WRITE
OPEN_CREATE = 0x00000010, // create the file if it doesn't exist; this is implicit if OF_TRUNCATE is set
OPEN_TEXT = 0x00000020,
OPEN_EXCLUSIVE = 0x00000040, // Use O_CREAT | O_EXCL
OPEN_NONBLOCKING = 0x00000080, // Use non-blocking i/o [Unix]
};
//Ctor, Dtor, CpyCtor, Operator=:

9
src/core/file_unix.cpp Normal file → Executable file
View File

@ -165,10 +165,13 @@ void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
openmode = (mode_t) 0600; // Make sure only root can read the file
}
if ( flags & OPEN_CREATE )
perm |= O_CREAT;
if ( flags & OPEN_CREATE )
perm |= O_CREAT;
#ifdef O_NONBLOCK
if( flags & OPEN_NONBLOCKING )
perm |= O_NONBLOCK;
#endif
//
// actually open the file
//

2
src/fs/fspropcalc.cpp Normal file → Executable file
View File

@ -295,7 +295,7 @@ void cFSPropCalc::VisitFSObject(cFSObject& obj)
pTheArch = &arch;
try
{
arch.OpenRead(strName.c_str());
arch.OpenRead(strName.c_str(), cFileArchive::FA_NONBLOCKING);
}
catch (eArchive&)
{