aboutsummaryrefslogtreecommitdiff
path: root/example/ioctl_client.c
diff options
context:
space:
mode:
authorGravatar Nikolaus Rath <Nikolaus@rath.org>2016-10-09 19:50:51 -0700
committerGravatar Nikolaus Rath <Nikolaus@rath.org>2016-10-09 22:03:07 -0700
commitbcad1a6f22662ff0d04a6ae417adb30550252d97 (patch)
tree2c73c2278eca7d7062ffef178669616c3afb1410 /example/ioctl_client.c
parent463189cd121ce9a9f79d24c207e7c6c31898ea06 (diff)
Renamed ioctl and poll examples
The new names should make it more obvious at first glance what each example demonstrates.
Diffstat (limited to 'example/ioctl_client.c')
-rw-r--r--example/ioctl_client.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/example/ioctl_client.c b/example/ioctl_client.c
new file mode 100644
index 0000000..83ede65
--- /dev/null
+++ b/example/ioctl_client.c
@@ -0,0 +1,73 @@
+/*
+ FUSE fioclient: FUSE ioctl example client
+ Copyright (C) 2008 SUSE Linux Products GmbH
+ Copyright (C) 2008 Tejun Heo <teheo@suse.de>
+
+ This program tests the ioctl.c example file systsem.
+
+ This program can be distributed under the terms of the GNU GPL.
+ See the file COPYING.
+*/
+
+/** @file
+ * @tableofcontents
+ *
+ * This program tests the ioctl.c example file systsem.
+ *
+ * \section section_compile compiling this example
+ *
+ * gcc -Wall ioctl_client.c -o ioctl_client
+ *
+ * \section section_source the complete source
+ * \include ioctl_client.c
+ */
+
+#include <config.h>
+
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <errno.h>
+#include "ioctl.h"
+
+const char *usage =
+"Usage: fioclient FIOC_FILE [size]\n"
+"\n"
+"Get size if <size> is omitted, set size otherwise\n"
+"\n";
+
+int main(int argc, char **argv)
+{
+ size_t size;
+ int fd;
+
+ if (argc < 2) {
+ fprintf(stderr, "%s", usage);
+ return 1;
+ }
+
+ fd = open(argv[1], O_RDWR);
+ if (fd < 0) {
+ perror("open");
+ return 1;
+ }
+
+ if (argc == 2) {
+ if (ioctl(fd, FIOC_GET_SIZE, &size)) {
+ perror("ioctl");
+ return 1;
+ }
+ printf("%zu\n", size);
+ } else {
+ size = strtoul(argv[2], NULL, 0);
+ if (ioctl(fd, FIOC_SET_SIZE, &size)) {
+ perror("ioctl");
+ return 1;
+ }
+ }
+ return 0;
+}