diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ed3456a69cd54acd914d770edd9e8681d80f1c04..0adec4f28cb56c9aba6d2af2b9e4b4eae5ae3634 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,21 @@
+2003-02-19  Rainer Orth  <ro@TechFak.Uni-Bielefeld.DE>
+
+	* config/mips/iris6.h (TARGET_OS_CPP_BUILTINS): Define __c99 for
+	ISO C99 and C++.
+
+	* fixinc/inclhack.def (irix___restrict): Don't change __restrict
+	for C++ on IRIX 6.5.1[89].
+	* fixinc/tests/base/internal/sgimacros.h: New file.
+
+	* fixinc/inclhack.def (irix_wcsftime): Use XPG5 variant for C99.
+	* fixinc/tests/base/internal/wchar_core.h: New file.
+	
+	* fixinc/inclhack.def (irix_socklen_t): Fix broken IRIX 6.5.1[78]
+	socklen_t definition.
+	* fixinc/fixincl.x: Regenerate.
+	* fixinc/tests/base/sys/socket.h: New file.
+	Fixes PR libgcj/9652.
+
 Wed Feb 19 17:22:51 CET 2003  Jan Hubicka  <jh@suse.cz>
 
 	* i386.md (movsfcc_1, movdfcc_1): Fix constrains.
diff --git a/gcc/config/mips/iris6.h b/gcc/config/mips/iris6.h
index 6e37de58f9ac7e40e8dea61c8833917f0c9ad02e..987a58c6b9d9c744bdb74d1fde432e4ea940cfc3 100644
--- a/gcc/config/mips/iris6.h
+++ b/gcc/config/mips/iris6.h
@@ -125,6 +125,13 @@ Boston, MA 02111-1307, USA.  */
      if (!ISA_MIPS1 && !ISA_MIPS2)			\
 	builtin_define ("_COMPILER_VERSION=601");	\
 							\
+     /* IRIX 6.5.18 and above provide many ISO C99	\
+	features protected by the __c99 macro.		\
+	libstdc++ v3 needs them as well.  */		\
+     if ((c_language == clk_c && flag_isoc99)		\
+	 || c_language == clk_cplusplus)		\
+	builtin_define ("__c99");			\
+							\
      if (c_language == clk_cplusplus)			\
       {							\
 	builtin_define ("__EXTENSIONS__");		\
diff --git a/gcc/fixinc/fixincl.x b/gcc/fixinc/fixincl.x
index ba29403d9031a573efc2580050f01ecd25d5a76c..017b748fc73b7d915696fbc626f33ff69acaef0f 100644
--- a/gcc/fixinc/fixincl.x
+++ b/gcc/fixinc/fixincl.x
@@ -5,7 +5,7 @@
  * files which are fixed to work correctly with ANSI C and placed in a
  * directory that GNU C will search.
  *
- * This file contains 143 fixup descriptions.
+ * This file contains 146 fixup descriptions.
  *
  * See README for more information.
  *
@@ -2370,6 +2370,88 @@ static const char* apzIrix_Limits_ConstPatch[] = {
     "extern __const ",
     (char*)NULL };
 
+/* * * * * * * * * * * * * * * * * * * * * * * * * *
+ *
+ *  Description of Irix___Restrict fix
+ */
+tSCC zIrix___RestrictName[] =
+     "irix___restrict";
+
+/*
+ *  File name selection pattern
+ */
+tSCC zIrix___RestrictList[] =
+  "|internal/sgimacros.h|";
+/*
+ *  Machine/OS name selection pattern
+ */
+tSCC* apzIrix___RestrictMachs[] = {
+        "mips-sgi-irix6.5",
+        (const char*)NULL };
+
+/*
+ *  content selection pattern - do fix if pattern found
+ */
+tSCC zIrix___RestrictSelect0[] =
+       "(#ifdef __c99\n\
+)(#[ \t]*define __restrict restrict)";
+
+#define    IRIX___RESTRICT_TEST_CT  1
+static tTestDesc aIrix___RestrictTests[] = {
+  { TT_EGREP,    zIrix___RestrictSelect0, (regex_t*)NULL }, };
+
+/*
+ *  Fix Command Arguments for Irix___Restrict
+ */
+static const char* apzIrix___RestrictPatch[] = {
+    "format",
+    "%1#  ifndef __cplusplus\n\
+%2\n\
+#  endif",
+    (char*)NULL };
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * *
+ *
+ *  Description of Irix_Socklen_T fix
+ */
+tSCC zIrix_Socklen_TName[] =
+     "irix_socklen_t";
+
+/*
+ *  File name selection pattern
+ */
+tSCC zIrix_Socklen_TList[] =
+  "|sys/socket.h|";
+/*
+ *  Machine/OS name selection pattern
+ */
+tSCC* apzIrix_Socklen_TMachs[] = {
+        "mips-sgi-irix6.5",
+        (const char*)NULL };
+
+/*
+ *  content selection pattern - do fix if pattern found
+ */
+tSCC zIrix_Socklen_TSelect0[] =
+       "(#define _SOCKLEN_T\n\
+)(typedef u_int32_t socklen_t;)";
+
+#define    IRIX_SOCKLEN_T_TEST_CT  1
+static tTestDesc aIrix_Socklen_TTests[] = {
+  { TT_EGREP,    zIrix_Socklen_TSelect0, (regex_t*)NULL }, };
+
+/*
+ *  Fix Command Arguments for Irix_Socklen_T
+ */
+static const char* apzIrix_Socklen_TPatch[] = {
+    "format",
+    "%1#if _NO_XOPEN4 && _NO_XOPEN5\n\
+typedef int socklen_t;\n\
+#else\n\
+%2\n\
+#endif /* _NO_XOPEN4 && _NO_XOPEN5 */",
+    (char*)NULL };
+
 /* * * * * * * * * * * * * * * * * * * * * * * * * *
  *
  *  Description of Irix_Stdio_Va_List fix
@@ -2405,6 +2487,45 @@ static const char* apzIrix_Stdio_Va_ListPatch[] = {
     "%1, __gnuc_va_list",
     (char*)NULL };
 
+/* * * * * * * * * * * * * * * * * * * * * * * * * *
+ *
+ *  Description of Irix_Wcsftime fix
+ */
+tSCC zIrix_WcsftimeName[] =
+     "irix_wcsftime";
+
+/*
+ *  File name selection pattern
+ */
+tSCC zIrix_WcsftimeList[] =
+  "|internal/wchar_core.h|";
+/*
+ *  Machine/OS name selection pattern
+ */
+tSCC* apzIrix_WcsftimeMachs[] = {
+        "mips-sgi-irix6.5",
+        (const char*)NULL };
+
+/*
+ *  content selection pattern - do fix if pattern found
+ */
+tSCC zIrix_WcsftimeSelect0[] =
+       "#if _NO_XOPEN5\n\
+(extern size_t[ \t]+wcsftime.*const char *.*)";
+
+#define    IRIX_WCSFTIME_TEST_CT  1
+static tTestDesc aIrix_WcsftimeTests[] = {
+  { TT_EGREP,    zIrix_WcsftimeSelect0, (regex_t*)NULL }, };
+
+/*
+ *  Fix Command Arguments for Irix_Wcsftime
+ */
+static const char* apzIrix_WcsftimePatch[] = {
+    "format",
+    "#if _NO_XOPEN5 && !defined(__c99)\n\
+%1",
+    (char*)NULL };
+
 /* * * * * * * * * * * * * * * * * * * * * * * * * *
  *
  *  Description of Isc_Fmod fix
@@ -5645,9 +5766,9 @@ static const char* apzX11_SprintfPatch[] = {
  *
  *  List of all fixes
  */
-#define REGEX_COUNT          155
+#define REGEX_COUNT          158
 #define MACH_LIST_SIZE_LIMIT 261
-#define FIX_COUNT            143
+#define FIX_COUNT            146
 
 /*
  *  Enumerate the fixes
@@ -5710,7 +5831,10 @@ typedef enum {
     IP_MISSING_SEMI_FIXIDX,
     IRIX_ASM_APOSTROPHE_FIXIDX,
     IRIX_LIMITS_CONST_FIXIDX,
+    IRIX___RESTRICT_FIXIDX,
+    IRIX_SOCKLEN_T_FIXIDX,
     IRIX_STDIO_VA_LIST_FIXIDX,
+    IRIX_WCSFTIME_FIXIDX,
     ISC_FMOD_FIXIDX,
     ISC_OMITS_WITH_STDC_FIXIDX,
     KANDR_CONCAT_FIXIDX,
@@ -6084,11 +6208,26 @@ tFixDesc fixDescList[ FIX_COUNT ] = {
      IRIX_LIMITS_CONST_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
      aIrix_Limits_ConstTests,   apzIrix_Limits_ConstPatch, 0 },
 
+  {  zIrix___RestrictName,    zIrix___RestrictList,
+     apzIrix___RestrictMachs,
+     IRIX___RESTRICT_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
+     aIrix___RestrictTests,   apzIrix___RestrictPatch, 0 },
+
+  {  zIrix_Socklen_TName,    zIrix_Socklen_TList,
+     apzIrix_Socklen_TMachs,
+     IRIX_SOCKLEN_T_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
+     aIrix_Socklen_TTests,   apzIrix_Socklen_TPatch, 0 },
+
   {  zIrix_Stdio_Va_ListName,    zIrix_Stdio_Va_ListList,
      apzIrix_Stdio_Va_ListMachs,
      IRIX_STDIO_VA_LIST_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
      aIrix_Stdio_Va_ListTests,   apzIrix_Stdio_Va_ListPatch, 0 },
 
+  {  zIrix_WcsftimeName,    zIrix_WcsftimeList,
+     apzIrix_WcsftimeMachs,
+     IRIX_WCSFTIME_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
+     aIrix_WcsftimeTests,   apzIrix_WcsftimePatch, 0 },
+
   {  zIsc_FmodName,    zIsc_FmodList,
      apzIsc_FmodMachs,
      ISC_FMOD_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
diff --git a/gcc/fixinc/inclhack.def b/gcc/fixinc/inclhack.def
index 213374a04f808d241d8fd538f1eb85ff9b73de43..5ff0e9a42fb9d657ed18315943c0eb07c64d2026 100644
--- a/gcc/fixinc/inclhack.def
+++ b/gcc/fixinc/inclhack.def
@@ -1356,6 +1356,48 @@ fix = {
 };
 
 
+/*
+ *  IRIX 6.5.1[89] <internal/sgimacros.h> unconditionally defines
+ *  __restrict as restrict iff __c99.  This is wrong for C++, which
+ *  needs many C99 features, but only supports __restrict.
+ */
+fix = {
+    hackname  = irix___restrict;
+    files     = internal/sgimacros.h;
+    select    = "(#ifdef __c99\n)(#[ \t]*define __restrict restrict)";
+
+    mach      = "mips-sgi-irix6.5";
+    c_fix     = format;
+    c_fix_arg = "%1"
+		"#  ifndef __cplusplus\n%2\n#  endif";
+
+    test_text = "#ifdef __c99\n#  define __restrict restrict";
+};
+
+/*
+ *  IRIX 6.5.1[78] <sys/socket.h> has a broken definition of socklen_t.
+ *  Various socket function prototypes use different types instead,
+ *  depending on the API in use (BSD, XPG4/5), but the socklen_t
+ *  definition doesn't reflect this (SGI Bug Id 864477, fixed in
+ *  IRIX 6.5.19).
+ */
+fix = {
+    hackname  = irix_socklen_t;
+    files     = sys/socket.h;
+    select    = "(#define _SOCKLEN_T\n)(typedef u_int32_t socklen_t;)";
+
+    mach      = "mips-sgi-irix6.5";
+    c_fix     = format;
+    c_fix_arg = "%1"
+    		"#if _NO_XOPEN4 && _NO_XOPEN5\n"
+    		"typedef int socklen_t;\n"
+		"#else\n"
+    		"%2\n"
+    		"#endif /* _NO_XOPEN4 && _NO_XOPEN5 */";
+
+    test_text = "#define _SOCKLEN_T\ntypedef u_int32_t socklen_t;";
+};
+
 /*
  *  IRIX 5.x's stdio.h declares some functions that take a va_list as
  *  taking char *.  However, GCC uses void * for va_list, so
@@ -1372,6 +1414,23 @@ fix = {
 };
 
 
+/*
+ *  IRIX 6.5.19 <internal/wchar_core.h> provides the XPG4 variant of
+ *  wcsftime by default.  ISO C99 requires the XPG5 variant instead.
+ */
+fix = {
+    hackname  = irix_wcsftime;
+    files     = internal/wchar_core.h;
+    select    = "#if _NO_XOPEN5\n(extern size_t[ \t]+wcsftime.*const char \*.*)";
+
+    mach      = "mips-sgi-irix6.5";
+    c_fix     = format;
+    c_fix_arg = "#if _NO_XOPEN5 && !defined(__c99)\n%1";
+
+    test_text = "#if _NO_XOPEN5\n"
+		"extern size_t          wcsftime(wchar_t *, __SGI_LIBC_NAMESPACE_QUALIFIER size_t, const char *, const struct tm *);";
+};
+
 /*
  * Fixing ISC fmod declaration
  */
diff --git a/gcc/fixinc/tests/base/internal/sgimacros.h b/gcc/fixinc/tests/base/internal/sgimacros.h
new file mode 100644
index 0000000000000000000000000000000000000000..fc72569749836f27f3f521495b41cb6ea2ba5aa6
--- /dev/null
+++ b/gcc/fixinc/tests/base/internal/sgimacros.h
@@ -0,0 +1,17 @@
+/*  DO NOT EDIT THIS FILE.
+
+    It has been auto-edited by fixincludes from:
+
+	"fixinc/tests/inc/internals/sgimacros.h"
+
+    This had to be done to correct non-standard usages in the
+    original, manufacturer supplied header file.  */
+
+
+
+#if defined( IRIX___RESTRICT_CHECK )
+#ifdef __c99
+#  ifndef __cplusplus
+#  define __restrict restrict
+#  endif
+#endif  /* IRIX___RESTRICT_CHECK */
diff --git a/gcc/fixinc/tests/base/internal/wchar_core.h b/gcc/fixinc/tests/base/internal/wchar_core.h
new file mode 100644
index 0000000000000000000000000000000000000000..57951c64603211873371e181fd40f2a52d492c97
--- /dev/null
+++ b/gcc/fixinc/tests/base/internal/wchar_core.h
@@ -0,0 +1,15 @@
+/*  DO NOT EDIT THIS FILE.
+
+    It has been auto-edited by fixincludes from:
+
+	"fixinc/tests/inc/internals/wchar_core.h"
+
+    This had to be done to correct non-standard usages in the
+    original, manufacturer supplied header file.  */
+
+
+
+#if defined( IRIX_WCSFTIME_CHECK )
+#if _NO_XOPEN5 && !defined(__c99)
+extern size_t          wcsftime(wchar_t *, __SGI_LIBC_NAMESPACE_QUALIFIER size_t, const char *, const struct tm *);
+#endif  /* IRIX_WCSFTIME_CHECK */
diff --git a/gcc/fixinc/tests/base/sys/socket.h b/gcc/fixinc/tests/base/sys/socket.h
new file mode 100644
index 0000000000000000000000000000000000000000..56099a92002d87f3c1f7c613564b08377c5646e1
--- /dev/null
+++ b/gcc/fixinc/tests/base/sys/socket.h
@@ -0,0 +1,19 @@
+/*  DO NOT EDIT THIS FILE.
+
+    It has been auto-edited by fixincludes from:
+
+	"fixinc/tests/inc/sys/socket.h"
+
+    This had to be done to correct non-standard usages in the
+    original, manufacturer supplied header file.  */
+
+
+
+#if defined( IRIX_SOCKLEN_T_CHECK )
+#define _SOCKLEN_T
+#if _NO_XOPEN4 && _NO_XOPEN5
+typedef int socklen_t;
+#else
+typedef u_int32_t socklen_t;
+#endif /* _NO_XOPEN4 && _NO_XOPEN5 */
+#endif  /* IRIX_SOCKLEN_T_CHECK */