resolved conflicts for merge of c8f6b82f to lmp-dev-plus-aosp
Change-Id: I03a4645eb5fbb54e41da25018729b270ba0ed48e
This commit is contained in:
commit
08df25419f
@ -36,22 +36,7 @@
|
|||||||
|
|
||||||
#include "private/ThreadLocalBuffer.h"
|
#include "private/ThreadLocalBuffer.h"
|
||||||
|
|
||||||
GLOBAL_INIT_THREAD_LOCAL_BUFFER(basename);
|
__LIBC64_HIDDEN__ int basename_r(const char* path, char* buffer, size_t buffer_size) {
|
||||||
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) {
|
|
||||||
const char* startp = NULL;
|
const char* startp = NULL;
|
||||||
const char* endp = NULL;
|
const char* endp = NULL;
|
||||||
int len;
|
int len;
|
||||||
@ -103,7 +88,7 @@ int basename_r(const char* path, char* buffer, size_t buffer_size) {
|
|||||||
return result;
|
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;
|
const char* endp = NULL;
|
||||||
int len;
|
int len;
|
||||||
int result;
|
int result;
|
||||||
@ -161,3 +146,18 @@ int dirname_r(const char* path, char* buffer, size_t buffer_size) {
|
|||||||
}
|
}
|
||||||
return result;
|
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;
|
||||||
|
}
|
||||||
|
@ -38,29 +38,21 @@ __BEGIN_DECLS
|
|||||||
/*
|
/*
|
||||||
* <string.h> gets you the GNU basename.
|
* <string.h> gets you the GNU basename.
|
||||||
* <libgen.h> the POSIX one.
|
* <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*);
|
extern char* basename(const char*);
|
||||||
#define __bionic_using_posix_basename
|
#define __bionic_using_posix_basename
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* our version of dirname/basename don't modify the input 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* path);
|
extern char* dirname(const char*);
|
||||||
|
|
||||||
/* special thread-safe Bionic versions
|
#if !defined(__LP64__)
|
||||||
*
|
/* These non-standard functions are not needed on Android; basename and dirname use thread-local storage. */
|
||||||
* if 'buffer' is NULL, 'bufflen' is ignored and the length of the result is returned
|
extern int dirname_r(const char*, char*, size_t);
|
||||||
* otherwise, place result in 'buffer'
|
extern int basename_r(const char*, char*, size_t);
|
||||||
*
|
#endif
|
||||||
* 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);
|
|
||||||
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ TEST(libgen, dirname) {
|
|||||||
TestDirname("/", "/");
|
TestDirname("/", "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__BIONIC__)
|
#if defined(__BIONIC__) && !defined(__LP64__)
|
||||||
static void TestBasename(const char* in, const char* expected_out, int expected_rc,
|
static void TestBasename(const char* in, const char* expected_out, int expected_rc,
|
||||||
char* buf, size_t buf_size, int expected_errno) {
|
char* buf, size_t buf_size, int expected_errno) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
@ -88,7 +88,7 @@ static void TestDirname(const char* in, const char* expected_out, int expected_r
|
|||||||
#endif // __BIONIC__
|
#endif // __BIONIC__
|
||||||
|
|
||||||
TEST(libgen, basename_r) {
|
TEST(libgen, basename_r) {
|
||||||
#if defined(__BIONIC__)
|
#if defined(__BIONIC__) && !defined(__LP64__)
|
||||||
char buf[256];
|
char buf[256];
|
||||||
TestBasename("", ".", 1, NULL, 0, 0);
|
TestBasename("", ".", 1, NULL, 0, 0);
|
||||||
TestBasename("", ".", -1, buf, 0, ERANGE);
|
TestBasename("", ".", -1, buf, 0, ERANGE);
|
||||||
@ -107,7 +107,7 @@ TEST(libgen, basename_r) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(libgen, dirname_r) {
|
TEST(libgen, dirname_r) {
|
||||||
#if defined(__BIONIC__)
|
#if defined(__BIONIC__) && !defined(__LP64__)
|
||||||
char buf[256];
|
char buf[256];
|
||||||
TestDirname("", ".", 1, NULL, 0, 0);
|
TestDirname("", ".", 1, NULL, 0, 0);
|
||||||
TestDirname("", ".", -1, buf, 0, ERANGE);
|
TestDirname("", ".", -1, buf, 0, ERANGE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user