From 49f3e46bb8b2f23b3267a70318605adf50b5903f Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Sat, 29 Sep 2018 16:54:33 +0300
Subject: [PATCH] allow command line argument order used by mount(8)

The mount spec and directory are passed as the first and second
arguments to the helper, followed by the options.

The current implementation works on glibc but fails on POSIX-conforming
C libraries such as musl.
---
 fuse/main.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/fuse/main.c b/fuse/main.c
index c645390..50b6787 100644
--- a/fuse/main.c
+++ b/fuse/main.c
@@ -512,9 +512,17 @@ static int fuse_exfat_main(char* mount_options, char* mount_point)
 			&fuse_exfat_ops, NULL);
 }
 
+static void read_arg(char **param, int *argc, char ***argv) {
+	if (!*param && *argc > optind && (*argv)[optind][0] != '-') {
+		*param = (*argv)[optind];
+		((*argv)++)[1] = (*argv)[0];
+		(*argc)--;
+	}
+}
+
 int main(int argc, char* argv[])
 {
-	const char* spec = NULL;
+	char* spec = NULL;
 	char* mount_point = NULL;
 	char* fuse_options;
 	char* exfat_options;
@@ -523,6 +531,9 @@ int main(int argc, char* argv[])
 
 	printf("FUSE exfat %s\n", VERSION);
 
+	read_arg(&spec, &argc, &argv);
+	read_arg(&mount_point, &argc, &argv);
+
 	fuse_options = strdup("allow_other,"
 #if defined(__linux__) || defined(__FreeBSD__)
 			"big_writes,"
@@ -573,15 +584,16 @@ int main(int argc, char* argv[])
 			usage(argv[0]);
 			break;
 		}
+
+		read_arg(&spec, &argc, &argv);
+		read_arg(&mount_point, &argc, &argv);
 	}
-	if (argc - optind != 2)
+	if (!mount_point || argc > optind)
 	{
 		free(exfat_options);
 		free(fuse_options);
 		usage(argv[0]);
 	}
-	spec = argv[optind];
-	mount_point = argv[optind + 1];
 
 	if (exfat_mount(&ef, spec, exfat_options) != 0)
 	{
-- 
2.14.4

