1 /* $OpenBSD: fuse-parse-cmdline.c,v 1.3 2018/07/20 12:05:08 helg Exp $ */
2 /*
3 * Copyright (c) 2017 Helg Bredow <helg@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 #include <fuse.h>
19 #include <stdlib.h>
20 #include <string.h>
21
22 static int
test_null_args(void)23 test_null_args(void)
24 {
25 if (fuse_parse_cmdline(NULL, NULL, NULL, NULL) == 0)
26 exit(__LINE__);
27
28 return (0);
29 }
30
31 static int
test_all_args(char ** dir,int * multithreaded,int * foreground)32 test_all_args(char **dir, int *multithreaded, int *foreground)
33 {
34 char *argv[] = {
35 "progname",
36 "-odebug",
37 /* read-only mount not supported yet */
38 /*fuse_opt_add_arg(args, "-odebug,ro");*/
39 /*fuse_opt_add_arg(args, "-r");*/
40 "-d",
41 "-f",
42 "/mnt",
43 "-s"
44 };
45 struct fuse_args args = FUSE_ARGS_INIT(6, argv);
46
47 if (dir != NULL)
48 *dir = NULL;
49
50 if (multithreaded != NULL)
51 *multithreaded = 0;
52
53 if (foreground != NULL)
54 *foreground = 0;
55
56 if (fuse_parse_cmdline(&args, dir, multithreaded, foreground) != 0)
57 exit (__LINE__);
58
59 if (dir != NULL && strcmp(*dir, "/mnt") != 0)
60 exit(__LINE__);
61 if (multithreaded != NULL && *multithreaded == 1)
62 exit(__LINE__);
63 if (foreground != NULL && *foreground == 0)
64 exit(__LINE__);
65
66 if (args.argc != 1)
67 exit(__LINE__);
68 if (strcmp(args.argv[0], "progname") != 0)
69 exit(__LINE__);
70
71 return (0);
72 }
73
74 int
main(void)75 main(void)
76 {
77 char *dir;
78 int multithreaded, foreground;
79
80 test_null_args();
81 test_all_args(NULL, NULL, NULL);
82 test_all_args(&dir, NULL, NULL);
83 test_all_args(&dir, &multithreaded, NULL);
84 test_all_args(&dir, &multithreaded, &foreground);
85
86 return (0);
87 }
88