am 70df6f85: Merge "Just use snprintf for android_get_control_socket."

* commit '70df6f85fe8164010be3e4e1cf87e1dd31fb7614':
  Just use snprintf for android_get_control_socket.
This commit is contained in:
Elliott Hughes 2015-04-03 03:45:30 +00:00 committed by Android Git Automerger
commit b2c3473d35

View file

@ -18,6 +18,7 @@
#define __CUTILS_SOCKETS_H #define __CUTILS_SOCKETS_H
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
@ -46,30 +47,19 @@ extern "C" {
*/ */
static inline int android_get_control_socket(const char *name) static inline int android_get_control_socket(const char *name)
{ {
char key[64] = ANDROID_SOCKET_ENV_PREFIX; char key[64];
const char *val; snprintf(key, sizeof(key), ANDROID_SOCKET_ENV_PREFIX "%s", name);
int fd;
/* build our environment variable, counting cycles like a wolf ... */ const char* val = getenv(key);
#if HAVE_STRLCPY if (!val) {
strlcpy(key + sizeof(ANDROID_SOCKET_ENV_PREFIX) - 1,
name,
sizeof(key) - sizeof(ANDROID_SOCKET_ENV_PREFIX));
#else /* for the host, which may lack the almightly strncpy ... */
strncpy(key + sizeof(ANDROID_SOCKET_ENV_PREFIX) - 1,
name,
sizeof(key) - sizeof(ANDROID_SOCKET_ENV_PREFIX));
key[sizeof(key)-1] = '\0';
#endif
val = getenv(key);
if (!val)
return -1; return -1;
}
errno = 0; errno = 0;
fd = strtol(val, NULL, 10); int fd = strtol(val, NULL, 10);
if (errno) if (errno) {
return -1; return -1;
}
return fd; return fd;
} }