2 * Commandline option parsing functions
4 * Copyright (c) 2003-2008 Fabrice Bellard
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 #include "qemu-common.h"
30 #include "qemu/error-report.h"
31 #include "qapi/qmp/types.h"
32 #include "qapi/error.h"
33 #include "qapi/qmp/qerror.h"
34 #include "qemu/option_int.h"
37 * Extracts the name of an option from the parameter string (p points at the
38 * first byte of the option name)
40 * The option name is delimited by delim (usually , or =) or the string end
41 * and is copied into buf. If the option name is longer than buf_size, it is
42 * truncated. buf is always zero terminated.
44 * The return value is the position of the delimiter/zero byte after the option
47 const char *get_opt_name(char *buf, int buf_size, const char *p, char delim)
52 while (*p != '\0' && *p != delim) {
53 if (q && (q - buf) < buf_size - 1)
64 * Extracts the value of an option from the parameter string p (p points at the
65 * first byte of the option value)
67 * This function is comparable to get_opt_name with the difference that the
68 * delimiter is fixed to be comma which starts a new option. To specify an
69 * option value that contains commas, double each comma.
71 const char *get_opt_value(char *buf, int buf_size, const char *p)
82 if (q && (q - buf) < buf_size - 1)
92 int get_next_param_value(char *buf, int buf_size,
93 const char *tag, const char **pstr)
100 p = get_opt_name(option, sizeof(option), p, '=');
104 if (!strcmp(tag, option)) {
105 *pstr = get_opt_value(buf, buf_size, p);
111 p = get_opt_value(NULL, 0, p);
120 int get_param_value(char *buf, int buf_size,
121 const char *tag, const char *str)
123 return get_next_param_value(buf, buf_size, tag, &str);
127 * Searches an option list for an option with the given name
129 QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
132 while (list && list->name) {
133 if (!strcmp(list->name, name)) {
142 static void parse_option_bool(const char *name, const char *value, bool *ret,
146 if (!strcmp(value, "on")) {
148 } else if (!strcmp(value, "off")) {
151 error_set(errp,QERR_INVALID_PARAMETER_VALUE, name, "'on' or 'off'");
158 static void parse_option_number(const char *name, const char *value,
159 uint64_t *ret, Error **errp)
165 number = strtoull(value, &postfix, 0);
166 if (*postfix != '\0') {
167 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number");
172 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number");
176 void parse_option_size(const char *name, const char *value,
177 uint64_t *ret, Error **errp)
183 sizef = strtod(value, &postfix);
200 *ret = (uint64_t) sizef;
203 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a size");
204 #if 0 /* conversion from qerror_report() to error_set() broke this: */
205 error_printf_unless_qmp("You may use k, M, G or T suffixes for "
206 "kilobytes, megabytes, gigabytes and terabytes.\n");
211 error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a size");
216 * Sets the value of a parameter in a given option list. The parsing of the
217 * value depends on the type of option:
219 * OPT_FLAG (uses value.n):
220 * If no value is given, the flag is set to 1.
221 * Otherwise the value must be "on" (set to 1) or "off" (set to 0)
223 * OPT_STRING (uses value.s):
224 * value is strdup()ed and assigned as option value
226 * OPT_SIZE (uses value.n):
227 * The value is converted to an integer. Suffixes for kilobytes etc. are
228 * allowed (powers of 1024).
230 * Returns 0 on succes, -1 in error cases
232 int set_option_parameter(QEMUOptionParameter *list, const char *name,
236 Error *local_err = NULL;
238 // Find a matching parameter
239 list = get_option_parameter(list, name);
241 fprintf(stderr, "Unknown option '%s'\n", name);
246 switch (list->type) {
248 parse_option_bool(name, value, &flag, &local_err);
250 list->value.n = flag;
256 list->value.s = g_strdup(value);
258 fprintf(stderr, "Option '%s' needs a parameter\n", name);
264 parse_option_size(name, value, &list->value.n, &local_err);
268 fprintf(stderr, "Bug: Option '%s' has an unknown type\n", name);
273 qerror_report_err(local_err);
274 error_free(local_err);
278 list->assigned = true;
284 * Sets the given parameter to an integer instead of a string.
285 * This function cannot be used to set string options.
287 * Returns 0 on success, -1 in error cases
289 int set_option_parameter_int(QEMUOptionParameter *list, const char *name,
292 // Find a matching parameter
293 list = get_option_parameter(list, name);
295 fprintf(stderr, "Unknown option '%s'\n", name);
300 switch (list->type) {
304 list->value.n = value;
311 list->assigned = true;
317 * Frees a option list. If it contains strings, the strings are freed as well.
319 void free_option_parameters(QEMUOptionParameter *list)
321 QEMUOptionParameter *cur = list;
323 while (cur && cur->name) {
324 if (cur->type == OPT_STRING) {
325 g_free(cur->value.s);
334 * Count valid options in list
336 static size_t count_option_parameters(QEMUOptionParameter *list)
338 size_t num_options = 0;
340 while (list && list->name) {
349 * Append an option list (list) to an option list (dest).
351 * If dest is NULL, a new copy of list is created.
353 * Returns a pointer to the first element of dest (or the newly allocated copy)
355 QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest,
356 QEMUOptionParameter *list)
358 size_t num_options, num_dest_options;
360 num_options = count_option_parameters(dest);
361 num_dest_options = num_options;
363 num_options += count_option_parameters(list);
365 dest = g_realloc(dest, (num_options + 1) * sizeof(QEMUOptionParameter));
366 dest[num_dest_options].name = NULL;
368 while (list && list->name) {
369 if (get_option_parameter(dest, list->name) == NULL) {
370 dest[num_dest_options++] = *list;
371 dest[num_dest_options].name = NULL;
380 * Parses a parameter string (param) into an option list (dest).
382 * list is the template option list. If dest is NULL, a new copy of list is
383 * created. If list is NULL, this function fails.
385 * A parameter string consists of one or more parameters, separated by commas.
386 * Each parameter consists of its name and possibly of a value. In the latter
387 * case, the value is delimited by an = character. To specify a value which
388 * contains commas, double each comma so it won't be recognized as the end of
391 * For more details of the parsing see above.
393 * Returns a pointer to the first element of dest (or the newly allocated copy)
394 * or NULL in error cases
396 QEMUOptionParameter *parse_option_parameters(const char *param,
397 QEMUOptionParameter *list, QEMUOptionParameter *dest)
399 QEMUOptionParameter *allocated = NULL;
402 char *param_delim, *value_delim;
411 dest = allocated = append_option_parameters(NULL, list);
414 for (i = 0; dest[i].name; i++) {
415 dest[i].assigned = false;
420 // Find parameter name and value in the string
421 param_delim = strchr(param, ',');
422 value_delim = strchr(param, '=');
424 if (value_delim && (value_delim < param_delim || !param_delim)) {
431 param = get_opt_name(name, sizeof(name), param, next_delim);
433 param = get_opt_value(value, sizeof(value), param + 1);
435 if (*param != '\0') {
440 if (set_option_parameter(dest, name, value_delim ? value : NULL)) {
448 // Only free the list if it was newly allocated
449 free_option_parameters(allocated);
453 bool has_help_option(const char *param)
455 size_t buflen = strlen(param) + 1;
456 char *buf = g_malloc0(buflen);
457 const char *p = param;
461 p = get_opt_value(buf, buflen, p);
466 if (is_help_option(buf)) {
477 bool is_valid_option_list(const char *param)
479 size_t buflen = strlen(param) + 1;
480 char *buf = g_malloc0(buflen);
481 const char *p = param;
485 p = get_opt_value(buf, buflen, p);
491 if (!*buf || *buf == ',') {
503 * Prints all options of a list that have a value to stdout
505 void print_option_parameters(QEMUOptionParameter *list)
507 while (list && list->name) {
508 switch (list->type) {
510 if (list->value.s != NULL) {
511 printf("%s='%s' ", list->name, list->value.s);
515 printf("%s=%s ", list->name, list->value.n ? "on" : "off");
519 printf("%s=%" PRId64 " ", list->name, list->value.n);
522 printf("%s=(unknown type) ", list->name);
530 * Prints an overview of all available options
532 void print_option_help(QEMUOptionParameter *list)
534 printf("Supported options:\n");
535 while (list && list->name) {
536 printf("%-16s %s\n", list->name,
537 list->help ? list->help : "No description available");
542 /* ------------------------------------------------------------------ */
544 static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)
548 QTAILQ_FOREACH_REVERSE(opt, &opts->head, QemuOptHead, next) {
549 if (strcmp(opt->name, name) != 0)
556 const char *qemu_opt_get(QemuOpts *opts, const char *name)
558 QemuOpt *opt = qemu_opt_find(opts, name);
559 return opt ? opt->str : NULL;
562 bool qemu_opt_has_help_opt(QemuOpts *opts)
566 QTAILQ_FOREACH_REVERSE(opt, &opts->head, QemuOptHead, next) {
567 if (is_help_option(opt->name)) {
574 bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
576 QemuOpt *opt = qemu_opt_find(opts, name);
580 assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
581 return opt->value.boolean;
584 uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
586 QemuOpt *opt = qemu_opt_find(opts, name);
590 assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
591 return opt->value.uint;
594 uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
596 QemuOpt *opt = qemu_opt_find(opts, name);
600 assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE);
601 return opt->value.uint;
604 static void qemu_opt_parse(QemuOpt *opt, Error **errp)
606 if (opt->desc == NULL)
609 switch (opt->desc->type) {
610 case QEMU_OPT_STRING:
614 parse_option_bool(opt->name, opt->str, &opt->value.boolean, errp);
616 case QEMU_OPT_NUMBER:
617 parse_option_number(opt->name, opt->str, &opt->value.uint, errp);
620 parse_option_size(opt->name, opt->str, &opt->value.uint, errp);
627 static void qemu_opt_del(QemuOpt *opt)
629 QTAILQ_REMOVE(&opt->opts->head, opt, next);
630 g_free((/* !const */ char*)opt->name);
631 g_free((/* !const */ char*)opt->str);
635 static bool opts_accepts_any(const QemuOpts *opts)
637 return opts->list->desc[0].name == NULL;
640 static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
645 for (i = 0; desc[i].name != NULL; i++) {
646 if (strcmp(desc[i].name, name) == 0) {
654 int qemu_opt_unset(QemuOpts *opts, const char *name)
656 QemuOpt *opt = qemu_opt_find(opts, name);
658 assert(opts_accepts_any(opts));
668 static void opt_set(QemuOpts *opts, const char *name, const char *value,
669 bool prepend, Error **errp)
672 const QemuOptDesc *desc;
673 Error *local_err = NULL;
675 desc = find_desc_by_name(opts->list->desc, name);
676 if (!desc && !opts_accepts_any(opts)) {
677 error_set(errp, QERR_INVALID_PARAMETER, name);
681 opt = g_malloc0(sizeof(*opt));
682 opt->name = g_strdup(name);
685 QTAILQ_INSERT_HEAD(&opts->head, opt, next);
687 QTAILQ_INSERT_TAIL(&opts->head, opt, next);
690 opt->str = g_strdup(value);
691 qemu_opt_parse(opt, &local_err);
693 error_propagate(errp, local_err);
698 int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
700 Error *local_err = NULL;
702 opt_set(opts, name, value, false, &local_err);
704 qerror_report_err(local_err);
705 error_free(local_err);
712 void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
715 opt_set(opts, name, value, false, errp);
718 int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
721 const QemuOptDesc *desc = opts->list->desc;
723 opt = g_malloc0(sizeof(*opt));
724 opt->desc = find_desc_by_name(desc, name);
725 if (!opt->desc && !opts_accepts_any(opts)) {
726 qerror_report(QERR_INVALID_PARAMETER, name);
731 opt->name = g_strdup(name);
733 opt->value.boolean = !!val;
734 opt->str = g_strdup(val ? "on" : "off");
735 QTAILQ_INSERT_TAIL(&opts->head, opt, next);
740 int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val)
743 const QemuOptDesc *desc = opts->list->desc;
745 opt = g_malloc0(sizeof(*opt));
746 opt->desc = find_desc_by_name(desc, name);
747 if (!opt->desc && !opts_accepts_any(opts)) {
748 qerror_report(QERR_INVALID_PARAMETER, name);
753 opt->name = g_strdup(name);
755 opt->value.uint = val;
756 opt->str = g_strdup_printf("%" PRId64, val);
757 QTAILQ_INSERT_TAIL(&opts->head, opt, next);
762 int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
763 int abort_on_failure)
768 QTAILQ_FOREACH(opt, &opts->head, next) {
769 rc = func(opt->name, opt->str, opaque);
770 if (abort_on_failure && rc != 0)
776 QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id)
780 QTAILQ_FOREACH(opts, &list->head, next) {
781 if (!opts->id && !id) {
784 if (opts->id && id && !strcmp(opts->id, id)) {
791 static int id_wellformed(const char *id)
795 if (!qemu_isalpha(id[0])) {
798 for (i = 1; id[i]; i++) {
799 if (!qemu_isalnum(id[i]) && !strchr("-._", id[i])) {
806 QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
807 int fail_if_exists, Error **errp)
809 QemuOpts *opts = NULL;
812 if (!id_wellformed(id)) {
813 error_set(errp,QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
814 #if 0 /* conversion from qerror_report() to error_set() broke this: */
815 error_printf_unless_qmp("Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.\n");
819 opts = qemu_opts_find(list, id);
821 if (fail_if_exists && !list->merge_lists) {
822 error_setg(errp, "Duplicate ID '%s' for %s", id, list->name);
828 } else if (list->merge_lists) {
829 opts = qemu_opts_find(list, NULL);
834 opts = g_malloc0(sizeof(*opts));
835 opts->id = g_strdup(id);
837 loc_save(&opts->loc);
838 QTAILQ_INIT(&opts->head);
839 QTAILQ_INSERT_TAIL(&list->head, opts, next);
843 void qemu_opts_reset(QemuOptsList *list)
845 QemuOpts *opts, *next_opts;
847 QTAILQ_FOREACH_SAFE(opts, &list->head, next, next_opts) {
852 void qemu_opts_loc_restore(QemuOpts *opts)
854 loc_restore(&opts->loc);
857 int qemu_opts_set(QemuOptsList *list, const char *id,
858 const char *name, const char *value)
861 Error *local_err = NULL;
863 opts = qemu_opts_create(list, id, 1, &local_err);
865 qerror_report_err(local_err);
866 error_free(local_err);
869 return qemu_opt_set(opts, name, value);
872 const char *qemu_opts_id(QemuOpts *opts)
877 /* The id string will be g_free()d by qemu_opts_del */
878 void qemu_opts_set_id(QemuOpts *opts, char *id)
883 void qemu_opts_del(QemuOpts *opts)
888 opt = QTAILQ_FIRST(&opts->head);
893 QTAILQ_REMOVE(&opts->list->head, opts, next);
898 int qemu_opts_print(QemuOpts *opts, void *dummy)
902 fprintf(stderr, "%s: %s:", opts->list->name,
903 opts->id ? opts->id : "<noid>");
904 QTAILQ_FOREACH(opt, &opts->head, next) {
905 fprintf(stderr, " %s=\"%s\"", opt->name, opt->str);
907 fprintf(stderr, "\n");
911 static int opts_do_parse(QemuOpts *opts, const char *params,
912 const char *firstname, bool prepend)
914 char option[128], value[1024];
915 const char *p,*pe,*pc;
916 Error *local_err = NULL;
918 for (p = params; *p != '\0'; p++) {
921 if (!pe || (pc && pc < pe)) {
922 /* found "foo,more" */
923 if (p == params && firstname) {
924 /* implicitly named first option */
925 pstrcpy(option, sizeof(option), firstname);
926 p = get_opt_value(value, sizeof(value), p);
928 /* option without value, probably a flag */
929 p = get_opt_name(option, sizeof(option), p, ',');
930 if (strncmp(option, "no", 2) == 0) {
931 memmove(option, option+2, strlen(option+2)+1);
932 pstrcpy(value, sizeof(value), "off");
934 pstrcpy(value, sizeof(value), "on");
938 /* found "foo=bar,more" */
939 p = get_opt_name(option, sizeof(option), p, '=');
944 p = get_opt_value(value, sizeof(value), p);
946 if (strcmp(option, "id") != 0) {
947 /* store and parse */
948 opt_set(opts, option, value, prepend, &local_err);
950 qerror_report_err(local_err);
951 error_free(local_err);
962 int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname)
964 return opts_do_parse(opts, params, firstname, false);
967 static QemuOpts *opts_parse(QemuOptsList *list, const char *params,
968 int permit_abbrev, bool defaults)
970 const char *firstname;
971 char value[1024], *id = NULL;
974 Error *local_err = NULL;
976 assert(!permit_abbrev || list->implied_opt_name);
977 firstname = permit_abbrev ? list->implied_opt_name : NULL;
979 if (strncmp(params, "id=", 3) == 0) {
980 get_opt_value(value, sizeof(value), params+3);
982 } else if ((p = strstr(params, ",id=")) != NULL) {
983 get_opt_value(value, sizeof(value), p+4);
988 * This code doesn't work for defaults && !list->merge_lists: when
989 * params has no id=, and list has an element with !opts->id, it
990 * appends a new element instead of returning the existing opts.
991 * However, we got no use for this case. Guard against possible
992 * (if unlikely) future misuse:
994 assert(!defaults || list->merge_lists);
995 opts = qemu_opts_create(list, id, !defaults, &local_err);
998 qerror_report_err(local_err);
999 error_free(local_err);
1004 if (opts_do_parse(opts, params, firstname, defaults) != 0) {
1005 qemu_opts_del(opts);
1012 QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params,
1015 return opts_parse(list, params, permit_abbrev, false);
1018 void qemu_opts_set_defaults(QemuOptsList *list, const char *params,
1023 opts = opts_parse(list, params, permit_abbrev, true);
1027 typedef struct OptsFromQDictState {
1030 } OptsFromQDictState;
1032 static void qemu_opts_from_qdict_1(const char *key, QObject *obj, void *opaque)
1034 OptsFromQDictState *state = opaque;
1039 if (!strcmp(key, "id") || *state->errp) {
1043 switch (qobject_type(obj)) {
1045 value = qstring_get_str(qobject_to_qstring(obj));
1048 n = snprintf(buf, sizeof(buf), "%" PRId64,
1049 qint_get_int(qobject_to_qint(obj)));
1050 assert(n < sizeof(buf));
1054 n = snprintf(buf, sizeof(buf), "%.17g",
1055 qfloat_get_double(qobject_to_qfloat(obj)));
1056 assert(n < sizeof(buf));
1060 pstrcpy(buf, sizeof(buf),
1061 qbool_get_int(qobject_to_qbool(obj)) ? "on" : "off");
1068 qemu_opt_set_err(state->opts, key, value, state->errp);
1072 * Create QemuOpts from a QDict.
1073 * Use value of key "id" as ID if it exists and is a QString.
1074 * Only QStrings, QInts, QFloats and QBools are copied. Entries with
1075 * other types are silently ignored.
1077 QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict,
1080 OptsFromQDictState state;
1081 Error *local_err = NULL;
1084 opts = qemu_opts_create(list, qdict_get_try_str(qdict, "id"), 1,
1087 error_propagate(errp, local_err);
1091 assert(opts != NULL);
1093 state.errp = &local_err;
1095 qdict_iter(qdict, qemu_opts_from_qdict_1, &state);
1097 error_propagate(errp, local_err);
1098 qemu_opts_del(opts);
1106 * Adds all QDict entries to the QemuOpts that can be added and removes them
1107 * from the QDict. When this function returns, the QDict contains only those
1108 * entries that couldn't be added to the QemuOpts.
1110 void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp)
1112 const QDictEntry *entry, *next;
1114 entry = qdict_first(qdict);
1116 while (entry != NULL) {
1117 Error *local_err = NULL;
1118 OptsFromQDictState state = {
1123 next = qdict_next(qdict, entry);
1125 if (find_desc_by_name(opts->list->desc, entry->key)) {
1126 qemu_opts_from_qdict_1(entry->key, entry->value, &state);
1128 error_propagate(errp, local_err);
1131 qdict_del(qdict, entry->key);
1140 * Convert from QemuOpts to QDict.
1141 * The QDict values are of type QString.
1142 * TODO We'll want to use types appropriate for opt->desc->type, but
1143 * this is enough for now.
1145 QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict)
1151 qdict = qdict_new();
1154 qdict_put(qdict, "id", qstring_from_str(opts->id));
1156 QTAILQ_FOREACH(opt, &opts->head, next) {
1157 val = QOBJECT(qstring_from_str(opt->str));
1158 qdict_put_obj(qdict, opt->name, val);
1163 /* Validate parsed opts against descriptions where no
1164 * descriptions were provided in the QemuOptsList.
1166 void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp)
1169 Error *local_err = NULL;
1171 assert(opts_accepts_any(opts));
1173 QTAILQ_FOREACH(opt, &opts->head, next) {
1174 opt->desc = find_desc_by_name(desc, opt->name);
1176 error_set(errp, QERR_INVALID_PARAMETER, opt->name);
1180 qemu_opt_parse(opt, &local_err);
1182 error_propagate(errp, local_err);
1188 int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
1189 int abort_on_failure)
1195 loc_push_none(&loc);
1196 QTAILQ_FOREACH(opts, &list->head, next) {
1197 loc_restore(&opts->loc);
1198 rc |= func(opts, opaque);
1199 if (abort_on_failure && rc != 0)