[util] fix BaseName() on BSD-derived systems

basename() is thread-safe on Linux in relatively new glibc
implementations as per its manual page [1].

However, basename() is not thread-safe at least on contemporary
version of Darwin/macOS as per basename() manual page ([2], [3], [4]):

  The basename() function returns a pointer to internal static storage
  space that will be overwritten by subsequent calls.

So, let's use thread-safe basename_r() on macOS. With that, the only
test scenario in file_cache-stress-test no longer fails on macOS.

As a bit of bigger picture, starting FreeBSD 12.0, the basename()
function was reimplemented to store its result in the provided
input buffer [5].

[1] https://www.man7.org/linux/man-pages/man3/basename.3.html
[2] https://www.freebsd.org/cgi/man.cgi?query=basename&sektion=3&manpath=Darwin+7.0.1
[3] https://www.unix.com/man-page/mojave/3/basename/
[4] https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/basename.3.html
[5] https://www.freebsd.org/cgi/man.cgi?query=basename&sektion=3&manpath=FreeBSD+12.0-RELEASE

Change-Id: I26b81757e48e0b7d5f79582349548f6e9e474d90
Reviewed-on: http://gerrit.cloudera.org:8080/16466
Tested-by: Alexey Serbin <aserbin@cloudera.com>
Reviewed-by: Grant Henke <granthenke@apache.org>
1 file changed