MCPcopy Create free account
hub / github.com/ClusterLabs/pacemaker / compare_version

Function compare_version

lib/common/utils.c:401–478  ·  view source on GitHub ↗

* version1 < version2 : -1 * version1 = version2 : 0 * version1 > version2 : 1 */

Source from the content-addressed store, hash-verified

399 * version1 > version2 : 1
400 */
401int
402compare_version(const char *version1, const char *version2)
403{
404 int rc = 0;
405 int lpc = 0;
406 char *ver1_copy = NULL, *ver2_copy = NULL;
407 char *rest1 = NULL, *rest2 = NULL;
408
409 if (version1 == NULL && version2 == NULL) {
410 return 0;
411 } else if (version1 == NULL) {
412 return -1;
413 } else if (version2 == NULL) {
414 return 1;
415 }
416
417 ver1_copy = strdup(version1);
418 ver2_copy = strdup(version2);
419 rest1 = ver1_copy;
420 rest2 = ver2_copy;
421
422 while (1) {
423 int digit1 = 0;
424 int digit2 = 0;
425
426 lpc++;
427
428 if (rest1 == rest2) {
429 break;
430 }
431
432 if (rest1 != NULL) {
433 digit1 = crm_version_helper(rest1, &rest1);
434 }
435
436 if (rest2 != NULL) {
437 digit2 = crm_version_helper(rest2, &rest2);
438 }
439
440 if (digit1 < digit2) {
441 rc = -1;
442 crm_trace("%d < %d", digit1, digit2);
443 break;
444
445 } else if (digit1 > digit2) {
446 rc = 1;
447 crm_trace("%d > %d", digit1, digit2);
448 break;
449 }
450
451 if (rest1 != NULL && rest1[0] == '.') {
452 rest1++;
453 }
454 if (rest1 != NULL && rest1[0] == 0) {
455 rest1 = NULL;
456 }
457
458 if (rest2 != NULL && rest2[0] == '.') {

Callers 9

cib_perform_opFunction · 0.85
filter_action_parametersFunction · 0.85
create_operation_updateFunction · 0.85
test_attr_expressionFunction · 0.85
unpack_rsc_opFunction · 0.85
do_election_count_voteFunction · 0.85
append_restart_listFunction · 0.85
revision_check_callbackFunction · 0.85

Calls 1

crm_version_helperFunction · 0.85

Tested by 1

test_attr_expressionFunction · 0.68