[XLA:GPU] Fix possible bug in libdevice path logic.
[XLA:GPU] Fix possible bug in libdevice path logic.

* When copying a C string, we need to include the null terminator byte. It seems likely this code reads off the end of the array since it only copies non-null bytes. But if we use a std::string it will handle this for us.
* dirname() may not be thread-safe. On Linux it likely is, but better to avoid it and just use the TSL utility for this.

This may be the cause of a flaky test failure in JAX CI.
