diff options
author | Elliott Hughes <enh@google.com> | 2014-09-08 23:46:04 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-09-08 23:46:04 +0000 |
commit | 201f36d23bb778b29c8d305fa40a41990e0487bc (patch) | |
tree | 15682b74fd20e0a37c8d6cef63bba9e05df7145f /libc | |
parent | d3d89f0d28aba2db9f11cc0a9b3a865fa1d9d265 (diff) | |
parent | cf5fc80c3eb710cb5a1985837156cb2758c87a5b (diff) | |
download | bionic-201f36d23bb778b29c8d305fa40a41990e0487bc.zip bionic-201f36d23bb778b29c8d305fa40a41990e0487bc.tar.gz bionic-201f36d23bb778b29c8d305fa40a41990e0487bc.tar.bz2 |
Merge "Don't expose non-standard basename_r and dirname_r in LP64."
Diffstat (limited to 'libc')
-rw-r--r-- | libc/bionic/libgen.cpp | 34 | ||||
-rw-r--r-- | libc/include/libgen.h | 26 |
2 files changed, 26 insertions, 34 deletions
diff --git a/libc/bionic/libgen.cpp b/libc/bionic/libgen.cpp index d8df494..b98f504 100644 --- a/libc/bionic/libgen.cpp +++ b/libc/bionic/libgen.cpp @@ -36,22 +36,7 @@ #include "private/ThreadLocalBuffer.h" -GLOBAL_INIT_THREAD_LOCAL_BUFFER(basename); -GLOBAL_INIT_THREAD_LOCAL_BUFFER(dirname); - -char* basename(const char* path) { - LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, basename, MAXPATHLEN); - int rc = basename_r(path, basename_tls_buffer, basename_tls_buffer_size); - return (rc < 0) ? NULL : basename_tls_buffer; -} - -char* dirname(const char* path) { - LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, dirname, MAXPATHLEN); - int rc = dirname_r(path, dirname_tls_buffer, dirname_tls_buffer_size); - return (rc < 0) ? NULL : dirname_tls_buffer; -} - -int basename_r(const char* path, char* buffer, size_t buffer_size) { +__LIBC64_HIDDEN__ int basename_r(const char* path, char* buffer, size_t buffer_size) { const char* startp = NULL; const char* endp = NULL; int len; @@ -103,7 +88,7 @@ int basename_r(const char* path, char* buffer, size_t buffer_size) { return result; } -int dirname_r(const char* path, char* buffer, size_t buffer_size) { +__LIBC64_HIDDEN__ int dirname_r(const char* path, char* buffer, size_t buffer_size) { const char* endp = NULL; int len; int result; @@ -161,3 +146,18 @@ int dirname_r(const char* path, char* buffer, size_t buffer_size) { } return result; } + +GLOBAL_INIT_THREAD_LOCAL_BUFFER(basename); +GLOBAL_INIT_THREAD_LOCAL_BUFFER(dirname); + +char* basename(const char* path) { + LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, basename, MAXPATHLEN); + int rc = basename_r(path, basename_tls_buffer, basename_tls_buffer_size); + return (rc < 0) ? NULL : basename_tls_buffer; +} + +char* dirname(const char* path) { + LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, dirname, MAXPATHLEN); + int rc = dirname_r(path, dirname_tls_buffer, dirname_tls_buffer_size); + return (rc < 0) ? NULL : dirname_tls_buffer; +} diff --git a/libc/include/libgen.h b/libc/include/libgen.h index 4caf8b9..e89328e 100644 --- a/libc/include/libgen.h +++ b/libc/include/libgen.h @@ -38,29 +38,21 @@ __BEGIN_DECLS /* * <string.h> gets you the GNU basename. * <libgen.h> the POSIX one. - * Note that our "POSIX" one has the wrong argument cv-qualifiers. + * Note that our "POSIX" one has the wrong argument cv-qualifiers, but doesn't + * modify its input and uses thread-local storage for the result if necessary. */ extern char* basename(const char*); #define __bionic_using_posix_basename #endif -/* our version of dirname/basename don't modify the input path */ -extern char* dirname (const char* path); +/* This has the wrong argument cv-qualifiers, but doesn't modify its input and uses thread-local storage for the result if necessary. */ +extern char* dirname(const char*); -/* special thread-safe Bionic versions - * - * if 'buffer' is NULL, 'bufflen' is ignored and the length of the result is returned - * otherwise, place result in 'buffer' - * - * at most bufflen-1 characters written, plus a terminating zero - * - * return length of result, or -1 in case of error, with errno set to: - * - * ERANGE: buffer is too short - * ENAMETOOLONG: the result is too long for a valid path - */ -extern int dirname_r(const char* path, char* buffer, size_t bufflen); -extern int basename_r(const char* path, char* buffer, size_t bufflen); +#if !defined(__LP64__) +/* These non-standard functions are not needed on Android; basename and dirname use thread-local storage. */ +extern int dirname_r(const char*, char*, size_t); +extern int basename_r(const char*, char*, size_t); +#endif __END_DECLS |