Work around <wchar.h> bug on OSF/1 5.1.
diff --git a/ChangeLog b/ChangeLog
index ba29562..c5f27e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-06-04  Bruno Haible  <bruno@clisp.org>
+
+	Work around <wchar.h> bug on OSF/1 5.1.
+	* lib/loop_wchar.h: Before including <wchar.h>, include <stdio.h> and
+	some other includes.
+
 2011-03-27  KO Myung-Hun  <komh@chollian.net>
 
 	Fix installation on OS/2.
diff --git a/lib/loop_wchar.h b/lib/loop_wchar.h
index e8dc68c..6dc011b 100644
--- a/lib/loop_wchar.h
+++ b/lib/loop_wchar.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2000-2002, 2005-2006, 2008-2009 Free Software Foundation, Inc.
+ * Copyright (C) 2000-2002, 2005-2006, 2008-2009, 2011 Free Software Foundation, Inc.
  * This file is part of the GNU LIBICONV Library.
  *
  * The GNU LIBICONV Library is free software; you can redistribute it
@@ -25,6 +25,15 @@
  */
 
 #if HAVE_WCRTOMB || HAVE_MBRTOWC
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+   <wchar.h>.
+   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+   included before <wchar.h>.
+   In some builds of uClibc, <wchar.h> is nonexistent and wchar_t is defined
+   by <stddef.h>.  */
+# include <stddef.h>
+# include <stdio.h>
+# include <time.h>
 # include <wchar.h>
 # define BUF_SIZE 64  /* assume MB_LEN_MAX <= 64 */
   /* Some systems, like BeOS, have multibyte encodings but lack mbstate_t.  */