Merge "Replace .S version of x86 crtfiles with .c version"
diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT
index 58e0ac1..2973caa 100644
--- a/libc/SYSCALLS.TXT
+++ b/libc/SYSCALLS.TXT
@@ -62,7 +62,7 @@
 int     getgroups:getgroups(int, gid_t *)      -1,-1,80
 pid_t   getpgid(pid_t)             132
 pid_t   getppid()                  64
-pid_t   getsid(pid_t)              147
+pid_t   getsid(pid_t)              147,147,151
 pid_t   setsid()                   66
 int     setgid:setgid32(gid_t)     214,214,-1
 int     setgid:setgid(gid_t)       -1,-1,46
diff --git a/libc/arch-arm/include/endian.h b/libc/arch-arm/include/endian.h
index 6de0889..7cba3b9 100644
--- a/libc/arch-arm/include/endian.h
+++ b/libc/arch-arm/include/endian.h
@@ -77,7 +77,7 @@
 #endif  /* __ARM_ARCH__ */
 #endif  /* __GNUC__ */
 
-#ifdef __ARMEB__
+#if defined(__ARMEB__)
 #define _BYTE_ORDER _BIG_ENDIAN
 #else
 #define _BYTE_ORDER _LITTLE_ENDIAN
diff --git a/libc/arch-arm/include/machine/_types.h b/libc/arch-arm/include/machine/_types.h
index 3e779ca..1521a4c 100644
--- a/libc/arch-arm/include/machine/_types.h
+++ b/libc/arch-arm/include/machine/_types.h
@@ -35,17 +35,6 @@
 #ifndef _ARM__TYPES_H_
 #define _ARM__TYPES_H_
 
-
-#if !defined(__ARM_EABI__)
-/* the kernel defines size_t as unsigned int, but g++ wants it to be unsigned long */
-#define _SIZE_T
-#define _SSIZE_T
-#define _PTRDIFF_T
-typedef unsigned long  size_t;
-typedef long           ssize_t;
-typedef long           ptrdiff_t;
-#endif
-
 /* 7.18.1.1 Exact-width integer types */
 typedef	__signed char		__int8_t;
 typedef	unsigned char		__uint8_t;
@@ -116,10 +105,4 @@
 typedef	void *			__wctrans_t;
 typedef	void *			__wctype_t;
 
-#ifdef __ARMEB__
-#define _BYTE_ORDER _BIG_ENDIAN
-#else
-#define _BYTE_ORDER _LITTLE_ENDIAN
-#endif
-
 #endif	/* _ARM__TYPES_H_ */
diff --git a/libc/arch-mips/include/endian.h b/libc/arch-mips/include/endian.h
index 6d4ca4e..41a9004 100644
--- a/libc/arch-mips/include/endian.h
+++ b/libc/arch-mips/include/endian.h
@@ -29,17 +29,6 @@
 #ifndef _MIPS64_ENDIAN_H_
 #define _MIPS64_ENDIAN_H_
 
-#if defined(__MIPSEL__)
-#define _BYTE_ORDER _LITTLE_ENDIAN
-#endif
-#if defined(__MIPSEB__)
-#define _BYTE_ORDER _BIG_ENDIAN
-#endif
-
-#if !defined(_BYTE_ORDER) && !defined(lint)
-#error "__MIPSEL__ or __MIPSEB__ must be defined to define BYTE_ORDER!!!"
-#endif
-
 #ifdef __GNUC__
 
 #if defined(__mips_isa_rev) && (__mips_isa_rev >= 2)
@@ -69,9 +58,13 @@
 #endif  /* __mips32r2__ */
 #endif  /* __GNUC__ */
 
-
+#if defined(__MIPSEB__)
+#define _BYTE_ORDER _BIG_ENDIAN
+#else
+#define _BYTE_ORDER _LITTLE_ENDIAN
+#endif
+#define __STRICT_ALIGNMENT
+#include <sys/types.h>
 #include <sys/endian.h>
 
-#define	__STRICT_ALIGNMENT
-
 #endif /* _MIPS64_ENDIAN_H_ */
diff --git a/libc/arch-mips/include/machine/_types.h b/libc/arch-mips/include/machine/_types.h
index 1cc6c21..05f79ef 100644
--- a/libc/arch-mips/include/machine/_types.h
+++ b/libc/arch-mips/include/machine/_types.h
@@ -105,8 +105,6 @@
 typedef float			__float_t;
 typedef long long		__off_t;
 typedef long			__ptrdiff_t;
-/*typedef	unsigned long		__size_t;*/
-typedef	long			__ssize_t;
 typedef	int			__time_t;
 typedef int			__timer_t;
 #if defined(__GNUC__) && __GNUC__ >= 3
@@ -124,12 +122,6 @@
 typedef	void *			__wctrans_t;
 typedef	void *			__wctype_t;
 
-#ifdef __MIPSEB__
-#define _BYTE_ORDER _BIG_ENDIAN
-#else
-#define _BYTE_ORDER _LITTLE_ENDIAN
-#endif
-
 #if defined(_KERNEL)
 typedef struct label_t {
 	__register_t val[14];
diff --git a/libc/arch-x86/include/endian.h b/libc/arch-x86/include/endian.h
index 4a70536..e7ad257 100644
--- a/libc/arch-x86/include/endian.h
+++ b/libc/arch-x86/include/endian.h
@@ -65,6 +65,7 @@
 #endif	/* __GNUC__ */
 
 #define _BYTE_ORDER _LITTLE_ENDIAN
+#include <sys/types.h>
 #include <sys/endian.h>
 
 #endif /* _I386_ENDIAN_H_ */
diff --git a/libc/arch-x86/include/machine/_types.h b/libc/arch-x86/include/machine/_types.h
index d3d9eeb..d217822 100644
--- a/libc/arch-x86/include/machine/_types.h
+++ b/libc/arch-x86/include/machine/_types.h
@@ -35,29 +35,6 @@
 #ifndef _I386__TYPES_H_
 #define _I386__TYPES_H_
 
-/* the kernel defines size_t as unsigned int, but g++ wants it to be unsigned long */
-#ifndef _SIZE_T_DEFINED_
-#  define _SIZE_T_DEFINED_
-#  ifdef __ANDROID__
-     typedef unsigned int  size_t;
-#  else
-     typedef unsigned long  size_t;
-#  endif
-#endif
-#if !defined(_SSIZE_T) && !defined(_SSIZE_T_DEFINED_)
-#define _SSIZE_T
-#define _SSIZE_T_DEFINED_
-typedef long int       ssize_t;
-#endif
-#ifndef _PTRDIFF_T
-#define _PTRDIFF_T
-#  ifdef __ANDROID__
-     typedef int            ptrdiff_t;
-#  else
-     typedef long           ptrdiff_t;
-#  endif
-#endif
-
 /* 7.18.1.1 Exact-width integer types */
 typedef	__signed char		__int8_t;
 typedef	unsigned char		__uint8_t;
diff --git a/libc/include/search.h b/libc/include/search.h
index ed0d216..e12e49e 100644
--- a/libc/include/search.h
+++ b/libc/include/search.h
@@ -12,13 +12,6 @@
 #include <sys/cdefs.h>
 #include <sys/_types.h>
 
-#if 0
-#ifndef _SIZE_T_DECLARED
-typedef	__size_t	size_t;
-#define	_SIZE_T_DECLARED
-#endif
-#endif
-
 typedef	enum {
 	preorder,
 	postorder,
diff --git a/libc/include/stdint.h b/libc/include/stdint.h
index 49879cb..c3e29dd 100644
--- a/libc/include/stdint.h
+++ b/libc/include/stdint.h
@@ -226,12 +226,6 @@
 #  define UINTMAX_C(c)	UINT64_C(c)
 #endif
 
-/* size_t is defined by the GCC-specific <stddef.h> */
-#ifndef _SSIZE_T_DEFINED_
-#define _SSIZE_T_DEFINED_
-typedef long int  ssize_t;
-#endif
-
 #define _BITSIZE 32
 
 /* Keep the kernel from trying to define these types... */
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index 20a9829..cd04d9c 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -39,30 +39,11 @@
 #define	_STDIO_H_
 
 #include <sys/cdefs.h>
-#include <sys/_types.h>
+#include <sys/types.h>
 
 #include <stdarg.h>
 #include <stddef.h>
 
-#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
-#include <sys/types.h>	/* XXX should be removed */
-#endif
-
-#ifndef _SIZE_T_DEFINED_
-#define _SIZE_T_DEFINED_
-typedef unsigned int  size_t;
-#endif
-
-#ifndef _SSIZE_T_DEFINED_
-#define _SSIZE_T_DEFINED_
-typedef long int  ssize_t;
-#endif
-
-#ifndef	_OFF_T_DEFINED_
-#define	_OFF_T_DEFINED_
-typedef	long    off_t;
-#endif
-
 #define __need_NULL
 #include <stddef.h>
 
diff --git a/libc/include/sys/linux-syscalls.h b/libc/include/sys/linux-syscalls.h
index f2249fd..ec48ada 100644
--- a/libc/include/sys/linux-syscalls.h
+++ b/libc/include/sys/linux-syscalls.h
@@ -83,7 +83,6 @@
 #define __NR_msync                        (__NR_SYSCALL_BASE + 144)
 #define __NR_readv                        (__NR_SYSCALL_BASE + 145)
 #define __NR_writev                       (__NR_SYSCALL_BASE + 146)
-#define __NR_getsid                       (__NR_SYSCALL_BASE + 147)
 
 #ifdef __arm__
 #define __NR_exit_group                   (__NR_SYSCALL_BASE + 248)
@@ -98,6 +97,7 @@
 #define __NR_gettid                       (__NR_SYSCALL_BASE + 224)
 #define __NR_readahead                    (__NR_SYSCALL_BASE + 225)
 #define __NR_getgroups32                  (__NR_SYSCALL_BASE + 205)
+#define __NR_getsid                       (__NR_SYSCALL_BASE + 147)
 #define __NR_setgid32                     (__NR_SYSCALL_BASE + 214)
 #define __NR_setreuid32                   (__NR_SYSCALL_BASE + 203)
 #define __NR_setresuid32                  (__NR_SYSCALL_BASE + 208)
@@ -221,6 +221,7 @@
 #define __NR_pipe                         (__NR_SYSCALL_BASE + 42)
 #define __NR_sigsuspend                   (__NR_SYSCALL_BASE + 72)
 #define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
+#define __NR_getsid                       (__NR_SYSCALL_BASE + 147)
 #define __NR_fdatasync                    (__NR_SYSCALL_BASE + 148)
 #define __NR_mlock                        (__NR_SYSCALL_BASE + 150)
 #define __NR_munlock                      (__NR_SYSCALL_BASE + 151)
@@ -352,6 +353,7 @@
 #define __NR_setgroups                    (__NR_SYSCALL_BASE + 81)
 #define __NR_fchown                       (__NR_SYSCALL_BASE + 95)
 #define __NR_cacheflush                   (__NR_SYSCALL_BASE + 147)
+#define __NR_getsid                       (__NR_SYSCALL_BASE + 151)
 #define __NR_fdatasync                    (__NR_SYSCALL_BASE + 152)
 #define __NR_mlock                        (__NR_SYSCALL_BASE + 154)
 #define __NR_munlock                      (__NR_SYSCALL_BASE + 155)
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index 62e0d8b..05b221f 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -112,6 +112,13 @@
 #define  st_mtimensec  st_mtime_nsec
 #define  st_ctimensec  st_ctime_nsec
 
+#ifdef __USE_BSD
+/* Permission macros provided by glibc for compatibility with BSDs. */
+#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
+#define ALLPERMS    (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */
+#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
+#endif
+
 extern int    chmod(const char *, mode_t);
 extern int    fchmod(int, mode_t);
 extern int    mkdir(const char *, mode_t);
diff --git a/libc/include/sys/types.h b/libc/include/sys/types.h
index 77b3223..8cfeeb6 100644
--- a/libc/include/sys/types.h
+++ b/libc/include/sys/types.h
@@ -83,11 +83,6 @@
 typedef  .... pthread_t;
 #endif
 
-#ifndef _SIZE_T_DEFINED_
-#define _SIZE_T_DEFINED_
-typedef unsigned int  size_t;
-#endif
-
 #ifndef _SSIZE_T_DEFINED_
 #define _SSIZE_T_DEFINED_
 typedef long int  ssize_t;
diff --git a/libc/include/wchar.h b/libc/include/wchar.h
index b46985b..ef88e04 100644
--- a/libc/include/wchar.h
+++ b/libc/include/wchar.h
@@ -45,7 +45,7 @@
 
 __BEGIN_DECLS
 
-typedef int                     wint_t;
+typedef __WINT_TYPE__           wint_t;
 typedef struct { int  dummy; }  mbstate_t;
 
 typedef enum {
diff --git a/libc/stdio/fopen.c b/libc/stdio/fopen.c
index a6cddd3..6d2d882 100644
--- a/libc/stdio/fopen.c
+++ b/libc/stdio/fopen.c
@@ -31,6 +31,8 @@
  * SUCH DAMAGE.
  */
 
+#define __USE_BSD
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
diff --git a/libc/stdio/freopen.c b/libc/stdio/freopen.c
index da3a674..f0386e9 100644
--- a/libc/stdio/freopen.c
+++ b/libc/stdio/freopen.c
@@ -31,6 +31,8 @@
  * SUCH DAMAGE.
  */
 
+#define __USE_BSD
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
diff --git a/libc/stdio/local.h b/libc/stdio/local.h
index 6b2111a..664cec1 100644
--- a/libc/stdio/local.h
+++ b/libc/stdio/local.h
@@ -35,10 +35,6 @@
 #include "wcio.h"
 #include "fileext.h"
 
-#ifndef DEFFILEMODE
-#define DEFFILEMODE  (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
-#endif
-
 
 /*
  * Information local to this implementation of stdio,
diff --git a/libc/tools/checksyscalls.py b/libc/tools/checksyscalls.py
index 286e727..b325676 100755
--- a/libc/tools/checksyscalls.py
+++ b/libc/tools/checksyscalls.py
@@ -2,7 +2,7 @@
 #
 # this tool is used to check that the syscall numbers that are in
 # SYSCALLS.TXT correspond to those found in the Linux kernel sources
-# for the arm and i386 architectures
+# for the arm, i386 and mips architectures
 #
 
 import sys, re, string, os, commands
@@ -167,13 +167,12 @@
     for sc in syscalls:
         sc_name = sc["name"]
         sc_id   = sc[idname]
+        if sc_id == -1:
+            sc_id = sc["common"]
         if sc_id >= 0:
             if not arch_dict.has_key(sc_name):
                 print "error: %s syscall %s not defined, should be %d" % (archname, sc_name, sc_id)
                 errors += 1
-            elif not arch_dict.has_key(sc_name):
-                print "error: %s syscall %s is not implemented" % (archname, sc_name)
-                errors += 1
             elif arch_dict[sc_name] != sc_id:
                 print "error: %s syscall %s should be %d instead of %d" % (archname, sc_name, arch_dict[sc_name], sc_id)
                 errors += 1
diff --git a/libc/tools/zoneinfo/generate b/libc/tools/zoneinfo/generate
index ba8ea0d..334ba3c 100755
--- a/libc/tools/zoneinfo/generate
+++ b/libc/tools/zoneinfo/generate
@@ -66,22 +66,24 @@
   """Downloads and repackages the given data from the given FTP server."""
 
   new_version = re.search('(tzdata.+)\\.tar\\.gz', data_filename).group(1)
-  signature_filename = '%s.sign' % data_filename
 
   # Switch to a temporary directory.
   tmp_dir = tempfile.mkdtemp('-tzdata')
   os.chdir(tmp_dir)
   print 'Created temporary directory "%s"...' % tmp_dir
 
-  print 'Downloading data and signature...'
+  print 'Downloading data...'
   Retrieve(ftp, data_filename)
+
+  print 'Downloading signature...'
+  signature_filename = '%s.asc' % data_filename
   Retrieve(ftp, signature_filename)
 
   print 'Verifying signature...'
   # If this fails for you, you probably need to import Paul Eggert's public key:
   # gpg --recv-keys ED97E90E62AA7E34
-  subprocess.check_call(['gpg', '--trusted-key=ED97E90E62AA7E34',
-                         '--verify', signature_filename, data_filename])
+  subprocess.check_call(['gpg', '--trusted-key=ED97E90E62AA7E34', '--verify',
+                         signature_filename, data_filename])
 
   print 'Extracting...'
   os.mkdir('extracted')
diff --git a/libc/zoneinfo/tzdata b/libc/zoneinfo/tzdata
index 367c0f9..019650e 100644
--- a/libc/zoneinfo/tzdata
+++ b/libc/zoneinfo/tzdata
Binary files differ
diff --git a/linker/linker.cpp b/linker/linker.cpp
index fc54f3a..0d0a8a9 100755
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -146,7 +146,7 @@
     {                                                                           \
         const char* msg = "ERROR: " #name " called from the dynamic linker!\n"; \
          __libc_android_log_write(ANDROID_LOG_FATAL, "linker", msg);            \
-        write(2, msg, sizeof(msg));                                             \
+        write(2, msg, strlen(msg));                                             \
         abort();                                                                \
     }
 #define UNUSED __attribute__((unused))
@@ -1916,9 +1916,9 @@
     somain = si;
 
     if (!soinfo_link_image(si)) {
-        char errmsg[] = "CANNOT LINK EXECUTABLE\n";
+        const char* msg = "CANNOT LINK EXECUTABLE\n";
         write(2, __linker_dl_err_buf, strlen(__linker_dl_err_buf));
-        write(2, errmsg, sizeof(errmsg));
+        write(2, msg, strlen(msg));
         exit(EXIT_FAILURE);
     }