summaryrefslogtreecommitdiffstats
path: root/contrib/fuse-lib/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/fuse-lib/misc.c')
-rw-r--r--contrib/fuse-lib/misc.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/contrib/fuse-lib/misc.c b/contrib/fuse-lib/misc.c
new file mode 100644
index 00000000000..877c3880de0
--- /dev/null
+++ b/contrib/fuse-lib/misc.c
@@ -0,0 +1,51 @@
+/*
+ FUSE: Filesystem in Userspace
+ Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
+
+ This program can be distributed under the terms of the GNU LGPLv2.
+ See the file COPYING.LIB
+*/
+
+#include <stdint.h>
+#include <string.h>
+#include <limits.h>
+#include <fcntl.h>
+#include "fuse_kernel.h"
+#include "fuse-misc.h"
+
+unsigned long
+calc_timeout_sec (double t)
+{
+ if (t > (double) ULONG_MAX)
+ return ULONG_MAX;
+ else if (t < 0.0)
+ return 0;
+ else
+ return (unsigned long) t;
+}
+
+unsigned int
+calc_timeout_nsec (double t)
+{
+ double f = t - (double) calc_timeout_sec (t);
+ if (f < 0.0)
+ return 0;
+ else if (f >= 0.999999999)
+ return 999999999;
+ else
+ return (unsigned int) (f * 1.0e9);
+}
+
+void
+convert_fuse_file_lock (struct fuse_file_lock *fl, struct flock *flock)
+{
+ memset (flock, 0, sizeof (struct flock));
+ flock->l_type = fl->type;
+ flock->l_whence = SEEK_SET;
+ flock->l_start = fl->start;
+ if (fl->end == OFFSET_MAX)
+ flock->l_len = 0;
+ else
+ flock->l_len = fl->end - fl->start + 1;
+ flock->l_pid = fl->pid;
+}