Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Implement missing fuse_opt_add_opt(3) and fuse_opt_add_opt_e...
details: https://anonhg.NetBSD.org/src/rev/d22c44921634
branches: trunk
changeset: 348897:d22c44921634
user: pho <pho%NetBSD.org@localhost>
date: Mon Nov 14 17:19:29 2016 +0000
description:
Implement missing fuse_opt_add_opt(3) and fuse_opt_add_opt_escaped(3)
diffstat:
lib/librefuse/fuse_opt.h | 3 +-
lib/librefuse/refuse.3 | 24 +++++++++++++++-
lib/librefuse/refuse_opt.c | 55 +++++++++++++++++++++++++------------
tests/lib/librefuse/t_refuse_opt.c | 35 ++++++++++++++++-------
4 files changed, 85 insertions(+), 32 deletions(-)
diffs (224 lines):
diff -r e27d7122b12a -r d22c44921634 lib/librefuse/fuse_opt.h
--- a/lib/librefuse/fuse_opt.h Mon Nov 14 16:10:31 2016 +0000
+++ b/lib/librefuse/fuse_opt.h Mon Nov 14 17:19:29 2016 +0000
@@ -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 @@
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 -r e27d7122b12a -r d22c44921634 lib/librefuse/refuse.3
--- a/lib/librefuse/refuse.3 Mon Nov 14 16:10:31 2016 +0000
+++ b/lib/librefuse/refuse.3 Mon Nov 14 17:19:29 2016 +0000
@@ -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 -r e27d7122b12a -r d22c44921634 lib/librefuse/refuse_opt.c
--- a/lib/librefuse/refuse_opt.c Mon Nov 14 16:10:31 2016 +0000
+++ b/lib/librefuse/refuse_opt.c Mon Nov 14 17:19:29 2016 +0000
@@ -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 @@
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 @@
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);
}
/*
diff -r e27d7122b12a -r d22c44921634 tests/lib/librefuse/t_refuse_opt.c
--- a/tests/lib/librefuse/t_refuse_opt.c Mon Nov 14 16:10:31 2016 +0000
+++ b/tests/lib/librefuse/t_refuse_opt.c Mon Nov 14 17:19:29 2016 +0000
@@ -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 @@
{
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");
+}
- RZ(fuse_opt_add_opt(&opt, "foo"));
- ATF_CHECK_STREQ(opt, "foo");
+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");
+}
- RZ(fuse_opt_add_opt(&opt, "b\\a,r"));
- ATF_CHECK_STREQ(opt, "foo,b\\a,r");
+ATF_TC_BODY(efuse_opt_add_opt_escaped, tc)
+{
+ char* opt = NULL;
+
+ RZ(fuse_opt_add_opt_escaped(&opt, "fo\\o"));
+ ATF_CHECK_STREQ(opt, "fo\\\\o");
+
+ 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_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();
}
Home |
Main Index |
Thread Index |
Old Index