aboutsummaryrefslogtreecommitdiff
path: root/lib/fuse_opt.c
diff options
context:
space:
mode:
authorGravatar Miklos Szeredi <miklos@szeredi.hu>2006-01-06 18:29:40 +0000
committerGravatar Miklos Szeredi <miklos@szeredi.hu>2006-01-06 18:29:40 +0000
commit95da860d29a54c6dc21683a34edefead597e3bbc (patch)
treeac1df7de0b985741e97169b2e3233ab1267cfdd5 /lib/fuse_opt.c
parent1f6a5346406a620071ae6a659d5a75cd5220a128 (diff)
fix
Diffstat (limited to 'lib/fuse_opt.c')
-rw-r--r--lib/fuse_opt.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/lib/fuse_opt.c b/lib/fuse_opt.c
index d1b3259..2ac499c 100644
--- a/lib/fuse_opt.c
+++ b/lib/fuse_opt.c
@@ -1,6 +1,6 @@
/*
FUSE: Filesystem in Userspace
- Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu>
+ Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu>
This program can be distributed under the terms of the GNU LGPL.
See the file COPYING.LIB
@@ -27,12 +27,13 @@ struct fuse_opt_context {
void fuse_opt_free_args(struct fuse_args *args)
{
- if (args && args->argv) {
+ if (args && args->argv && args->allocated) {
int i;
for (i = 0; i < args->argc; i++)
free(args->argv[i]);
free(args->argv);
args->argv = NULL;
+ args->allocated = 0;
}
}
@@ -44,12 +45,18 @@ static int alloc_failed(void)
int fuse_opt_add_arg(struct fuse_args *args, const char *arg)
{
- char **newargv = realloc(args->argv, (args->argc + 2) * sizeof(char *));
- char *newarg = newargv ? strdup(arg) : NULL;
+ char **newargv;
+ char *newarg;
+
+ assert(!args->argv || args->allocated);
+
+ newargv = realloc(args->argv, (args->argc + 2) * sizeof(char *));
+ newarg = newargv ? strdup(arg) : NULL;
if (!newargv || !newarg)
return alloc_failed();
args->argv = newargv;
+ args->allocated = 1;
args->argv[args->argc++] = newarg;
args->argv[args->argc] = NULL;
return 0;
@@ -183,7 +190,7 @@ static int process_opt(struct fuse_opt_context *ctx,
const struct fuse_opt *opt, unsigned sep,
const char *arg, int iso)
{
- if (opt->offset == FUSE_OPT_OFFSET_KEY) {
+ if (opt->offset == -1U) {
if (call_proc(ctx, arg, opt->value, iso) == -1)
return -1;
} else {
@@ -324,27 +331,29 @@ static int opt_parse(struct fuse_opt_context *ctx)
return 0;
}
-int fuse_opt_parse(int argc, char *argv[], void *data,
- const struct fuse_opt opts[], fuse_opt_proc_t proc,
- struct fuse_args *outargs)
+int fuse_opt_parse(struct fuse_args *args, void *data,
+ const struct fuse_opt opts[], fuse_opt_proc_t proc)
{
int res;
struct fuse_opt_context ctx = {
- .argc = argv ? argc : outargs->argc,
- .argv = argv ? argv : outargs->argv,
.data = data,
.opt = opts,
.proc = proc,
};
+ if (!args || !args->argv || !args->argc)
+ return 0;
+
+ ctx.argc = args->argc;
+ ctx.argv = args->argv;
+
res = opt_parse(&ctx);
- if (!argv)
- fuse_opt_free_args(outargs);
+ if (res != -1) {
+ struct fuse_args tmp = *args;
+ *args = ctx.outargs;
+ ctx.outargs = tmp;
+ }
free(ctx.opts);
- if (res != -1 && outargs)
- *outargs = ctx.outargs;
- else
- fuse_opt_free_args(&ctx.outargs);
-
+ fuse_opt_free_args(&ctx.outargs);
return res;
}