mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
Core: FileStream NOWRITESHARE implemented for Linux,BSD using flock
git-svn-id: svn://ultimatepp.org/upp/trunk@4641 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
6ade22475d
commit
7a3af47051
3 changed files with 22 additions and 4 deletions
|
|
@ -473,6 +473,11 @@ bool FileStream::Open(const char *name, dword mode, mode_t tmode) {
|
||||||
O_RDWR|O_CREAT,
|
O_RDWR|O_CREAT,
|
||||||
tmode);
|
tmode);
|
||||||
if(handle >= 0) {
|
if(handle >= 0) {
|
||||||
|
if((mode & NOWRITESHARE) && flock(handle, LOCK_EX|LOCK_NB) < 0) {
|
||||||
|
close(handle);
|
||||||
|
handle = -1;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
int64 fsz = LSEEK64_(handle, 0, SEEK_END);
|
int64 fsz = LSEEK64_(handle, 0, SEEK_END);
|
||||||
if(fsz >= 0) {
|
if(fsz >= 0) {
|
||||||
OpenInit(mode, fsz);
|
OpenInit(mode, fsz);
|
||||||
|
|
@ -508,6 +513,20 @@ FileStream::~FileStream() {
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PLATFORM_POSIX
|
||||||
|
bool FileOut::Open(const char *fn, mode_t acm)
|
||||||
|
{
|
||||||
|
return FileStream::Open(fn, FileStream::CREATE|FileStream::NOWRITESHARE, acm);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef PLATFORM_WIN32
|
||||||
|
bool FileOut::Open(const char *fn)
|
||||||
|
{
|
||||||
|
return FileStream::Open(fn, FileStream::CREATE|FileStream::NOWRITESHARE);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
END_UPP_NAMESPACE
|
END_UPP_NAMESPACE
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <sys/file.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
|
||||||
|
|
@ -418,14 +418,12 @@ public:
|
||||||
class FileOut : public FileStream {
|
class FileOut : public FileStream {
|
||||||
public:
|
public:
|
||||||
#ifdef PLATFORM_POSIX
|
#ifdef PLATFORM_POSIX
|
||||||
bool Open(const char *fn, mode_t acm = 0644)
|
bool Open(const char *fn, mode_t acm = 0644);
|
||||||
{ return FileStream::Open(fn, FileStream::CREATE, acm); }
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef PLATFORM_WIN32
|
#ifdef PLATFORM_WIN32
|
||||||
bool Open(const char *fn) { return FileStream::Open(fn, FileStream::CREATE|FileStream::NOWRITESHARE); }
|
bool Open(const char *fn);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
FileOut(const char *fn) { Open(fn); }
|
FileOut(const char *fn) { Open(fn); }
|
||||||
FileOut() {}
|
FileOut() {}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue