We'll make a fake locale xx_XX.UTF-8. Start by copying en_US.UTF-8:
```
# cp -r /usr/share/locale/en_US.UTF-8 /usr/share/locale/xx_XX.UTF-8
```
Now create a new LC_COLLATE file that has a version string stamped on it, and install it:
```
# localedef \
-i /usr/src/share/colldef/en_US.UTF-8.src \
-f /usr/src/tools/tools/locale/etc/final-maps/map.UTF-8 \
-V '30.0.2' \
xx_XX
# cp xx_XX/LC_COLLATE /usr/share/locale/xx_XX.UTF-8/
```
Now we can access the version string with querylocaleversion:
```
# cat test.c
#include <locale.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
const char *name;
locale_t loc;
if (argc < 2)
return (1);
name = argv[1];
loc = newlocale(LC_ALL_MASK, name, NULL);
if (!loc) {
printf("failed to open locale\n");
return (1);
}
printf("name = [%s], version = [%s]\n",
querylocale(LC_COLLATE_MASK, loc),
querylocale(LC_COLLATE_MASK | LC_VERSION_MASK, loc));
freelocale(loc);
return (0);
}
# cc -Wall test.c
# ./a.out xx_XX.UTF-8
name = [xx_XX.UTF-8], version = [30.0.2]
```
Collation files that don't have a version return an empty string:
```
# ./a.out fr_FR.UTF-8
name = [fr_FR.UTF-8], version = []
```
The new LC_COLLATE files can still be successfully loaded by unpatched libc (because they only read the BSD 1.0 header up to to the first NUL).