1 /*
2  * Copyright (c) Sylvestre Gallon <ccna.syl@gmail.com>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #include <string.h>
18 #include <fuse_opt.h>
19 
20 #define ADD_ARG(fa, a)	if (fuse_opt_add_arg(fa, a) != 0) \
21 				return (1);
22 
23 char *argstest[] = {
24 	"-d",
25 	"test",
26 	"--test",
27 	"-o foo",
28 	"barfoo"
29 };
30 
31 int
32 main(int ac, char **av)
33 {
34 	struct fuse_args args = FUSE_ARGS_INIT(ac, av);
35 	int len, i;
36 
37 	len = sizeof(argstest) / sizeof(*argstest);
38 
39 	for (i = 0; i < len; i++)
40 		ADD_ARG(&args, argstest[i]);
41 
42 	if (!args.allocated)
43 		return (1);
44 	if (fuse_opt_add_arg(&args, NULL) != -1)
45 		return (1);
46 	if (fuse_opt_add_arg(&args, "") != -1)
47 		return (1);
48 
49 	for (i = 0; i < len; i++)
50 		if (strcmp(args.argv[i+1], argstest[i]) != 0)
51 			return (1);
52 
53 	if (args.argc != len + 1)
54 		return (1);
55 
56 	fuse_opt_free_args(&args);
57 	if (args.allocated)
58 		return (1);
59 	return (0);
60 }
61 
62