diff options
| author | pho <pho@NetBSD.org> | 2016-11-14 17:19:29 +0000 |
|---|---|---|
| committer | pho <pho@NetBSD.org> | 2016-11-14 17:19:29 +0000 |
| commit | 5a307a76ee40da555c6ad3a46643dfe13885c093 (patch) | |
| tree | c5c151df43996301c4e267687af58e516b01c3c8 /lib/librefuse | |
| parent | 2e5fe1337b2826eb05cb436bd40e144b881ae1f4 (diff) | |
Implement missing fuse_opt_add_opt(3) and fuse_opt_add_opt_escaped(3)
Diffstat (limited to 'lib/librefuse')
| -rw-r--r-- | lib/librefuse/fuse_opt.h | 3 | ||||
| -rw-r--r-- | lib/librefuse/refuse.3 | 24 | ||||
| -rw-r--r-- | lib/librefuse/refuse_opt.c | 55 |
3 files changed, 61 insertions, 21 deletions
diff --git a/lib/librefuse/fuse_opt.h b/lib/librefuse/fuse_opt.h index fe77abf4932..dd010734f50 100644 --- a/lib/librefuse/fuse_opt.h +++ b/lib/librefuse/fuse_opt.h @@ -1,4 +1,4 @@ -/* $NetBSD: fuse_opt.h,v 1.6 2016/01/22 22:39:29 dholland Exp $ */ +/* $NetBSD: fuse_opt.h,v 1.7 2016/11/14 17:19:29 pho Exp $ */ /* * Copyright (c) 2007 Alistair Crooks. All rights reserved. @@ -61,6 +61,7 @@ struct fuse_args *fuse_opt_deep_copy_args(int, char **); void fuse_opt_free_args(struct fuse_args *); int fuse_opt_insert_arg(struct fuse_args *, int, const char *); int fuse_opt_add_opt(char **, const char *); +int fuse_opt_add_opt_escaped(char **, const char *); int fuse_opt_parse(struct fuse_args *, void *, const struct fuse_opt *, fuse_opt_proc_t); int fuse_opt_match(const struct fuse_opt *, const char *); diff --git a/lib/librefuse/refuse.3 b/lib/librefuse/refuse.3 index 7fc767af457..03f4b25d0dd 100644 --- a/lib/librefuse/refuse.3 +++ b/lib/librefuse/refuse.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: refuse.3,v 1.9 2014/03/18 18:20:38 riastradh Exp $ +.\" $NetBSD: refuse.3,v 1.10 2016/11/14 17:19:29 pho Exp $ .\" .\" Copyright © 2007 Alistair Crooks. All rights reserved. .\" @@ -26,7 +26,7 @@ .\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd April 30, 2007 +.Dd November 15, 2016 .Dt REFUSE 3 .Os .Sh NAME @@ -40,11 +40,31 @@ .Fo fuse_main .Fa "int argc" "char **argv" "const struct fuse_operations *" .Fc +.Ft struct fuse_args +.Fo FUSE_ARGS_INIT +.Fa "int argc" "char **argv" +.Fc .Ft int .Fo fuse_opt_add_arg .Fa "struct fuse_args *args" "const char *arg" .Fc .Ft int +.Fo fuse_opt_add_opt +.Fa "char **opts" "const char *opt" +.Fc +.Ft int +.Fo fuse_opt_add_opt_escaped +.Fa "char **opts" "const char *opt" +.Fc +.Ft void +.Fo fuse_opt_free_args +.Fa "struct fuse_args *args" +.Fc +.Ft int +.Fo fuse_opt_insert_arg +.Fa "struct fuse_args *args" "int pos" "const char *arg" +.Fc +.Ft int .Fo fuse_opt_parse .Fa "struct fuse_args *args" "void *userdata" .Fa "const struct fuse_opt *descriptions" "fuse_opt_proc_t processingfunc" diff --git a/lib/librefuse/refuse_opt.c b/lib/librefuse/refuse_opt.c index 5b222585d86..e5fc0d62f08 100644 --- a/lib/librefuse/refuse_opt.c +++ b/lib/librefuse/refuse_opt.c @@ -1,4 +1,4 @@ -/* $NetBSD: refuse_opt.c,v 1.15 2011/03/01 11:23:42 soda Exp $ */ +/* $NetBSD: refuse_opt.c,v 1.16 2016/11/14 17:19:29 pho Exp $ */ /*- * Copyright (c) 2007 Juan Romero Pardines. @@ -39,6 +39,7 @@ #include <err.h> #include <fuse.h> #include <fuse_opt.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -64,22 +65,8 @@ struct fuse_opt_option { static int fuse_opt_popt(struct fuse_opt_option *, const struct fuse_opt *); -/* +/* * Public API. - * - * The following functions always return 0: - * - * int fuse_opt_add_opt(char **, const char *); - * - * We implement the next ones: - * - * int fuse_opt_add_arg(struct fuse_args *, const char *); - * void fuse_opt_free_args(struct fuse_args *); - * int fuse_opt_insert_arg(struct fuse_args *, const char *); - * int fuse_opt_match(const struct fuse_opt *, const char *); - * int fuse_opt_parse(struct fuse_args *, void *, - * const struct fuse_opt *, fuse_opt_proc_t); - * */ /* ARGSUSED */ @@ -180,12 +167,44 @@ fuse_opt_insert_arg(struct fuse_args *args, int pos, const char *arg) return 0; } -/* ARGSUSED */ +static int add_opt(char **opts, const char *opt, bool escape) +{ + const size_t orig_len = *opts == NULL ? 0 : strlen(*opts); + char* buf = realloc(*opts, orig_len + 1 + strlen(opt) * 2 + 1); + + if (buf == NULL) { + return -1; + } + *opts = buf; + + if (orig_len > 0) { + buf += orig_len; + *buf++ = ','; + } + + for (; *opt; opt++) { + if (escape && (*opt == ',' || *opt == '\\')) { + *buf++ = '\\'; + } + *buf++ = *opt; + } + *buf = '\0'; + + return 0; +} + int fuse_opt_add_opt(char **opts, const char *opt) { DPRINTF(("%s: arguments passed: [opts=%s] [opt=%s]\n", __func__, *opts, opt)); - return 0; + return add_opt(opts, opt, false); +} + +int fuse_opt_add_opt_escaped(char **opts, const char *opt) +{ + DPRINTF(("%s: arguments passed: [opts=%s] [opt=%s]\n", + __func__, *opts, opt)); + return add_opt(opts, opt, true); } /* |
