MCPcopy Create free account
hub / github.com/corosync/corosync / set_key

Function set_key

tools/corosync-cmapctl.c:604–726  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

602}
603
604static void set_key(cmap_handle_t handle, const char *key_name, const char *key_type_s, const char *key_value_s)
605{
606 int64_t i64;
607 uint64_t u64;
608 double dbl;
609 float flt;
610 cs_error_t err = CS_OK;
611 int scanf_res = 0;
612
613 cmap_value_types_t type;
614
615 if (convert_name_to_type(key_type_s) == -1) {
616 fprintf(stderr, "Unknown type %s\n", key_type_s);
617 exit (EXIT_FAILURE);
618 }
619
620 type = convert_name_to_type(key_type_s);
621
622 switch (type) {
623 case CMAP_VALUETYPE_INT8:
624 case CMAP_VALUETYPE_INT16:
625 case CMAP_VALUETYPE_INT32:
626 case CMAP_VALUETYPE_INT64:
627 scanf_res = sscanf(key_value_s, "%"PRId64, &i64);
628 break;
629 case CMAP_VALUETYPE_UINT8:
630 case CMAP_VALUETYPE_UINT16:
631 case CMAP_VALUETYPE_UINT32:
632 case CMAP_VALUETYPE_UINT64:
633 scanf_res = sscanf(key_value_s, "%"PRIu64, &u64);
634 break;
635 case CMAP_VALUETYPE_FLOAT:
636 scanf_res = sscanf(key_value_s, "%f", &flt);
637 break;
638 case CMAP_VALUETYPE_DOUBLE:
639 scanf_res = sscanf(key_value_s, "%lf", &dbl);
640 break;
641 case CMAP_VALUETYPE_STRING:
642 case CMAP_VALUETYPE_BINARY:
643 /*
644 * Do nothing
645 */
646 scanf_res = 1;
647 break;
648 }
649
650 if (scanf_res != 1) {
651 fprintf(stderr, "%s is not valid %s type value\n", key_value_s, key_type_s);
652 exit(EXIT_FAILURE);
653 }
654 /*
655 * We have parsed value, so insert value
656 */
657
658 switch (type) {
659 case CMAP_VALUETYPE_INT8:
660 if (i64 > INT8_MAX || i64 < INT8_MIN) {
661 fprintf(stderr, "%s is not valid i8 integer\n", key_value_s);

Callers 2

read_in_config_fileFunction · 0.85
mainFunction · 0.85

Calls 14

convert_name_to_typeFunction · 0.85
cmap_set_int8Function · 0.85
cmap_set_int16Function · 0.85
cmap_set_int32Function · 0.85
cmap_set_int64Function · 0.85
cmap_set_uint8Function · 0.85
cmap_set_uint16Function · 0.85
cmap_set_uint32Function · 0.85
cmap_set_uint64Function · 0.85
cmap_set_floatFunction · 0.85
cmap_set_doubleFunction · 0.85
cmap_set_stringFunction · 0.85

Tested by

no test coverage detected