Code drop from //branches/cupcake/...@124589
diff --git a/libc/include/dirent.h b/libc/include/dirent.h
index edfb639..55eef7b 100644
--- a/libc/include/dirent.h
+++ b/libc/include/dirent.h
@@ -68,6 +68,11 @@
 extern  int              closedir(DIR*  dirp);
 extern  void             rewinddir(DIR *dirp);
 extern  int              dirfd(DIR* dirp);
+extern  int              alphasort(const void *a, const void *b);
+extern  int              scandir(const char *dir, struct dirent ***namelist,
+                                 int(*filter)(const struct dirent *),
+                                 int(*compar)(const struct dirent **, 
+                                              const struct dirent **));
 
 __END_DECLS
 
diff --git a/libc/include/utility b/libc/include/features.h
similarity index 67%
copy from libc/include/utility
copy to libc/include/features.h
index 12044a7..343c84d 100644
--- a/libc/include/utility
+++ b/libc/include/features.h
@@ -25,14 +25,34 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#ifndef _CPP_UTILITY
-#define _CPP_UTILITY
+#ifndef _FEATURES_H_
+#define _FEATURES_H_
 
-#pragma GCC system_header
+/* certain Linux-specific programs expect a <features.h> header file
+ * that defines various features macros
+ */
 
-#define  __STL_BEGIN_NAMESPACE  namespace std {
-#define  __STL_END_NAMESPACE    }
+/* we do include a number of BSD extensions */
+#define  _BSD_SOURCE  1
 
-#include <stl_pair.h>
+/* we do include a number of GNU extensions */
+#define  _GNU_SOURCE  1
 
-#endif /* _CPP_UTILITY */
+/* C95 support */
+#undef __USE_ISOC95
+#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199409L
+# define __USE_ISOC95   1
+#endif
+
+/* C99 support */
+#undef __USE_ISOC99
+#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
+# define __USE_ISOC99   1
+#endif
+
+/* Posix support */
+#define  __USE_POSIX   1
+#define  __USE_POSIX2  1
+#define  __USE_XPG     1
+
+#endif /* _FEATURES_H_ */
diff --git a/libc/include/grp.h b/libc/include/grp.h
index 4efc2bd..86d99f3 100644
--- a/libc/include/grp.h
+++ b/libc/include/grp.h
@@ -74,6 +74,9 @@
 
 int   getgrouplist (const char *user, gid_t group,
                   gid_t *groups, int *ngroups);
+
+int   initgroups (const char *user, gid_t group);
+
 __END_DECLS
 
 #endif /* !_GRP_H_ */
diff --git a/libc/include/net/if.h b/libc/include/net/if.h
index 763ac5b..9044fc5 100644
--- a/libc/include/net/if.h
+++ b/libc/include/net/if.h
@@ -37,5 +37,6 @@
  * Map an interface name into its corresponding index.
  */
 extern unsigned int if_nametoindex(const char *);
+extern char*        if_indextoname(unsigned ifindex, char *ifname);
 
 __END_DECLS
diff --git a/libc/include/netdb.h b/libc/include/netdb.h
index 9209590..e824a3a 100644
--- a/libc/include/netdb.h
+++ b/libc/include/netdb.h
@@ -153,9 +153,10 @@
 #define	EAI_SERVICE	 9	/* servname not supported for ai_socktype */
 #define	EAI_SOCKTYPE	10	/* ai_socktype not supported */
 #define	EAI_SYSTEM	11	/* system error returned in errno */
-#define	EAI_BADHINTS	12
-#define	EAI_PROTOCOL	13
-#define	EAI_MAX		14
+#define	EAI_BADHINTS	12	/* invalid value for hints */
+#define	EAI_PROTOCOL	13	/* resolved protocol is unknown */
+#define	EAI_OVERFLOW	14	/* argument buffer overflow */
+#define	EAI_MAX		15
 
 /*
  * Flag values for getaddrinfo()
diff --git a/libc/include/netinet/in.h b/libc/include/netinet/in.h
index 8bffbef..77ae506 100644
--- a/libc/include/netinet/in.h
+++ b/libc/include/netinet/in.h
@@ -31,6 +31,7 @@
 #include <endian.h>
 #include <linux/socket.h>
 #include <linux/in.h>
+#include <linux/in6.h>
 
 __BEGIN_DECLS
 
diff --git a/libc/include/netinet/in6.h b/libc/include/netinet/in6.h
index 330e718..e645c48 100644
--- a/libc/include/netinet/in6.h
+++ b/libc/include/netinet/in6.h
@@ -36,6 +36,12 @@
 	 (*(const uint32_t *)(const void *)(&(a)->s6_addr[8]) == 0) &&	\
 	 (*(const uint32_t *)(const void *)(&(a)->s6_addr[12]) == 0))
 
+#define IN6_IS_ADDR_LOOPBACK(a)		\
+	((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) &&	\
+	 (*(const uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) &&	\
+	 (*(const uint32_t *)(const void *)(&(a)->s6_addr[8]) == 0) &&	\
+	 (*(const uint32_t *)(const void *)(&(a)->s6_addr[12]) == ntohl(1)))
+
 #define IN6_IS_ADDR_V4COMPAT(a)		\
 	((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) &&	\
 	 (*(const uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) &&	\
@@ -54,10 +60,34 @@
 #define IN6_IS_ADDR_SITELOCAL(a)	\
 	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
 
-#define IN6_IS_ADDR_MULTICAST(a) \
-    (((__const uint8_t *) (a))[0] == 0xff)
+#define IN6_IS_ADDR_MULTICAST(a)	\
+	(((__const uint8_t *) (a))[0] == 0xff)
+
+
+#define IPV6_ADDR_SCOPE_NODELOCAL       0x01
+#define IPV6_ADDR_SCOPE_INTFACELOCAL    0x01
+#define IPV6_ADDR_SCOPE_LINKLOCAL       0x02
+#define IPV6_ADDR_SCOPE_SITELOCAL       0x05
+#define IPV6_ADDR_SCOPE_ORGLOCAL        0x08
+#define IPV6_ADDR_SCOPE_GLOBAL          0x0e
+
+#define IPV6_ADDR_MC_SCOPE(a)	\
+	((a)->s6_addr[1] & 0x0f)
+
+#define IN6_IS_ADDR_MC_LINKLOCAL(a)	\
+	(IN6_IS_ADDR_MULTICAST(a) &&  \
+	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL))
+#define IN6_IS_ADDR_MC_SITELOCAL(a)     \
+	(IN6_IS_ADDR_MULTICAST(a) &&  \
+	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL))
+#define IN6_IS_ADDR_MC_ORGLOCAL(a)     \
+	(IN6_IS_ADDR_MULTICAST(a) &&  \
+	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL))
+
 
 #define IN6_ARE_ADDR_EQUAL(a, b)			\
     (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
 
+#define INET6_ADDRSTRLEN 46
+
 #endif /* _NETINET_IN6_H */
diff --git a/libc/include/pthread.h b/libc/include/pthread.h
index f7dd766..9c40099 100644
--- a/libc/include/pthread.h
+++ b/libc/include/pthread.h
@@ -148,6 +148,8 @@
 int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
 int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type);
 int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
+int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int  pshared);
+int pthread_mutexattr_getpshared(pthread_mutexattr_t *attr, int *pshared);
 
 int pthread_mutex_init(pthread_mutex_t *mutex,
                        const pthread_mutexattr_t *attr);
diff --git a/libc/include/signal.h b/libc/include/signal.h
index bdda84f..5540847 100644
--- a/libc/include/signal.h
+++ b/libc/include/signal.h
@@ -114,6 +114,7 @@
 extern int sigpending(sigset_t *);
 extern int sigsuspend(const sigset_t *);
 extern int sigwait(const sigset_t *set, int *sig);
+extern int siginterrupt(int  sig, int  flag);
 
 extern int raise(int);
 extern int kill(pid_t, int);
diff --git a/libc/include/stdint.h b/libc/include/stdint.h
index 17f32b7..39a8ab8 100644
--- a/libc/include/stdint.h
+++ b/libc/include/stdint.h
@@ -41,6 +41,11 @@
 #  define  __STDINT_MACROS
 #endif
 
+/* the definitions of STDINT_LIMITS depend on those of STDINT_MACROS */
+#if defined __STDINT_LIMITS && !defined __STDINT_MACROS
+#  define  __STDINT_MACROS
+#endif
+
 typedef __int8_t      int8_t;
 typedef __uint8_t     uint8_t;
 typedef __int16_t     int16_t;
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index 9f62d63..b3b0adf 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -292,7 +292,7 @@
 FILE	*fdopen(int, const char *);
 int	 fileno(FILE *);
 
-#if __POSIX_VISIBLE >= 199209
+#if (__POSIX_VISIBLE >= 199209) || 1 /* ANDROID: Bionic does include this */
 int	 pclose(FILE *);
 FILE	*popen(const char *, const char *);
 #endif
@@ -317,12 +317,6 @@
 #endif
 __END_DECLS
 
-#ifndef _POSIX_THREADS
-#  define flockfile(fp)			/* nothing */
-#  define ftrylockfile(fp)		(0)
-#  define funlockfile(fp)		/* nothing */
-#endif
-
 #endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */
 
 /*
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index ff3c1f7..15925e3 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -134,6 +134,32 @@
   return 0;     /* devpts does this all for us! */
 }
 
+typedef struct {
+    int  quot;
+    int  rem;
+} div_t;
+
+extern div_t   div(int, int);
+
+typedef struct {
+    long int  quot;
+    long int  rem;
+} ldiv_t;
+
+extern ldiv_t   ldiv(long, long);
+
+typedef struct {
+    long long int  quot;
+    long long int  rem;
+} lldiv_t;
+
+extern lldiv_t   lldiv(long long, long long);
+
+/* make STLPort happy */
+extern int      mblen(const char *, size_t);
+extern size_t   mbstowcs(wchar_t *, const char *, size_t);
+extern int      mbtowc(wchar_t *, const char *, size_t);
+
 __END_DECLS
 
 #endif /* _STDLIB_H_ */
diff --git a/libc/include/stl_pair.h b/libc/include/stl_pair.h
deleted file mode 100644
index 08180b0..0000000
--- a/libc/include/stl_pair.h
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-/*
- *
- * Copyright (c) 1994
- * Hewlett-Packard Company
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation.  Hewlett-Packard Company makes no
- * representations about the suitability of this software for any
- * purpose.  It is provided "as is" without express or implied warranty.
- *
- *
- * Copyright (c) 1996,1997
- * Silicon Graphics Computer Systems, Inc.
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation.  Silicon Graphics makes no
- * representations about the suitability of this software for any
- * purpose.  It is provided "as is" without express or implied warranty.
- */
-
-/* NOTE: This is an internal header file, included by other STL headers.
- *   You should not attempt to use it directly.
- */
-
-#ifndef __SGI_STL_INTERNAL_PAIR_H
-#define __SGI_STL_INTERNAL_PAIR_H
-
-__STL_BEGIN_NAMESPACE
-
-template <class _T1, class _T2>
-struct pair {
-  typedef _T1 first_type;
-  typedef _T2 second_type;
-
-  _T1 first;
-  _T2 second;
-  pair() : first(), second() {}
-  pair(const _T1& __a, const _T2& __b) : first(__a), second(__b) {}
-
-  template <class _U1, class _U2>
-  pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}
-};
-
-template <class _T1, class _T2>
-inline bool operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
-{
-  return __x.first == __y.first && __x.second == __y.second;
-}
-
-template <class _T1, class _T2>
-inline bool operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
-{
-  return __x.first < __y.first ||
-         (!(__y.first < __x.first) && __x.second < __y.second);
-}
-
-template <class _T1, class _T2>
-inline bool operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
-  return !(__x == __y);
-}
-
-template <class _T1, class _T2>
-inline bool operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
-  return __y < __x;
-}
-
-template <class _T1, class _T2>
-inline bool operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
-  return !(__y < __x);
-}
-
-template <class _T1, class _T2>
-inline bool operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
-  return !(__x < __y);
-}
-
-template <class _T1, class _T2>
-inline pair<_T1, _T2> make_pair(_T1 __x, _T2 __y)
-{
-  return pair<_T1, _T2>(__x, __y);
-}
-
-} // namespace std
-
-#endif /* __SGI_STL_INTERNAL_PAIR_H */
-
-// Local Variables:
-// mode:C++
-// End:
diff --git a/libc/include/sys/_system_properties.h b/libc/include/sys/_system_properties.h
index a145927..42a7f6c 100644
--- a/libc/include/sys/_system_properties.h
+++ b/libc/include/sys/_system_properties.h
@@ -61,16 +61,16 @@
 #define SERIAL_DIRTY(serial) ((serial) & 1)
 
 struct prop_info {
-    unsigned char name[PROP_NAME_MAX];
+    char name[PROP_NAME_MAX];
     unsigned volatile serial;
-    unsigned char value[PROP_VALUE_MAX];
+    char value[PROP_VALUE_MAX];
 };
 
 struct prop_msg 
 {
     unsigned cmd;
-    unsigned char name[PROP_NAME_MAX];
-    unsigned char value[PROP_VALUE_MAX];
+    char name[PROP_NAME_MAX];
+    char value[PROP_VALUE_MAX];
 };
 
 #define PROP_MSG_SETPROP 1
diff --git a/libc/include/sys/atomics.h b/libc/include/sys/atomics.h
index fbf9b6e..d3fa145 100644
--- a/libc/include/sys/atomics.h
+++ b/libc/include/sys/atomics.h
@@ -29,6 +29,7 @@
 #define _SYS_ATOMICS_H
 
 #include <sys/cdefs.h>
+#include <sys/time.h>
 
 __BEGIN_DECLS
 
diff --git a/libc/include/sys/linux-syscalls.h b/libc/include/sys/linux-syscalls.h
index b6912ad..bed00ce 100644
--- a/libc/include/sys/linux-syscalls.h
+++ b/libc/include/sys/linux-syscalls.h
@@ -37,7 +37,6 @@
 #define __NR_getrusage                    (__NR_SYSCALL_BASE + 77)
 #define __NR_setgroups32                  (__NR_SYSCALL_BASE + 206)
 #define __NR_setpgid                      (__NR_SYSCALL_BASE + 57)
-#define __NR_vfork                        (__NR_SYSCALL_BASE + 190)
 #define __NR_setregid32                   (__NR_SYSCALL_BASE + 204)
 #define __NR_chroot                       (__NR_SYSCALL_BASE + 61)
 #define __NR_prctl                        (__NR_SYSCALL_BASE + 172)
@@ -46,6 +45,8 @@
 #define __NR_acct                         (__NR_SYSCALL_BASE + 51)
 #define __NR_read                         (__NR_SYSCALL_BASE + 3)
 #define __NR_write                        (__NR_SYSCALL_BASE + 4)
+#define __NR_pread64                      (__NR_SYSCALL_BASE + 180)
+#define __NR_pwrite64                     (__NR_SYSCALL_BASE + 181)
 #define __NR_open                         (__NR_SYSCALL_BASE + 5)
 #define __NR_close                        (__NR_SYSCALL_BASE + 6)
 #define __NR_lseek                        (__NR_SYSCALL_BASE + 19)
@@ -100,6 +101,7 @@
 #define __NR_settimeofday                 (__NR_SYSCALL_BASE + 79)
 #define __NR_times                        (__NR_SYSCALL_BASE + 43)
 #define __NR_nanosleep                    (__NR_SYSCALL_BASE + 162)
+#define __NR_getitimer                    (__NR_SYSCALL_BASE + 105)
 #define __NR_setitimer                    (__NR_SYSCALL_BASE + 104)
 #define __NR_sigaction                    (__NR_SYSCALL_BASE + 67)
 #define __NR_sigprocmask                  (__NR_SYSCALL_BASE + 126)
@@ -130,6 +132,7 @@
 #ifdef __arm__
 #define __NR_exit_group                   (__NR_SYSCALL_BASE + 248)
 #define __NR_waitid                       (__NR_SYSCALL_BASE + 280)
+#define __NR_vfork                        (__NR_SYSCALL_BASE + 190)
 #define __NR_openat                       (__NR_SYSCALL_BASE + 322)
 #define __NR_madvise                      (__NR_SYSCALL_BASE + 220)
 #define __NR_mincore                      (__NR_SYSCALL_BASE + 219)
@@ -217,6 +220,7 @@
 #define __NR_timer_getoverrun             (__NR_SYSCALL_BASE + 262)
 #define __NR_timer_delete                 (__NR_SYSCALL_BASE + 263)
 #define __NR_utimes                       (__NR_SYSCALL_BASE + 271)
+#define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
 #define __NR_epoll_create                 (__NR_SYSCALL_BASE + 254)
 #define __NR_epoll_ctl                    (__NR_SYSCALL_BASE + 255)
 #define __NR_epoll_wait                   (__NR_SYSCALL_BASE + 256)
diff --git a/libc/include/sys/linux-unistd.h b/libc/include/sys/linux-unistd.h
index a3ffa3e..8539c7b 100644
--- a/libc/include/sys/linux-unistd.h
+++ b/libc/include/sys/linux-unistd.h
@@ -7,7 +7,7 @@
 
 void             _exit (int);
 void             _exit_thread (int);
-int              fork (void);
+pid_t            __fork (void);
 pid_t            _waitpid (pid_t, int*, int, struct rusage*);
 int              waitid (int, pid_t, struct siginfo_t*, int,void*);
 pid_t            __clone (int (*fn)(void*), void *child_stack, int flags, void *arg);
@@ -51,6 +51,8 @@
 int              acct (const char*  filepath);
 ssize_t          read (int, void*, size_t);
 ssize_t          write (int, const void*, size_t);
+ssize_t          __pread64 (int, void *, size_t, off_t, off_t);
+ssize_t          __pwrite64 (int, void *, size_t, off_t, off_t);
 int              __open (const char*, int, mode_t);
 int              __openat (int, const char*, int, mode_t);
 int              close (int);
@@ -124,12 +126,13 @@
 int              clock_settime (clockid_t clk_id, const struct timespec *tp);
 int              clock_getres (clockid_t clk_id, struct timespec *res);
 int              clock_nanosleep (const struct timespec *req, struct timespec *rem);
+int              getitimer (int, const struct itimerval *);
 int              setitimer (int, const struct itimerval *, struct itimerval *);
-int              timer_create (clockid_t clockid, struct sigevent *evp, timer_t *timerid);
-int              timer_settime (timer_t, int, const struct itimerspec*, struct itimerspec*);
-int              timer_gettime (timer_t, struct itimerspec*);
-int              timer_getoverrun (timer_t);
-int              timer_delete (timer_t);
+int              __timer_create (clockid_t clockid, struct sigevent *evp, timer_t *timerid);
+int              __timer_settime (timer_t, int, const struct itimerspec*, struct itimerspec*);
+int              __timer_gettime (timer_t, struct itimerspec*);
+int              __timer_getoverrun (timer_t);
+int              __timer_delete (timer_t);
 int              utimes (const char*, const struct timeval tvp[2]);
 int              sigaction (int, const struct sigaction *, struct sigaction *);
 int              sigprocmask (int, const sigset_t *, sigset_t *);
@@ -153,6 +156,21 @@
 int              getsockopt (int, int, int, void *, socklen_t *);
 int              sendmsg (int, const struct msghdr *, unsigned int);
 int              recvmsg (int, struct msghdr *, unsigned int);
+int              socket (int, int, int);
+int              bind (int, struct sockaddr *, int);
+int              connect (int, struct sockaddr *, socklen_t);
+int              listen (int, int);
+int              accept (int, struct sockaddr *, socklen_t *);
+int              getsockname (int, struct sockaddr *, socklen_t *);
+int              getpeername (int, struct sockaddr *, socklen_t *);
+int              socketpair (int, int, int, int*);
+int              sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t);
+int              recvfrom (int, void *, size_t, unsigned int, struct sockaddr *, socklen_t *);
+int              shutdown (int, int);
+int              setsockopt (int, int, int, const void *, socklen_t);
+int              getsockopt (int, int, int, void *, socklen_t *);
+int              sendmsg (int, const struct msghdr *, unsigned int);
+int              recvmsg (int, struct msghdr *, unsigned int);
 int              sched_setscheduler (pid_t pid, int policy, const struct sched_param *param);
 int              sched_getscheduler (pid_t pid);
 int              sched_yield (void);
diff --git a/libc/include/sys/socket.h b/libc/include/sys/socket.h
index 85516fe..208663e 100644
--- a/libc/include/sys/socket.h
+++ b/libc/include/sys/socket.h
@@ -42,7 +42,7 @@
 #define SOCK_PACKET      10
 
 #ifdef __i386__
-# define __socketcall extern __cdecl
+# define __socketcall extern __attribute__((__cdecl__))
 #else
 # define __socketcall extern
 #endif
diff --git a/libc/include/utility b/libc/include/sys/timeb.h
similarity index 82%
rename from libc/include/utility
rename to libc/include/sys/timeb.h
index 12044a7..f2cc39c 100644
--- a/libc/include/utility
+++ b/libc/include/sys/timeb.h
@@ -25,14 +25,22 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#ifndef _CPP_UTILITY
-#define _CPP_UTILITY
+#ifndef _SYS_TIMEB_H
+#define _SYS_TIMEB_H
 
-#pragma GCC system_header
+#include <sys/time.h>
 
-#define  __STL_BEGIN_NAMESPACE  namespace std {
-#define  __STL_END_NAMESPACE    }
+__BEGIN_DECLS
 
-#include <stl_pair.h>
+struct timeb {
+    time_t          time;
+    unsigned short  millitm;
+    short           timezone;
+    short           dstflag;
+};
 
-#endif /* _CPP_UTILITY */
+extern int  ftime(struct timeb*  timebuf);
+
+__END_DECLS
+
+#endif /* _SYS_TIMEB_H */
diff --git a/libc/include/termios.h b/libc/include/termios.h
index 043fe16..ad19089 100644
--- a/libc/include/termios.h
+++ b/libc/include/termios.h
@@ -66,22 +66,11 @@
     return ioctl(fd, TCFLSH, (void *)(intptr_t)__queue);
 }
 
-static __inline__ pid_t tcgetpgrp(int fd)
-{
-    pid_t _pid;
-    return ioctl(fd, TIOCGPGRP, &_pid) ? (pid_t)-1 : _pid;
-}
-
-static __inline__ int tcsetpgrp(int fd, pid_t _pid)
-{
-    return ioctl(fd, TIOCSPGRP, &_pid);
-}
-
 static __inline__ pid_t tcgetsid(int fd)
 {
     pid_t _pid;
     return ioctl(fd, TIOCGSID, &_pid) ? (pid_t)-1 : _pid;
-}  
+}
 
 static __inline__ int tcsendbreak(int fd, int __duration)
 {
diff --git a/libc/include/time.h b/libc/include/time.h
index 5251ff3..35c2358 100644
--- a/libc/include/time.h
+++ b/libc/include/time.h
@@ -64,6 +64,7 @@
 #define   TM_ZONE   tm_zone
 
 extern char* asctime(const struct tm* a);
+extern char* asctime_r(const struct tm* a, char* buf);
 
 /* Return the difference between TIME1 and TIME0.  */
 extern double difftime (time_t __time1, time_t __time0);
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index 096b152..b6d70cc 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -184,6 +184,8 @@
 /* A special syscall that is only available on the ARM, not x86 function. */
 extern int cacheflush(long start, long end, long flags);
 
+extern pid_t tcgetpgrp(int fd);
+extern int   tcsetpgrp(int fd, pid_t _pid);
 
 __END_DECLS
 
diff --git a/libc/include/wchar.h b/libc/include/wchar.h
index 7ff6ffc..d2d022a 100644
--- a/libc/include/wchar.h
+++ b/libc/include/wchar.h
@@ -44,7 +44,11 @@
 
 __BEGIN_DECLS
 
-typedef unsigned char           wchar_t;
+#ifndef __cplusplus
+/* wchar_t is a builtin keyword of g++ */
+typedef unsigned char            wchar_t;
+#endif
+
 typedef int                     wint_t;
 typedef struct { int  dummy; }  mbstate_t;