{"id":32136700,"url":"https://github.com/repology/libversion","last_synced_at":"2025-10-21T04:03:45.488Z","repository":{"id":46096340,"uuid":"85185645","full_name":"repology/libversion","owner":"repology","description":"Advanced version string comparison library","archived":false,"fork":false,"pushed_at":"2025-10-06T20:28:11.000Z","size":173,"stargazers_count":118,"open_issues_count":8,"forks_count":16,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-10-21T04:01:54.343Z","etag":null,"topics":["c","library","version","versioning"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/repology.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-03-16T10:55:38.000Z","updated_at":"2025-10-06T20:28:14.000Z","dependencies_parsed_at":"2024-01-18T18:48:11.430Z","dependency_job_id":"1d101561-9da9-42c0-b081-ddc4ef5d256c","html_url":"https://github.com/repology/libversion","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/repology/libversion","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/repology%2Flibversion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/repology%2Flibversion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/repology%2Flibversion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/repology%2Flibversion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/repology","download_url":"https://codeload.github.com/repology/libversion/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/repology%2Flibversion/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280200872,"owners_count":26289477,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","library","version","versioning"],"created_at":"2025-10-21T04:02:02.838Z","updated_at":"2025-10-21T04:03:45.483Z","avatar_url":"https://github.com/repology.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libversion\n\n\u003ca href=\"https://repology.org/metapackage/libversion/versions\"\u003e\n\t\u003cimg src=\"https://repology.org/badge/vertical-allrepos/libversion.svg\" alt=\"libversion packaging status\" align=\"right\"\u003e\n\u003c/a\u003e\n\n![CI](https://github.com/repology/libversion/workflows/CI/badge.svg)\n[![Github commits (since latest release)](https://img.shields.io/github/commits-since/repology/libversion/latest.svg)](https://github.com/repology/libversion)\n\nAdvanced version string comparison library.\n\nNeed to compare software, package or whatever versions? Comparing\n`1.0` and `1.1` could be easy, but are you ready for more\ncomplex cases like `1.2-x.3~alpha4`? **libversion** is, which\nis proven by using the library in [Repology](https://repology.org/)\nproject which relies on comparing software version strings, even\nif they are written in different formats.\n\n## Features\n\nA short list of version features libversion handles for you:\n\n* Simple versions, obviously: `0.9 \u003c 1.0 \u003c 1.1`\n* Omitting insignificant components: `1.0 == 1.0.0`\n* Leading zeroes: `1.001 == 1.1`\n* Unusual separators: `1_2~3 == 1.2.3`\n* Letter suffixes: `1.2 \u003c 1.2a \u003c 1.2b \u003c 1.3`\n* Alphanumeric prerelease components:\n  * `1.0alpha1 == 1.0.alpha1 == 1.0a1 == 1.0.a1`\n  * `1.0alpha1 \u003c 1.0alpha2 \u003c 1.0beta1 \u003c 1.0rc1 \u003c 1.0`\n* Awareness of prerelease keywords: while `1.0 \u003c 1.0a-1` (_a_ treated\n  as version addendum), but `1.0alpha-1 \u003c 1.0` (_alpha_ is treated\n  as prerelease marker)\n* Awareness of _patch_, _post_ and _pl_ keywords: while `1.0alpha1 \u003c 1.0`\n  (_alpha_ is pre-release), but `1.0 \u003c 1.0patch1 \u003c 1.1` (_patch_ is post-release)\n* Customizable handling of _p_ keyword (it may mean either _patch_ or _pre_,\n  and since libversion cannot guess, this is controlled with an external flag)\n\nSee [doc/ALGORITHM.md](doc/ALGORITHM.md) for more elaborate description\nof inner logic.\n\n## API\n\n### Version comparison\n\n```\nint version_compare2(const char* v1, const char* v2);\nint version_compare4(const char* v1, const char* v2, int v1_flags, int v2_flags);\n```\n\nCompares version strings `v1` and `v2`.\n\nReturns **-1** if `v1` is lower than `v2`, **0** if `v1` is equal to `v2` and **1** if `v1` is higher than `v2`.\n\nThread safe, does not produce errors, does not allocate dynamic memory,\nO(N) computational complexity, O(1) stack memory requirements.\n\n4-argument form allows specifying flags for each version argument to\ntune comparison behavior in specific cases. Currently supported `flags`\nvalues are:\n\n* `VERSIONFLAG_P_IS_PATCH` _p_ letter is treated as _patch_\n  (post-release) instead of _pre_ (pre-release).\n* `VERSIONFLAG_ANY_IS_PATCH` any letter sequence is treated as\n  post-release (useful for handling patchsets as in\n  `1.2foopatchset3.barpatchset4`).\n* `VERSIONFLAG_LOWER_BOUND` derive lowest possible version with\n  the given prefix. For example, lower bound for `1.0` is such\n  imaginary version `?` that it's higher than any release before\n  `1.0` and lower than any prerelease of `1.0`.\n  E.g. `0.999` \u003c lower bound(`1.0`) \u003c `1.0alpha0`.\n* `VERSIONFLAG_UPPER_BOUND` derive highest possible version with\n  the given prefix. Opposite of `VERSIONFLAG_LOWER_BOUND`.\n\nIf both `flags` are zero, `version_compare4` acts exactly the same\nas `version_compare2`.\n\n## Example\n\n```c\n#include \u003cassert.h\u003e\n#include \u003clibversion/version.h\u003e\n\nint main() {\n    /* 0.99 \u003c 1.11 */\n    assert(version_compare2(\"0.99\", \"1.11\") == -1);\n\n    /* 1.0 == 1.0.0 */\n    assert(version_compare2(\"1.0\", \"1.0.0\") == 0);\n\n    /* 1.0alpha1 \u003c 1.0.rc1 */\n    assert(version_compare2(\"1.0alpha1\", \"1.0.rc1\") == -1);\n\n    /* 1.0 \u003e 1.0.rc1 */\n    assert(version_compare2(\"1.0\", \"1.0-rc1\") == 1);\n\n    /* 1.2.3alpha4 is the same as 1.2.3~a4 */\n    assert(version_compare2(\"1.2.3alpha4\", \"1.2.3~a4\") == 0);\n\n    /* by default, `p' is treated as `pre'... */\n    assert(version_compare2(\"1.0p1\", \"1.0pre1\") == 0);\n    assert(version_compare2(\"1.0p1\", \"1.0post1\") == -1);\n    assert(version_compare2(\"1.0p1\", \"1.0patch1\") == -1);\n\n    /* ...but this is tunable: here it's handled as `patch` */\n    assert(version_compare4(\"1.0p1\", \"1.0pre1\", VERSIONFLAG_P_IS_PATCH, 0) == 1);\n    assert(version_compare4(\"1.0p1\", \"1.0post1\", VERSIONFLAG_P_IS_PATCH, 0) == 0);\n    assert(version_compare4(\"1.0p1\", \"1.0patch1\", VERSIONFLAG_P_IS_PATCH, 0) == 0);\n\n    /* a way to check that the version belongs to a given release */\n    assert(\n        (version_compare4(\"1.0alpha1\", \"1.0\", 0, VERSIONFLAG_LOWER_BOUND) == 1) \u0026\u0026\n        (version_compare4(\"1.0alpha1\", \"1.0\", 0, VERSIONFLAG_UPPER_BOUND) == -1) \u0026\u0026\n        (version_compare4(\"1.0.1\", \"1.0\", 0, VERSIONFLAG_LOWER_BOUND) == 1) \u0026\u0026\n        (version_compare4(\"1.0.1\", \"1.0\", 0, VERSIONFLAG_UPPER_BOUND) == -1) \u0026\u0026\n        /* 1.0alpha1 and 1.0.1 belong to 1.0 release, e.g. they lie between\n           (lowest possible version in 1.0) and (highest possible version in 1.0) */\n    );\n}\n```\n\n```sh\ngcc my_code.c `pkg-config --cflags --libs libversion`\n# or (for static linking)\ngcc my_code.c --static `pkg-config --static --cflags --libs libversion`\n```\n\nUsing libversion in CMake is very simple (note that this handles\ninclude paths and compiler flags as well):\n\n```cmake\nfind_package(libversion)\ntarget_link_libraries(my_target libversion::libversion)\n# or (for static linking)\ntarget_link_libraries(my_target libversion::libversion_static)\n```\n\n## Building\n\nlibversion uses [CMake](https://cmake.org/) build system.\n\nTo build the library, run `cmake . \u0026\u0026 cmake --build .`.\n\nTo run test suite, run `ctest` after building.\n\nTo install the library systemwide, run `make install`.\n\nThe project installs library, headers, pkg-config file, CMake import\nfiles and a demo utility, `version_compare`, which may be used to\ncompare versions from command line:\n\n```\n$ ./version_compare\nUsage: ./version_compare version1 version2\n$ ./version_compare 0.99 1.0\n\u003c\n```\n\n## Bindings and compatible implementations\n\n* Python: [py-libversion](https://github.com/repology/py-libversion) by @AMDmi3\n* Go: [golibversion](https://github.com/saenai255/golibversion) by @saenai255\n* Rust: [libversion-rs](https://github.com/repology/libversion-rs) by @AMDmi3 (not really a binding, but pure Rust implementation)\n* Ruby: [ruby-libversion](https://github.com/Zopolis4/ruby-libversion) by @Zopolis4\n* Perl: [Version::libversion::XS](https://github.com/giterlizzi/perl-Version-libversion-XS) by @giterlizzi\n* Raku: [Version::Repology](https://raku.land/zef:lizmat/Version::Repology) by @lizmat (a pure Raku implementation)\n\n## Author\n\n* [Dmitry Marakasov](https://github.com/AMDmi3) \u003camdmi3@amdmi3.ru\u003e\n\n## License\n\n* [MIT](COPYING)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frepology%2Flibversion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frepology%2Flibversion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frepology%2Flibversion/lists"}