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/core/file.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/core/file.c') diff --git a/src/core/file.c b/src/core/file.c index 4715be2a..b76fdcda 100644 --- a/src/core/file.c +++ b/src/core/file.c @@ -128,4 +128,32 @@ const char * nni_file_basename(const char *path) { return (nni_plat_file_basename(path)); +} + +struct nni_file_lockh { + nni_plat_flock lk; +}; + +int +nni_file_lock(const char *path, nni_file_lockh **hp) +{ + nni_file_lockh *h; + int rv; + if ((h = NNI_ALLOC_STRUCT(h)) == NULL) { + return (NNG_ENOMEM); + } + rv = nni_plat_file_lock(path, &h->lk); + if (rv != 0) { + NNI_FREE_STRUCT(h); + return (rv); + } + *hp = h; + return (0); +} + +void +nni_file_unlock(nni_file_lockh *h) +{ + nni_plat_file_unlock(&h->lk); + NNI_FREE_STRUCT(h); } \ No newline at end of file -- cgit v1.2.3-70-g09d2