"Fossies" - the Fresh Open Source Software Archive

Member "fuse-3.2.3/example/ioctl_client.c" (11 May 2018, 1269 Bytes) of package /linux/misc/fuse-3.2.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "ioctl_client.c": 3.2.0_vs_3.2.1.

    1 /*
    2   FUSE fioclient: FUSE ioctl example client
    3   Copyright (C) 2008       SUSE Linux Products GmbH
    4   Copyright (C) 2008       Tejun Heo <teheo@suse.de>
    5 
    6   This program tests the ioctl.c example file systsem.
    7 
    8   This program can be distributed under the terms of the GNU GPL.
    9   See the file COPYING.
   10 */
   11 
   12 /** @file
   13  *
   14  * This program tests the ioctl.c example file systsem.
   15  *
   16  * Compile with:
   17  *
   18  *     gcc -Wall ioctl_client.c -o ioctl_client
   19  *
   20  * ## Source code ##
   21  * \include ioctl_client.c
   22  */
   23 
   24 #include <sys/types.h>
   25 #include <fcntl.h>
   26 #include <sys/stat.h>
   27 #include <sys/ioctl.h>
   28 #include <stdio.h>
   29 #include <stdlib.h>
   30 #include <ctype.h>
   31 #include <errno.h>
   32 #include "ioctl.h"
   33 
   34 const char *usage =
   35 "Usage: fioclient FIOC_FILE [size]\n"
   36 "\n"
   37 "Get size if <size> is omitted, set size otherwise\n"
   38 "\n";
   39 
   40 int main(int argc, char **argv)
   41 {
   42     size_t size;
   43     int fd;
   44 
   45     if (argc < 2) {
   46         fprintf(stderr, "%s", usage);
   47         return 1;
   48     }
   49 
   50     fd = open(argv[1], O_RDWR);
   51     if (fd < 0) {
   52         perror("open");
   53         return 1;
   54     }
   55 
   56     if (argc == 2) {
   57         if (ioctl(fd, FIOC_GET_SIZE, &size)) {
   58             perror("ioctl");
   59             return 1;
   60         }
   61         printf("%zu\n", size);
   62     } else {
   63         size = strtoul(argv[2], NULL, 0);
   64         if (ioctl(fd, FIOC_SET_SIZE, &size)) {
   65             perror("ioctl");
   66             return 1;
   67         }
   68     }
   69     return 0;
   70 }