1 /* $OpenBSD: fuse-opt-add-arg.c,v 1.4 2018/07/20 12:05:08 helg Exp $ */
2 /*
3 * Copyright (c) Sylvestre Gallon <ccna.syl@gmail.com>
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 <string.h>
19 #include <fuse_opt.h>
20
21 #define ADD_ARG(fa, a) if (fuse_opt_add_arg(fa, a) != 0) \
22 return (1);
23
24 char *argstest[] = {
25 "-d",
26 "test",
27 "--test",
28 "-o foo",
29 "barfoo"
30 };
31
32 int
main(int ac,char ** av)33 main(int ac, char **av)
34 {
35 struct fuse_args args = FUSE_ARGS_INIT(ac, av);
36 int len, i;
37
38 len = sizeof(argstest) / sizeof(*argstest);
39
40 for (i = 0; i < len; i++)
41 ADD_ARG(&args, argstest[i]);
42
43 if (!args.allocated)
44 return (1);
45 if (fuse_opt_add_arg(&args, NULL) != -1)
46 return (2);
47
48 for (i = 0; i < len; i++)
49 if (strcmp(args.argv[i+1], argstest[i]) != 0)
50 return (4);
51
52 if (args.argc != len + 1)
53 return (5);
54
55 fuse_opt_free_args(&args);
56 if (args.allocated)
57 return (6);
58 return (0);
59 }
60
61