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

Function icmap_set_r

exec/icmap.c:411–489  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

409}
410
411cs_error_t icmap_set_r(
412 const icmap_map_t map,
413 const char *key_name,
414 const void *value,
415 size_t value_len,
416 icmap_value_types_t type)
417{
418 struct icmap_item *item;
419 struct icmap_item *new_item;
420 size_t new_value_len;
421 size_t new_item_size;
422
423 if (value == NULL || key_name == NULL) {
424 return (CS_ERR_INVALID_PARAM);
425 }
426
427 if (icmap_check_value_len(value, value_len, type) != 0) {
428 return (CS_ERR_INVALID_PARAM);
429 }
430
431 item = qb_map_get(map->qb_map, key_name);
432 if (item != NULL) {
433 /*
434 * Check that key is really changed
435 */
436 if (icmap_item_eq(item, value, value_len, type)) {
437 return (CS_OK);
438 }
439 } else {
440 if (icmap_check_key_name(key_name) != 0) {
441 return (CS_ERR_NAME_TOO_LONG);
442 }
443 }
444
445 if (type == ICMAP_VALUETYPE_BINARY || type == ICMAP_VALUETYPE_STRING) {
446 if (type == ICMAP_VALUETYPE_STRING) {
447 new_value_len = strlen((const char *)value);
448 if (new_value_len > value_len) {
449 new_value_len = value_len;
450 }
451 new_value_len++;
452 } else {
453 new_value_len = value_len;
454 }
455 } else {
456 new_value_len = icmap_get_valuetype_len(type);
457 }
458
459 new_item_size = sizeof(struct icmap_item) + new_value_len;
460 new_item = malloc(new_item_size);
461 if (new_item == NULL) {
462 return (CS_ERR_NO_MEMORY);
463 }
464 memset(new_item, 0, new_item_size);
465
466 if (item == NULL) {
467 new_item->key_name = strdup(key_name);
468 if (new_item->key_name == NULL) {

Callers 13

icmap_setFunction · 0.85
icmap_set_int8_rFunction · 0.85
icmap_set_uint8_rFunction · 0.85
icmap_set_int16_rFunction · 0.85
icmap_set_uint16_rFunction · 0.85
icmap_set_int32_rFunction · 0.85
icmap_set_uint32_rFunction · 0.85
icmap_set_int64_rFunction · 0.85
icmap_set_uint64_rFunction · 0.85
icmap_set_float_rFunction · 0.85
icmap_set_double_rFunction · 0.85
icmap_set_string_rFunction · 0.85

Calls 4

icmap_check_value_lenFunction · 0.85
icmap_item_eqFunction · 0.85
icmap_check_key_nameFunction · 0.85
icmap_get_valuetype_lenFunction · 0.85

Tested by

no test coverage detected