From c4da7817b4c8dd71b2a07d4d1c46b486ec57eeb4 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 5 Mar 2018 17:27:04 -0800 Subject: fixes #265 nngcat should support persistent ZT nodes fixes #267 zerotier transport should lock ZT_HOME --- src/platform/windows/win_file.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/platform/windows/win_file.c') diff --git a/src/platform/windows/win_file.c b/src/platform/windows/win_file.c index 2a9504aa..515647e0 100644 --- a/src/platform/windows/win_file.c +++ b/src/platform/windows/win_file.c @@ -342,4 +342,28 @@ nni_plat_file_basename(const char *name) return (name); } +int +nni_plat_file_lock(const char *path, nni_plat_flock *lk) +{ + HANDLE h; + + // On Windows we do not have to explicitly lock the file, the + // dwShareMode being set to zeor effectively prevents it. + h = CreateFile(path, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) { + return (nni_win_error(GetLastError())); + } + lk->h = h; + return (0); +} + +void +nni_plat_file_unlock(nni_plat_flock *lk) +{ + HANDLE h = lk->h; + (void) CloseHandle(h); + lk->h = INVALID_HANDLE_VALUE; +} + #endif // NNG_PLATFORM_WINDOWS \ No newline at end of file -- cgit v1.2.3-70-g09d2