Move android_get_control_socket out of line

android_get_control_socket has a warning from the implicit cast from
long to int.  The warning was being hidden because cutils/sockets.h was
included with -isystem.  Move android_get_control_socket to sockets.cpp,
since we don't want header only dependencies anyways, and fix the
warning with a range check and a static_cast.

Bug: 31492149
Test: m -j <module that uses sockets.h and -Wall>
Change-Id: I1f394ab26d4ec8a7dd0e7907c10416d7f8647624
diff --git a/libcutils/sockets.cpp b/libcutils/sockets.cpp
index d9ab146..bba63ac 100644
--- a/libcutils/sockets.cpp
+++ b/libcutils/sockets.cpp
@@ -45,3 +45,24 @@
     }
     return -1;
 }
+
+int android_get_control_socket(const char* name) {
+    char key[64];
+    snprintf(key, sizeof(key), ANDROID_SOCKET_ENV_PREFIX "%s", name);
+
+    const char* val = getenv(key);
+    if (!val) {
+        return -1;
+    }
+
+    errno = 0;
+    long ret = strtol(val, NULL, 10);
+    if (errno) {
+        return -1;
+    }
+    if (ret < 0 || ret > INT_MAX) {
+        return -1;
+    }
+
+    return static_cast<int>(ret);
+}