X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fmount%2Fparse_opt.c;h=ab869d901d12ba66d0b26b1ac46a23e0d5d90f4e;hp=493450859f2235714caaca5391496f8eed85a588;hb=cf5b38e707b629540b5123124228311a620e3dce;hpb=0dcb83a870926de215307472676096056dabc9b0 diff --git a/utils/mount/parse_opt.c b/utils/mount/parse_opt.c index 4934508..ab869d9 100644 --- a/utils/mount/parse_opt.c +++ b/utils/mount/parse_opt.c @@ -101,6 +101,37 @@ fail: return NULL; } +static struct mount_option *option_dup(const struct mount_option *option) +{ + struct mount_option *new; + + new = malloc(sizeof(*new)); + if (!new) + return NULL; + + new->next = NULL; + new->prev = NULL; + + new->keyword = strdup(option->keyword); + if (!new->keyword) + goto fail; + + new->value = NULL; + if (option->value) { + new->value = strdup(option->value); + if (!new->value) { + free(new->keyword); + goto fail; + } + } + + return new; + +fail: + free(new); + return NULL; +} + static void option_destroy(struct mount_option *option) { free(option->keyword); @@ -228,6 +259,40 @@ fail: return NULL; } +/** + * po_dup - duplicate an existing list of options + * @options: pointer to mount options + * + */ +struct mount_options *po_dup(struct mount_options *source) +{ + struct mount_options *target; + struct mount_option *current; + + if (!source) + return NULL; + + target = options_create(); + if (options_empty(source) || target == NULL) + return target; + + current = source->head; + while (target->count < source->count) { + struct mount_option *option; + + option = option_dup(current); + if (!option) { + po_destroy(target); + return NULL; + } + + options_tail_insert(target, option); + current = current->next; + } + + return target; +} + /** * po_replace - replace mount options in one mount_options object with another * @target: pointer to previously instantiated object to replace @@ -437,12 +502,13 @@ po_found_t po_get_numeric(struct mount_options *options, char *keyword, long *va * as "proto=," "udp" and "tcp." * * Returns the index into @keys of the option that is rightmost. - * If none of the options are present, returns zero. + * If none of the options listed in @keys is present in @options, or + * if @options is NULL, returns -1. */ -unsigned int po_rightmost(struct mount_options *options, const char *keys[]) +int po_rightmost(struct mount_options *options, const char *keys[]) { struct mount_option *option; - unsigned int i; + int i; if (options) { for (option = options->tail; option; option = option->prev) { @@ -452,7 +518,7 @@ unsigned int po_rightmost(struct mount_options *options, const char *keys[]) } } - return 0; + return -1; } /**