]> git.ipfire.org Git - location/libloc.git/blobdiff - src/database.c
country: Add simple function to test if a country code is valid
[location/libloc.git] / src / database.c
index 825d7982199cd5f8de14bcecc5df5d3a33aa0577..d19bf7c140bc3ded8b7fb51641b73dba3f66deaf 100644 (file)
@@ -751,10 +751,6 @@ LOC_EXPORT int loc_database_enumerator_set_country_code(struct loc_database_enum
                return 0;
        }
 
-       // Country codes must be two characters
-       if (strlen(country_code) != 2)
-               return -EINVAL;
-
        // Treat A1, A2, A3 as special country codes,
        // but perform search for flags instead
        if (strcmp(country_code, "A1") == 0) {
@@ -768,6 +764,10 @@ LOC_EXPORT int loc_database_enumerator_set_country_code(struct loc_database_enum
                        LOC_NETWORK_FLAG_ANYCAST);
        }
 
+       // Country codes must be two characters
+       if (!loc_country_code_is_valid(country_code))
+               return -EINVAL;
+
        for (unsigned int i = 0; i < 3; i++) {
                enumerator->country_code[i] = country_code[i];
        }