Skip to content

Commit

Permalink
Add collation versions for FreeBSD.
Browse files Browse the repository at this point in the history
On FreeBSD 13, use querylocale() to read the current version of libc
collations.  Similar to commits 352f6f2 for Windows and d5ac14f for
GNU/Linux.

Discussion: https://postgr.es/m/CAEepm%3D0uEQCpfq_%2BLYFBdArCe4Ot98t1aR4eYiYTe%3DyavQygiQ%40mail.gmail.com
  • Loading branch information
macdice committed Nov 20, 2020
1 parent a4ef032 commit ca051d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion doc/src/sgml/charset.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,8 @@ CREATE COLLATION ignore_accents (provider = icu, locale = 'und-u-ks-level1-kc-tr
Version information is available from the
<literal>icu</literal> provider on all operating systems. For the
<literal>libc</literal> provider, versions are currently only available
on systems using the GNU C library (most Linux systems) and Windows.
on systems using the GNU C library (most Linux systems), FreeBSD and
Windows.
</para>

<note>
Expand Down
20 changes: 20 additions & 0 deletions src/backend/utils/adt/pg_locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,26 @@ get_collation_actual_version(char collprovider, const char *collcollate)

/* Use the glibc version because we don't have anything better. */
collversion = pstrdup(gnu_get_libc_version());
#elif defined(LC_VERSION_MASK)
locale_t loc;

/* C[.encoding] and POSIX never change. */
if (strcmp("C", collcollate) == 0 ||
strncmp("C.", collcollate, 2) == 0 ||
strcmp("POSIX", collcollate) == 0)
return NULL;

/* Look up FreeBSD collation version. */
loc = newlocale(LC_COLLATE, collcollate, NULL);
if (loc)
{
collversion =
pstrdup(querylocale(LC_COLLATE_MASK | LC_VERSION_MASK, loc));
freelocale(loc);
}
else
ereport(ERROR,
(errmsg("could not load locale \"%s\"", collcollate)));
#elif defined(WIN32) && _WIN32_WINNT >= 0x0600
/*
* If we are targeting Windows Vista and above, we can ask for a name
Expand Down

0 comments on commit ca051d8

Please sign in to comment.