Module Name: src Committed By: pho Date: Mon Nov 14 17:19:29 UTC 2016
Modified Files: src/lib/librefuse: fuse_opt.h refuse.3 refuse_opt.c src/tests/lib/librefuse: t_refuse_opt.c Log Message: Implement missing fuse_opt_add_opt(3) and fuse_opt_add_opt_escaped(3) To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/lib/librefuse/fuse_opt.h cvs rdiff -u -r1.9 -r1.10 src/lib/librefuse/refuse.3 cvs rdiff -u -r1.15 -r1.16 src/lib/librefuse/refuse_opt.c cvs rdiff -u -r1.1 -r1.2 src/tests/lib/librefuse/t_refuse_opt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/librefuse/fuse_opt.h diff -u src/lib/librefuse/fuse_opt.h:1.6 src/lib/librefuse/fuse_opt.h:1.7 --- src/lib/librefuse/fuse_opt.h:1.6 Fri Jan 22 22:39:29 2016 +++ src/lib/librefuse/fuse_opt.h Mon Nov 14 17:19:29 2016 @@ -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_arg 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 *); Index: src/lib/librefuse/refuse.3 diff -u src/lib/librefuse/refuse.3:1.9 src/lib/librefuse/refuse.3:1.10 --- src/lib/librefuse/refuse.3:1.9 Tue Mar 18 18:20:38 2014 +++ src/lib/librefuse/refuse.3 Mon Nov 14 17:19:29 2016 @@ -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" Index: src/lib/librefuse/refuse_opt.c diff -u src/lib/librefuse/refuse_opt.c:1.15 src/lib/librefuse/refuse_opt.c:1.16 --- src/lib/librefuse/refuse_opt.c:1.15 Tue Mar 1 11:23:42 2011 +++ src/lib/librefuse/refuse_opt.c Mon Nov 14 17:19:29 2016 @@ -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 *ar 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); } /* Index: src/tests/lib/librefuse/t_refuse_opt.c diff -u src/tests/lib/librefuse/t_refuse_opt.c:1.1 src/tests/lib/librefuse/t_refuse_opt.c:1.2 --- src/tests/lib/librefuse/t_refuse_opt.c:1.1 Mon Nov 14 16:10:31 2016 +++ src/tests/lib/librefuse/t_refuse_opt.c Mon Nov 14 17:19:29 2016 @@ -1,12 +1,9 @@ -/* $NetBSD: t_refuse_opt.c,v 1.1 2016/11/14 16:10:31 pho Exp $ */ +/* $NetBSD: t_refuse_opt.c,v 1.2 2016/11/14 17:19:29 pho Exp $ */ /*- - * Copyright (c) 2011 The NetBSD Foundation, Inc. + * Copyright (c) 2016 The NetBSD Foundation, Inc. * All rights reserved. * - * This code is derived from software contributed to The NetBSD Foundation - * by Jukka Ruohonen. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -29,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include <sys/cdefs.h> -__RCSID("$NetBSD: t_refuse_opt.c,v 1.1 2016/11/14 16:10:31 pho Exp $"); +__RCSID("$NetBSD: t_refuse_opt.c,v 1.2 2016/11/14 17:19:29 pho Exp $"); #include <atf-c.h> @@ -85,13 +82,28 @@ ATF_TC_BODY(efuse_opt_add_opt, tc) { char* opt = NULL; - atf_tc_expect_death("fuse_opt_add_opt(3) is not implemented yet"); + RZ(fuse_opt_add_opt(&opt, "fo\\o")); + ATF_CHECK_STREQ(opt, "fo\\o"); + + RZ(fuse_opt_add_opt(&opt, "ba,r")); + ATF_CHECK_STREQ(opt, "fo\\o,ba,r"); +} + +ATF_TC(efuse_opt_add_opt_escaped); +ATF_TC_HEAD(efuse_opt_add_opt_escaped, tc) +{ + atf_tc_set_md_var(tc, "descr", "Check that fuse_opt_add_opt_escaped(3) works"); +} + +ATF_TC_BODY(efuse_opt_add_opt_escaped, tc) +{ + char* opt = NULL; - RZ(fuse_opt_add_opt(&opt, "foo")); - ATF_CHECK_STREQ(opt, "foo"); + RZ(fuse_opt_add_opt_escaped(&opt, "fo\\o")); + ATF_CHECK_STREQ(opt, "fo\\\\o"); - RZ(fuse_opt_add_opt(&opt, "b\\a,r")); - ATF_CHECK_STREQ(opt, "foo,b\\a,r"); + RZ(fuse_opt_add_opt_escaped(&opt, "ba,r")); + ATF_CHECK_STREQ(opt, "fo\\\\o,ba\\,r"); } ATF_TP_ADD_TCS(tp) @@ -99,6 +111,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, efuse_opt_add_arg); ATF_TP_ADD_TC(tp, efuse_opt_insert_arg); ATF_TP_ADD_TC(tp, efuse_opt_add_opt); + ATF_TP_ADD_TC(tp, efuse_opt_add_opt_escaped); return atf_no_error(); }