auto import from //branches/cupcake/...@130745
diff --git a/libc/include/pthread.h b/libc/include/pthread.h
index 9c40099..e3afdae 100644
--- a/libc/include/pthread.h
+++ b/libc/include/pthread.h
@@ -97,6 +97,9 @@
 #define PTHREAD_PROCESS_PRIVATE  0
 #define PTHREAD_PROCESS_SHARED   1
 
+#define PTHREAD_SCOPE_SYSTEM     0
+#define PTHREAD_SCOPE_PROCESS    1
+
 /*
  * Prototypes
  */
@@ -128,6 +131,9 @@
 int pthread_attr_setguardsize(pthread_attr_t * attr, size_t guard_size);
 int pthread_attr_getguardsize(pthread_attr_t const * attr, size_t * guard_size);
 
+int pthread_attr_setscope(pthread_attr_t *attr, int  scope);
+int pthread_attr_getscope(pthread_attr_t const *attr);
+
 int pthread_getattr_np(pthread_t thid, pthread_attr_t * attr);
 
 int pthread_create(pthread_t *thread, pthread_attr_t const * attr,
diff --git a/libc/include/string.h b/libc/include/string.h
index 435923b..613dcd7 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -82,9 +82,8 @@
 
 extern char*  strsignal(int  sig);
 
-/* Just declared to make libstdc++-v3 happy.  */
-extern int    strcoll (const char *, const char *);
-extern size_t strxfrm (char *, const char *, size_t);
+extern int    strcoll(const char *, const char *);
+extern size_t strxfrm(char *, const char *, size_t);
 
 __END_DECLS
 
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index 5e6363f..23ab5ae 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -71,6 +71,10 @@
     unsigned long long  st_ino;
 };
 
+extern int    chmod(const char *, mode_t);
+extern int    fchmod(int, mode_t);
+extern int    mkdir(const char *, mode_t);
+
 extern int    stat(const char *, struct stat *);
 extern int    fstat(int, struct stat *);
 extern int    lstat(const char *, struct stat *);
diff --git a/libc/include/sys/time.h b/libc/include/sys/time.h
index 4dee4da..1f010d4 100644
--- a/libc/include/sys/time.h
+++ b/libc/include/sys/time.h
@@ -56,7 +56,7 @@
 #define timeradd(a, b, res)                           \
     do {                                              \
         (res)->tv_sec  = (a)->tv_sec  + (b)->tv_sec;  \
-        (res)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
+        (res)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
         if ((res)->tv_usec >= 1000000) {              \
             (res)->tv_usec -= 1000000;                \
             (res)->tv_sec  += 1;                      \
diff --git a/libc/include/sys/types.h b/libc/include/sys/types.h
index 92b452c..b071ee9 100644
--- a/libc/include/sys/types.h
+++ b/libc/include/sys/types.h
@@ -65,6 +65,7 @@
 #define _OFF_T_DEFINED_
 typedef __kernel_off_t       off_t;
 typedef __kernel_loff_t      loff_t;
+typedef loff_t               off64_t;  /* GLibc-specific */
 
 typedef __kernel_pid_t		 pid_t;
 
diff --git a/libc/include/time64.h b/libc/include/time64.h
new file mode 100644
index 0000000..9da4bc7
--- /dev/null
+++ b/libc/include/time64.h
@@ -0,0 +1,54 @@
+/*
+
+Copyright (c) 2007-2008  Michael G Schwern
+
+This software originally derived from Paul Sheer's pivotal_gmtime_r.c.
+
+The MIT License:
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+Origin: http://code.google.com/p/y2038
+Modified for Bionic by the Android Open Source Project
+
+*/
+#ifndef TIME64_H
+#define TIME64_H
+
+#include <time.h>
+#include <stdint.h>
+
+typedef int64_t  time64_t;
+
+struct tm *gmtime64_r (const time64_t *, struct tm *);
+struct tm *localtime64_r (const time64_t *, struct tm *);
+struct tm *gmtime64 (const time64_t *);
+struct tm *localtime64 (const time64_t *);
+
+char *asctime64 (const struct tm *);
+char *asctime64_r (const struct tm *, char *);
+
+char *ctime64 (const time64_t*);
+char *ctime64_r (const time64_t*, char*);
+
+time64_t timegm64 (const struct tm *);
+time64_t mktime64 (const struct tm *);
+time64_t timelocal64 (const struct tm *);
+
+#endif /* TIME64_H */
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index b6d70cc..1ada37e 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -34,6 +34,7 @@
 #include <sys/select.h>
 #include <sys/sysconf.h>
 #include <linux/capability.h>
+#include <pathconf.h>
 
 __BEGIN_DECLS
 
@@ -111,9 +112,6 @@
 extern int unlink(const char *);
 extern int chdir(const char *);
 extern int fchdir(int);
-extern int chmod(const char *, mode_t);
-extern int fchmod(int, mode_t);
-extern int mkdir(const char *, mode_t);
 extern int rmdir(const char *);
 extern int pipe(int *);
 extern int chroot(const char *);