diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-03-05 17:27:04 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-03-05 19:39:15 -0800 |
| commit | c4da7817b4c8dd71b2a07d4d1c46b486ec57eeb4 (patch) | |
| tree | b1166d49e6673fcbad28c0bd65630f5af37a86ab /src/core/file.c | |
| parent | b6298c28473acbed2f1429176c7cae4fb514d98b (diff) | |
| download | nng-c4da7817b4c8dd71b2a07d4d1c46b486ec57eeb4.tar.gz nng-c4da7817b4c8dd71b2a07d4d1c46b486ec57eeb4.tar.bz2 nng-c4da7817b4c8dd71b2a07d4d1c46b486ec57eeb4.zip | |
fixes #265 nngcat should support persistent ZT nodes
fixes #267 zerotier transport should lock ZT_HOME
Diffstat (limited to 'src/core/file.c')
| -rw-r--r-- | src/core/file.c | 28 |
1 files changed, 28 insertions, 0 deletions
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 |
