1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2015 Zbigniew Jędrzejewski-Szmek
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "fstab-util.h"
26 int fstab_filter_options(const char *opts, const char *names,
27 const char **namefound, char **value, char **filtered) {
28 const char *name, *n = NULL, *x;
29 _cleanup_strv_free_ char **stor = NULL;
30 _cleanup_free_ char *v = NULL, **strv = NULL;
32 assert(names && *names);
37 /* If !value and !filtered, this function is not allowed to fail. */
40 const char *word, *state;
43 FOREACH_WORD_SEPARATOR(word, l, opts, ",", state)
44 NULSTR_FOREACH(name, names) {
47 if (!strneq(word, name, strlen(name)))
50 /* we know that the string is NUL
51 * terminated, so *x is valid */
52 x = word + strlen(name);
53 if (IN_SET(*x, '\0', '=', ',')) {
57 if (IN_SET(*x, '\0', ','))
62 v = strndup(x, l - strlen(name) - 1);
72 stor = strv_split(opts, ",");
75 strv = memdup(stor, sizeof(char*) * (strv_length(stor) + 1));
79 for (s = t = strv; *s; s++) {
80 NULSTR_FOREACH(name, names) {
81 x = startswith(*s, name);
82 if (x && IN_SET(*x, '\0', '='))
90 /* Keep the last occurence found */
114 f = strv_join(strv, ",");
128 int fstab_find_pri(const char *options, int *ret) {
129 _cleanup_free_ char *opt = NULL;
135 r = fstab_filter_options(options, "pri\0", NULL, &opt, NULL);
141 r = safe_atou(opt, &pri);