1*f3de9d7dShelg /* $OpenBSD: fuse-opt-insert-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 char *argstest[] = {
224cd66a05Ssyl "-d",
234cd66a05Ssyl "test",
244cd66a05Ssyl "--test",
254cd66a05Ssyl "-o foo",
264cd66a05Ssyl "barfoo"
274cd66a05Ssyl };
284cd66a05Ssyl
294cd66a05Ssyl int
main(int ac,char ** av)304cd66a05Ssyl main(int ac, char **av)
314cd66a05Ssyl {
324cd66a05Ssyl struct fuse_args args = FUSE_ARGS_INIT(ac, av);
334cd66a05Ssyl int len, i;
344cd66a05Ssyl
354cd66a05Ssyl len = sizeof(argstest) / sizeof(*argstest);
364cd66a05Ssyl
374cd66a05Ssyl if (fuse_opt_insert_arg(&args, 1, "test") != 0)
384cd66a05Ssyl return (1);
394cd66a05Ssyl if (fuse_opt_insert_arg(&args, 1, "-d") != 0)
40a8f3d127Smpi return (2);
414cd66a05Ssyl if (fuse_opt_insert_arg(&args, 3, "barfoo") != 0)
42a8f3d127Smpi return (3);
434cd66a05Ssyl if (fuse_opt_insert_arg(&args, 3, "--test") != 0)
44a8f3d127Smpi return (4);
454cd66a05Ssyl if (fuse_opt_insert_arg(&args, 4, "-o foo") != 0)
46a8f3d127Smpi return (5);
474cd66a05Ssyl
484cd66a05Ssyl if (!args.allocated)
49a8f3d127Smpi return (6);
504cd66a05Ssyl if (fuse_opt_insert_arg(&args, 1, NULL) != -1)
51a8f3d127Smpi return (7);
524cd66a05Ssyl if (fuse_opt_insert_arg(&args, -1, "foo") != -1)
53a8f3d127Smpi return (9);
544cd66a05Ssyl if (fuse_opt_insert_arg(&args, 42, "foo") != -1)
55a8f3d127Smpi return (10);
564cd66a05Ssyl
574cd66a05Ssyl for (i = 0; i < len; i++)
584cd66a05Ssyl if (strcmp(args.argv[i+1], argstest[i]) != 0)
59a8f3d127Smpi return (11);
604cd66a05Ssyl
614cd66a05Ssyl if (args.argc != len + 1)
62a8f3d127Smpi return (12);
634cd66a05Ssyl
644cd66a05Ssyl fuse_opt_free_args(&args);
654cd66a05Ssyl if (args.allocated)
66a8f3d127Smpi return (13);
674cd66a05Ssyl return (0);
684cd66a05Ssyl }
694cd66a05Ssyl
70