Commit 5b75b40b authored by Natanael Copa's avatar Natanael Copa

version: added apk_version_compare_blob() function

We want be able to compare blobs so we basicly revert the old change,
and make a wrapper that takes version strings.
parent 4bbed2d6
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
const char *apk_version_op_string(int result_mask); const char *apk_version_op_string(int result_mask);
int apk_version_result_mask(const char *str); int apk_version_result_mask(const char *str);
int apk_version_validate(apk_blob_t ver); int apk_version_validate(apk_blob_t ver);
int apk_version_compare_blob(apk_blob_t a, apk_blob_t b);
int apk_version_compare(const char *str1, const char *str2); int apk_version_compare(const char *str1, const char *str2);
#endif #endif
...@@ -174,20 +174,16 @@ int apk_version_validate(apk_blob_t ver) ...@@ -174,20 +174,16 @@ int apk_version_validate(apk_blob_t ver)
return t == TOKEN_END; return t == TOKEN_END;
} }
int apk_version_compare(const char *str1, const char *str2) int apk_version_compare_blob(apk_blob_t a, apk_blob_t b)
{ {
int at = TOKEN_DIGIT, bt = TOKEN_DIGIT; int at = TOKEN_DIGIT, bt = TOKEN_DIGIT;
int av = 0, bv = 0; int av = 0, bv = 0;
apk_blob_t a, b;
if (str1 == NULL || str2 == NULL) { if (APK_BLOB_IS_NULL(a) || APK_BLOB_IS_NULL(b)) {
if (str1 == NULL && str2 == NULL) if (APK_BLOB_IS_NULL(a) && APK_BLOB_IS_NULL(b))
return APK_VERSION_EQUAL; return APK_VERSION_EQUAL;
return APK_VERSION_EQUAL | APK_VERSION_GREATER | APK_VERSION_LESS; return APK_VERSION_EQUAL | APK_VERSION_GREATER | APK_VERSION_LESS;
} }
a = APK_BLOB_STR(str1);
b = APK_BLOB_STR(str2);
while (at == bt && at != TOKEN_END && at != TOKEN_INVALID && av == bv) { while (at == bt && at != TOKEN_END && at != TOKEN_INVALID && av == bv) {
av = get_token(&at, &a); av = get_token(&at, &a);
...@@ -213,3 +209,8 @@ int apk_version_compare(const char *str1, const char *str2) ...@@ -213,3 +209,8 @@ int apk_version_compare(const char *str1, const char *str2)
APK_VERSION_LESS : APK_VERSION_GREATER; APK_VERSION_LESS : APK_VERSION_GREATER;
return APK_VERSION_EQUAL; return APK_VERSION_EQUAL;
} }
int apk_version_compare(const char *str1, const char *str2)
{
return apk_version_compare_blob(APK_BLOB_STR(str1), APK_BLOB_STR(str2));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment