xref: /openbsd-src/regress/lib/libfuse/fuse-opt-add-arg.c (revision f3de9d7dd81d004e964f4bd559c4dd6d7cb610e1)
1*f3de9d7dShelg /* $OpenBSD: fuse-opt-add-arg.c,v 1.4 2018/07/20 12:05:08 helg Exp $ */
24cd66a05Ssyl /*
34cd66a05Ssyl  * Copyright (c) Sylvestre Gallon <ccna.syl@gmail.com>
44cd66a05Ssyl  *
54cd66a05Ssyl  * Permission to use, copy, modify, and distribute this software for any
64cd66a05Ssyl  * purpose with or without fee is hereby granted, provided that the above
74cd66a05Ssyl  * copyright notice and this permission notice appear in all copies.
84cd66a05Ssyl  *
94cd66a05Ssyl  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
104cd66a05Ssyl  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
114cd66a05Ssyl  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
124cd66a05Ssyl  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
134cd66a05Ssyl  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
144cd66a05Ssyl  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
154cd66a05Ssyl  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
164cd66a05Ssyl  */
174cd66a05Ssyl 
184cd66a05Ssyl #include <string.h>
194cd66a05Ssyl #include <fuse_opt.h>
204cd66a05Ssyl 
214cd66a05Ssyl #define ADD_ARG(fa, a)	if (fuse_opt_add_arg(fa, a) != 0) \
224cd66a05Ssyl 				return (1);
234cd66a05Ssyl 
244cd66a05Ssyl char *argstest[] = {
254cd66a05Ssyl 	"-d",
264cd66a05Ssyl 	"test",
274cd66a05Ssyl 	"--test",
284cd66a05Ssyl 	"-o foo",
294cd66a05Ssyl 	"barfoo"
304cd66a05Ssyl };
314cd66a05Ssyl 
324cd66a05Ssyl int
main(int ac,char ** av)334cd66a05Ssyl main(int ac, char **av)
344cd66a05Ssyl {
354cd66a05Ssyl 	struct fuse_args args = FUSE_ARGS_INIT(ac, av);
364cd66a05Ssyl 	int len, i;
374cd66a05Ssyl 
384cd66a05Ssyl 	len = sizeof(argstest) / sizeof(*argstest);
394cd66a05Ssyl 
404cd66a05Ssyl 	for (i = 0; i < len; i++)
414cd66a05Ssyl 		ADD_ARG(&args, argstest[i]);
424cd66a05Ssyl 
434cd66a05Ssyl 	if (!args.allocated)
444cd66a05Ssyl 		return (1);
454cd66a05Ssyl 	if (fuse_opt_add_arg(&args, NULL) != -1)
46a8f3d127Smpi 		return (2);
474cd66a05Ssyl 
484cd66a05Ssyl 	for (i = 0; i < len; i++)
494cd66a05Ssyl 		if (strcmp(args.argv[i+1], argstest[i]) != 0)
50a8f3d127Smpi 			return (4);
514cd66a05Ssyl 
524cd66a05Ssyl 	if (args.argc != len + 1)
53a8f3d127Smpi 		return (5);
544cd66a05Ssyl 
554cd66a05Ssyl 	fuse_opt_free_args(&args);
564cd66a05Ssyl 	if (args.allocated)
57a8f3d127Smpi 		return (6);
584cd66a05Ssyl 	return (0);
594cd66a05Ssyl }
604cd66a05Ssyl 
61