1*f3de9d7dShelg /* $OpenBSD: fuse-parse-cmdline.c,v 1.3 2018/07/20 12:05:08 helg Exp $ */
20e9b8da4Shelg /*
30e9b8da4Shelg * Copyright (c) 2017 Helg Bredow <helg@openbsd.org>
40e9b8da4Shelg *
50e9b8da4Shelg * Permission to use, copy, modify, and distribute this software for any
60e9b8da4Shelg * purpose with or without fee is hereby granted, provided that the above
70e9b8da4Shelg * copyright notice and this permission notice appear in all copies.
80e9b8da4Shelg *
90e9b8da4Shelg * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
100e9b8da4Shelg * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
110e9b8da4Shelg * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
120e9b8da4Shelg * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
130e9b8da4Shelg * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
140e9b8da4Shelg * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
150e9b8da4Shelg * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
160e9b8da4Shelg */
170e9b8da4Shelg
180e9b8da4Shelg #include <fuse.h>
190e9b8da4Shelg #include <stdlib.h>
200e9b8da4Shelg #include <string.h>
210e9b8da4Shelg
220e9b8da4Shelg static int
test_null_args(void)230e9b8da4Shelg test_null_args(void)
240e9b8da4Shelg {
250e9b8da4Shelg if (fuse_parse_cmdline(NULL, NULL, NULL, NULL) == 0)
260e9b8da4Shelg exit(__LINE__);
270e9b8da4Shelg
280e9b8da4Shelg return (0);
290e9b8da4Shelg }
300e9b8da4Shelg
310e9b8da4Shelg static int
test_all_args(char ** dir,int * multithreaded,int * foreground)320e9b8da4Shelg test_all_args(char **dir, int *multithreaded, int *foreground)
330e9b8da4Shelg {
340e9b8da4Shelg char *argv[] = {
350e9b8da4Shelg "progname",
360e9b8da4Shelg "-odebug",
370e9b8da4Shelg /* read-only mount not supported yet */
380e9b8da4Shelg /*fuse_opt_add_arg(args, "-odebug,ro");*/
390e9b8da4Shelg /*fuse_opt_add_arg(args, "-r");*/
400e9b8da4Shelg "-d",
410e9b8da4Shelg "-f",
420e9b8da4Shelg "/mnt",
430e9b8da4Shelg "-s"
440e9b8da4Shelg };
450e9b8da4Shelg struct fuse_args args = FUSE_ARGS_INIT(6, argv);
460e9b8da4Shelg
470e9b8da4Shelg if (dir != NULL)
480e9b8da4Shelg *dir = NULL;
490e9b8da4Shelg
500e9b8da4Shelg if (multithreaded != NULL)
510e9b8da4Shelg *multithreaded = 0;
520e9b8da4Shelg
530e9b8da4Shelg if (foreground != NULL)
540e9b8da4Shelg *foreground = 0;
550e9b8da4Shelg
560e9b8da4Shelg if (fuse_parse_cmdline(&args, dir, multithreaded, foreground) != 0)
570e9b8da4Shelg exit (__LINE__);
580e9b8da4Shelg
590e9b8da4Shelg if (dir != NULL && strcmp(*dir, "/mnt") != 0)
600e9b8da4Shelg exit(__LINE__);
610e9b8da4Shelg if (multithreaded != NULL && *multithreaded == 1)
620e9b8da4Shelg exit(__LINE__);
630e9b8da4Shelg if (foreground != NULL && *foreground == 0)
640e9b8da4Shelg exit(__LINE__);
650e9b8da4Shelg
660e9b8da4Shelg if (args.argc != 1)
670e9b8da4Shelg exit(__LINE__);
680e9b8da4Shelg if (strcmp(args.argv[0], "progname") != 0)
690e9b8da4Shelg exit(__LINE__);
700e9b8da4Shelg
710e9b8da4Shelg return (0);
720e9b8da4Shelg }
730e9b8da4Shelg
740e9b8da4Shelg int
main(void)750e9b8da4Shelg main(void)
760e9b8da4Shelg {
770e9b8da4Shelg char *dir;
780e9b8da4Shelg int multithreaded, foreground;
790e9b8da4Shelg
800e9b8da4Shelg test_null_args();
810e9b8da4Shelg test_all_args(NULL, NULL, NULL);
820e9b8da4Shelg test_all_args(&dir, NULL, NULL);
830e9b8da4Shelg test_all_args(&dir, &multithreaded, NULL);
840e9b8da4Shelg test_all_args(&dir, &multithreaded, &foreground);
850e9b8da4Shelg
860e9b8da4Shelg return (0);
870e9b8da4Shelg }
88