From 9bcbc8f919fc1c779d3b9c649dcbe3606fdbed32 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 25 May 2018 14:17:20 -0700 Subject: Added locking support to Bu::File. --- src/stable/file.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/stable/file.cpp') diff --git a/src/stable/file.cpp b/src/stable/file.cpp index 35933f1..a15f394 100644 --- a/src/stable/file.cpp +++ b/src/stable/file.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -200,6 +201,21 @@ void Bu::File::setBlocking( bool bBlocking ) #endif } +bool Bu::File::canLock() const +{ + return true; +} + +void Bu::File::lock( bool bExclusive ) +{ + ::flock( fd, bExclusive?LOCK_EX:LOCK_SH ); +} + +void Bu::File::unlock() +{ + ::flock( fd, LOCK_UN ); +} + Bu::File Bu::File::tempFile( Bu::String &sName ) { int iXes; -- cgit v1.2.3