diff options
author | Elliott Hughes <enh@google.com> | 2015-04-03 14:53:01 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-04-03 14:53:01 +0000 |
commit | 16bcaac5fd8fac754148d3f82cb1d2bfef28f4dd (patch) | |
tree | bf654634dc0123b4058d02cc049c42dde5e70ef4 /include | |
parent | 84dbd37b99e2a2e252aa96e940dadb49b95f148e (diff) | |
parent | cd8683709c2d1bcac7e3b9de827a2dfc8f24bf09 (diff) | |
download | system_core-16bcaac5fd8fac754148d3f82cb1d2bfef28f4dd.zip system_core-16bcaac5fd8fac754148d3f82cb1d2bfef28f4dd.tar.gz system_core-16bcaac5fd8fac754148d3f82cb1d2bfef28f4dd.tar.bz2 |
am cd868370: am b2c3473d: am 70df6f85: Merge "Just use snprintf for android_get_control_socket."
* commit 'cd8683709c2d1bcac7e3b9de827a2dfc8f24bf09':
Just use snprintf for android_get_control_socket.
Diffstat (limited to 'include')
-rw-r--r-- | include/cutils/sockets.h | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/include/cutils/sockets.h b/include/cutils/sockets.h index c47588c..f8076ca 100644 --- a/include/cutils/sockets.h +++ b/include/cutils/sockets.h @@ -18,6 +18,7 @@ #define __CUTILS_SOCKETS_H #include <errno.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> @@ -46,30 +47,19 @@ extern "C" { */ static inline int android_get_control_socket(const char *name) { - char key[64] = ANDROID_SOCKET_ENV_PREFIX; - const char *val; - int fd; + char key[64]; + snprintf(key, sizeof(key), ANDROID_SOCKET_ENV_PREFIX "%s", name); - /* build our environment variable, counting cycles like a wolf ... */ -#if HAVE_STRLCPY - 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) + const char* val = getenv(key); + if (!val) { return -1; + } errno = 0; - fd = strtol(val, NULL, 10); - if (errno) + int fd = strtol(val, NULL, 10); + if (errno) { return -1; + } return fd; } |