aboutsummaryrefslogtreecommitdiff
path: root/src/core/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/file.c')
-rw-r--r--src/core/file.c28
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