/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright 2021-2022, Danny Robson */ #include "./flock.hpp" #include "./except.hpp" #include "../platform.hpp" #include using flock_ = cruft::posix::flock; #ifndef PLATFORM_WIN32 /////////////////////////////////////////////////////////////////////////////// flock_::flock (cruft::posix::fd const &_fd, int const _operation) : flock (_fd.dup (), _operation) { ; } //----------------------------------------------------------------------------- flock_::flock ( cruft::posix::fd &&_fd, int operation ) : m_fd (std::move (_fd)) { cruft::posix::error::try_code ( ::flock (m_fd.native (), operation) ); } //----------------------------------------------------------------------------- flock_::flock (flock_ &&rhs) noexcept : m_fd (std::move (rhs.m_fd)) { ; } //----------------------------------------------------------------------------- flock_::~flock () { if (m_fd.native () < 0) return; cruft::posix::error::try_code ( ::flock (m_fd.native (), LOCK_UN) ); } //----------------------------------------------------------------------------- cruft::posix::fd const& flock_::native (void) const { return m_fd; } #endif