Allocate thread local buffers in __init_tls.

Thread local buffers were using pthread_setspecific for storage with
lazy initialization. pthread_setspecific shares TLS slots between the
linker and libc.so, so thread local buffers being initialized in a
different order between libc.so and the linker meant that bad things
would happen (manifesting as snprintf not working because the
locale was mangled)

Bug: http://b/20464031
Test: /data/nativetest64/bionic-unit-tests/bionic-unit-tests
      everything passes
Test: /data/nativetest/bionic-unit-tests/bionic-unit-tests
      thread_local tests are failing both before and after (KUSER_HELPERS?)
Test: /data/nativetest64/bionic-unit-tests-static/bionic-unit-tests-static
      no additional failures
Change-Id: I9f445a77c6e86979f3fa49c4a5feecf6ec2b0c3f
diff --git a/libc/bionic/pty.cpp b/libc/bionic/pty.cpp
index d699ff5..bdabf36 100644
--- a/libc/bionic/pty.cpp
+++ b/libc/bionic/pty.cpp
@@ -36,10 +36,7 @@
 #include <unistd.h>
 #include <utmp.h>
 
-#include "private/ThreadLocalBuffer.h"
-
-static ThreadLocalBuffer<char, 32> g_ptsname_tls_buffer;
-static ThreadLocalBuffer<char, 64> g_ttyname_tls_buffer;
+#include "bionic/pthread_internal.h"
 
 int getpt() {
   return posix_openpt(O_RDWR|O_NOCTTY);
@@ -54,8 +51,9 @@
 }
 
 char* ptsname(int fd) {
-  char* buf = g_ptsname_tls_buffer.get();
-  int error = ptsname_r(fd, buf, g_ptsname_tls_buffer.size());
+  bionic_tls& tls = __get_bionic_tls();
+  char* buf = tls.ptsname_buf;
+  int error = ptsname_r(fd, buf, sizeof(tls.ptsname_buf));
   return (error == 0) ? buf : NULL;
 }
 
@@ -80,8 +78,9 @@
 }
 
 char* ttyname(int fd) {
-  char* buf = g_ttyname_tls_buffer.get();
-  int error = ttyname_r(fd, buf, g_ttyname_tls_buffer.size());
+  bionic_tls& tls = __get_bionic_tls();
+  char* buf = tls.ttyname_buf;
+  int error = ttyname_r(fd, buf, sizeof(tls.ttyname_buf));
   return (error == 0) ? buf : NULL;
 }