Mostly just typos. Corrected the example some. However, please see below. I 
don't
think the example works or I'm just doing something wrong.

Index: fuse_opt.3
===================================================================
RCS file: /cvs/src/lib/libfuse/fuse_opt.3,v
retrieving revision 1.2
diff -u -p -u -r1.2 fuse_opt.3
--- fuse_opt.3  8 Jul 2018 06:17:10 -0000       1.2
+++ fuse_opt.3  29 Nov 2018 13:27:26 -0000
@@ -224,7 +224,7 @@ automatically depending on the format of
 If
 .Fa proc
 is not NULL, then this is called for any argument that matches a template
-with that has
+that has
 .Fa val
 = FUSE_OPT_KEY.
 .Fa opts
@@ -275,35 +275,34 @@ returns 1 on match, 0 if no match.
 .Sh EXAMPLES
 .Bd -literal -offset indent
 struct foo_config {
-       char *foor;
+       char *foo;
        int bar;
-};
+} config;
 
-#define FOO_OPT(t, m) {t, offsetof(struct foo_config, m), 1}
+#define FOO_OPT(t, m) { t, offsetof(struct foo_config, m), 1 }
 
 struct fuse_opt opts[] {
-       FUSE_OPT_KEY("--foo ",  KEY_FOO),
-       FOO_OPT("-b",           bar),
-       FOO_OPT("gid=",         set_gid), /* set to 1 if present */
-       FOO_OPT("gid=%u",       gid),   /* set to parsed value of %u */
+       FUSE_OPT_KEY("--foo %s",        KEY_FOO),
+       FOO_OPT("-b",                   bar),
+       FOO_OPT("gid=",                 set_gid), /* set to 1 if present */
+       FOO_OPT("gid=%u",               gid),     /* set to parsed value of %u 
*/
        FUSE_OPT_END
 }
 
 int
-foo_process_proc(void *data, int key, char *val, struct fuse_args *args)
+foo_process_proc(void *data, const char *val, int key, struct fuse_args *args)
 {
-       foo_cofig *conf = data;
+       foo_config *conf = data;
 
-       switch(key)
-       {
+       switch(key) {
        case KEY_FOO:
                /* Do something... */
-               conf.foo = val;
+               conf->foo = val;
                return (0); /* discard */
+       default:
+               /* didn't process so keep the option */
+               return (1);
        }
-
-       /* didn't process so keep the option */
-       return (1);
 }
 
 int
@@ -311,7 +310,7 @@ main(int argc, char *argv[])
 {
        struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
 
-       if (fuse_opt_parse(opts, config, foo_process_proc) != 0) {
+       if (fuse_opt_parse(opts, &config, opts, foo_process_proc) != 0) {
        ...
 .Ed
 .Sh ERRORS

Here was my test to ensure the above worked.

#include <errno.h>
#include <fuse.h>
#include <fuse_opt.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

struct fuse_operations fsops = {
};

struct fuse_config {
        char *string;
        int num;
} config;

#define TEST_FUSE_OPT(t, m)                                     \
        { t, offsetof(struct fuse_config, m), 1 }

enum {
        KEY_STRING,
};

static struct fuse_opt opts[] = {
        /* with "--s " this test gives the following output 
         * config.string = --sstring
         * config.num = 1
         * fuse: bad mount point string : No such file or directory
         */
        FUSE_OPT_KEY("--s %s", KEY_STRING),
        TEST_FUSE_OPT("--n", num), /* should set num to 1 */
        FUSE_OPT_END
};

static int
fuse_opt_cb(void *data, const char *val, int key, struct fuse_args *outargs)
{
        struct fuse_config *conf = data;

        switch (key) {
        case KEY_STRING:
                /* I had to use strdup. conf->string = val didn't seem to work 
*/
                conf->string = strdup(val); 
                return (0);
        default:
                break;
        }

        return (1);
}

int
main(int argc, char *argv[])
{
        struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
        int rv;

        if (fuse_opt_parse(&args, &config, opts, fuse_opt_cb) == -1)
                return(1);

        fprintf(stderr, "config.string = %s\n", config.string);
        fprintf(stderr, "config.num = %d\n", config.num);

        rv = fuse_main(argc, argv, &fsops, NULL);

        fuse_opt_free_args(&args);

        return(rv);
}

clang -o fuse fuse.c -lfuse /* I know creative */

$ mkdir /tmp/test
$ doas ./fuse -d --n --s string /tmp/test
config.string = string
config.num = 1
fuse: bad mount point string : No such file or directory

Thanks,

Edgar

Reply via email to