Merge "Add accept4 unit test to bionic."
diff --git a/libc/bionic/strtotimeval.c b/libc/bionic/strtotimeval.c
index 1c132ec..195381b 100644
--- a/libc/bionic/strtotimeval.c
+++ b/libc/bionic/strtotimeval.c
@@ -30,34 +30,29 @@
 #include <stdlib.h>
 #include <sys/time.h>
 
-char * strtotimeval (const char *str, struct timeval *ts)
-{
-    int n;
-    char *s, *s0;
-    long  fs;	/* Fractional seconds */
+char * strtotimeval(const char *str, struct timeval *ts) {
+  char *s;
+  long fs = 0; /* fractional seconds */
 
-    ts->tv_sec = strtoumax(str, &s, 10);
-    fs = 0;
+  ts->tv_sec = strtoumax(str, &s, 10);
 
-    if ( *s == '.' ) {
-	int  count;
+  if (*s == '.') {
+    s++;
+    int count = 0;
 
-        s0 = s+1;
-
-	/* read up to 6 digits */
-	fs    = 0;
-	count = 0;
-	while ( *s && isdigit(*s) )
-	{
-            if ( ++count < 7 )
-	        fs = fs*10 + (*s - '0');
-	    s++;
-	}
-
-	for ( ; count < 6; count++ )
-	    fs *= 10;
+    /* read up to 6 digits (microseconds) */
+    while (*s && isdigit(*s)) {
+      if (++count < 7) {
+        fs = fs*10 + (*s - '0');
+      }
+      s++;
     }
 
-    ts->tv_usec = fs;
-    return s;
+    for (; count < 6; count++) {
+      fs *= 10;
+    }
+  }
+
+  ts->tv_usec = fs;
+  return s;
 }
diff --git a/linker/Android.mk b/linker/Android.mk
index 1d03a9c..c517a30 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -1,9 +1,70 @@
 LOCAL_PATH:= $(call my-dir)
 
-linker_2nd_arch_var_prefix :=
-include $(LOCAL_PATH)/linker.mk
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
 
+LOCAL_SRC_FILES:= \
+    debugger.cpp \
+    dlfcn.cpp \
+    linker.cpp \
+    linker_environ.cpp \
+    linker_phdr.cpp \
+    rt.cpp \
+
+LOCAL_SRC_FILES_arm     := arch/arm/begin.S
+LOCAL_SRC_FILES_arm64   := arch/arm64/begin.S
+LOCAL_SRC_FILES_x86     := arch/x86/begin.c
+LOCAL_SRC_FILES_x86_64  := arch/x86_64/begin.S
+LOCAL_SRC_FILES_mips    := arch/mips/begin.S
+
+LOCAL_LDFLAGS := \
+    -shared \
+    -Wl,-Bsymbolic \
+    -Wl,--exclude-libs,ALL \
+
+LOCAL_CFLAGS += \
+    -fno-stack-protector \
+    -Wstrict-overflow=5 \
+    -fvisibility=hidden \
+    -Wall -Wextra -Werror \
+
+LOCAL_CONLYFLAGS += \
+    -std=gnu99 \
+
+LOCAL_CPPFLAGS += \
+    -std=gnu++11 \
+
+# We need to access Bionic private headers in the linker.
+LOCAL_CFLAGS += -I$(LOCAL_PATH)/../libc/
+
+# we don't want crtbegin.o (because we have begin.o), so unset it
+# just for this module
+LOCAL_NO_CRT := true
+# TODO: split out the asflags.
+LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
+
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/linker_executable.mk
+
+LOCAL_STATIC_LIBRARIES := libc_nomalloc
+
+LOCAL_FORCE_STATIC_EXECUTABLE := true # not necessary when not including BUILD_EXECUTABLE
+
+LOCAL_2ND_ARCH_VAR_PREFIX := $(linker_2nd_arch_var_prefix)
+
+LOCAL_MODULE := linker
+LOCAL_MODULE_STEM_32 := linker
+LOCAL_MODULE_STEM_64 := linker64
+LOCAL_MULTILIB := both
+
+include $(LOCAL_PATH)/linker_executable.mk
 ifdef TARGET_2ND_ARCH
-linker_2nd_arch_var_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
-include $(LOCAL_PATH)/linker.mk
+LOCAL_2ND_ARCH_VAR_PREFIX := $(TARGET_2ND_ARCH_VAR_PREFIX)
+OVERRIDE_BUILT_MODULE_PATH :=
+LOCAL_BUILT_MODULE :=
+LOCAL_INSTALLED_MODULE :=
+LOCAL_MODULE_STEM :=
+LOCAL_BUILT_MODULE_STEM :=
+LOCAL_INSTALLED_MODULE_STEM :=
+LOCAL_INTERMEDIATE_TARGETS :=
+include $(LOCAL_PATH)/linker_executable.mk
 endif
diff --git a/linker/linker.mk b/linker/linker.mk
deleted file mode 100644
index 384435a..0000000
--- a/linker/linker.mk
+++ /dev/null
@@ -1,58 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-    debugger.cpp \
-    dlfcn.cpp \
-    linker.cpp \
-    linker_environ.cpp \
-    linker_phdr.cpp \
-    rt.cpp \
-
-LOCAL_SRC_FILES_arm     := arch/arm/begin.S
-LOCAL_SRC_FILES_arm64   := arch/arm64/begin.S
-LOCAL_SRC_FILES_x86     := arch/x86/begin.c
-LOCAL_SRC_FILES_x86_64  := arch/x86_64/begin.S
-LOCAL_SRC_FILES_mips    := arch/mips/begin.S
-
-LOCAL_LDFLAGS := \
-    -shared \
-    -Wl,-Bsymbolic \
-    -Wl,--exclude-libs,ALL \
-
-LOCAL_CFLAGS += \
-    -fno-stack-protector \
-    -Wstrict-overflow=5 \
-    -fvisibility=hidden \
-    -Wall -Wextra -Werror \
-
-LOCAL_CONLYFLAGS += \
-    -std=gnu99 \
-
-LOCAL_CPPFLAGS += \
-    -std=gnu++11 \
-
-# We need to access Bionic private headers in the linker.
-LOCAL_CFLAGS += -I$(LOCAL_PATH)/../libc/
-
-# we don't want crtbegin.o (because we have begin.o), so unset it
-# just for this module
-LOCAL_NO_CRT := true
-# TODO: split out the asflags.
-LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
-
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/linker.mk $(LOCAL_PATH)/linker_executable.mk
-
-LOCAL_STATIC_LIBRARIES := libc_nomalloc
-
-LOCAL_FORCE_STATIC_EXECUTABLE := true # not necessary when not including BUILD_EXECUTABLE
-
-LOCAL_2ND_ARCH_VAR_PREFIX := $(linker_2nd_arch_var_prefix)
-
-ifeq ($(TARGET_IS_64_BIT)|$(linker_2nd_arch_var_prefix),true|)
-LOCAL_MODULE := linker64
-else
-LOCAL_MODULE := linker
-endif
-
-include $(LOCAL_PATH)/linker_executable.mk
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index 26b7775..c055769 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -387,3 +387,51 @@
   ASSERT_EQ(ESRCH, pthread_detach(tdd.thread_id));
 #endif
 }
+
+TEST(time, strtotimeval) {
+#if defined(__BIONIC__)
+  struct timeval tv1;
+  char* rest1 = strtotimeval("10.123456", &tv1);
+  ASSERT_EQ(10, tv1.tv_sec);
+  ASSERT_EQ(123456, tv1.tv_usec);
+  ASSERT_EQ('\0', *rest1);
+
+  // strtotimeval interprets the fractional part as microseconds and thus will
+  // only consider its first 6 digits. Even so it should consume all valid
+  // digits.
+  struct timeval tv2;
+  char* rest2 = strtotimeval(".1234567", &tv2);
+  ASSERT_EQ(0, tv2.tv_sec);
+  ASSERT_EQ(123456, tv2.tv_usec);
+  ASSERT_EQ('\0', *rest2);
+
+  struct timeval tv3;
+  char* rest3 = strtotimeval("1.1a", &tv3);
+  ASSERT_EQ(1, tv3.tv_sec);
+  ASSERT_EQ(100000, tv3.tv_usec);
+  ASSERT_EQ('a', *rest3);
+
+  struct timeval tv4;
+  char* rest4 = strtotimeval("a", &tv4);
+  ASSERT_EQ(0, tv4.tv_sec);
+  ASSERT_EQ(0, tv4.tv_usec);
+  ASSERT_EQ('a', *rest4);
+
+  struct timeval tv5;
+  char* rest5 = strtotimeval("0", &tv5);
+  ASSERT_EQ(0, tv5.tv_sec);
+  ASSERT_EQ(0, tv5.tv_usec);
+  ASSERT_EQ('\0', *rest5);
+
+  // TODO: should we reject this case and just return '.'?
+  struct timeval tv6;
+  char* rest6 = strtotimeval(".", &tv6);
+  ASSERT_EQ(0, tv6.tv_sec);
+  ASSERT_EQ(0, tv6.tv_usec);
+  ASSERT_EQ('\0', *rest6);
+
+#else // __BIONIC__
+  GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif // __BIONIC__
+}
+