diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/system/flock.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/system/flock.cpp')
-rw-r--r-- | util/system/flock.cpp | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/util/system/flock.cpp b/util/system/flock.cpp index fe88fecaff..ed485109d3 100644 --- a/util/system/flock.cpp +++ b/util/system/flock.cpp @@ -1,71 +1,71 @@ -#include "flock.h" +#include "flock.h" #ifndef _unix_ - #include <util/generic/utility.h> + #include <util/generic/utility.h> + + #include "winint.h" + #include <io.h> + #include <errno.h> - #include "winint.h" - #include <io.h> - #include <errno.h> - - #ifdef __cplusplus + #ifdef __cplusplus extern "C" { - #endif + #endif - int flock(int fd, int op) { - return Flock((HANDLE)_get_osfhandle(fd), op); - } + int flock(int fd, int op) { + return Flock((HANDLE)_get_osfhandle(fd), op); + } - int Flock(void* hdl, int op) { - errno = 0; + int Flock(void* hdl, int op) { + errno = 0; - if (hdl == INVALID_HANDLE_VALUE) { - errno = EBADF; - return -1; - } + if (hdl == INVALID_HANDLE_VALUE) { + errno = EBADF; + return -1; + } - DWORD low = 1, high = 0; - OVERLAPPED io; + DWORD low = 1, high = 0; + OVERLAPPED io; - Zero(io); + Zero(io); + + UnlockFileEx(hdl, 0, low, high, &io); - UnlockFileEx(hdl, 0, low, high, &io); - - switch (op & ~LOCK_NB) { - case LOCK_EX: - case LOCK_SH: { - auto mode = ((op & ~LOCK_NB) == LOCK_EX) ? LOCKFILE_EXCLUSIVE_LOCK : 0; - if (op & LOCK_NB) { - if (LockFileEx(hdl, mode | LOCKFILE_FAIL_IMMEDIATELY, 0, low, high, &io)) { - return 0; - } else if (GetLastError() == ERROR_LOCK_VIOLATION) { - ClearLastSystemError(); - errno = EWOULDBLOCK; - return -1; - } - } else { - if (LockFileEx(hdl, mode, 0, low, high, &io)) { - return 0; - } + switch (op & ~LOCK_NB) { + case LOCK_EX: + case LOCK_SH: { + auto mode = ((op & ~LOCK_NB) == LOCK_EX) ? LOCKFILE_EXCLUSIVE_LOCK : 0; + if (op & LOCK_NB) { + if (LockFileEx(hdl, mode | LOCKFILE_FAIL_IMMEDIATELY, 0, low, high, &io)) { + return 0; + } else if (GetLastError() == ERROR_LOCK_VIOLATION) { + ClearLastSystemError(); + errno = EWOULDBLOCK; + return -1; + } + } else { + if (LockFileEx(hdl, mode, 0, low, high, &io)) { + return 0; + } } - break; + break; } - case LOCK_UN: - return 0; - break; - default: - break; + case LOCK_UN: + return 0; + break; + default: + break; } - errno = EINVAL; - return -1; + errno = EINVAL; + return -1; } - int fsync(int fd) { - return _commit(fd); - } + int fsync(int fd) { + return _commit(fd); + } - #ifdef __cplusplus + #ifdef __cplusplus } - #endif + #endif #endif |