Index: build/ChangeLog
===================================================================
RCS file: /cvs/gnome/build/ChangeLog,v
retrieving revision 1.67
diff -p -u -2 -r1.67 ChangeLog
--- build/ChangeLog	1 Aug 2004 05:54:52 -0000	1.67
+++ build/ChangeLog	13 Aug 2004 04:07:34 -0000
@@ -1,2 +1,11 @@
+2004-08-11  Tor Lillqvist  <tml@iki.fi>
+
+	* win32/dirent/dirent.[ch]: Update from mingw-runtime-3.3.
+	Implements both normal and wide-char versions.
+
+	* win32/dirent/wdirent.c: New file.
+
+	* win32/dirent/Makefile.am (EXTRA_DIST): Add wdirent.c.
+
 2004-05-01  Hans Breuer  <hans@breuer.org>
 
Index: build/win32/dirent/Makefile.am
===================================================================
RCS file: /cvs/gnome/build/win32/dirent/Makefile.am,v
retrieving revision 1.2
diff -p -u -2 -r1.2 Makefile.am
--- build/win32/dirent/Makefile.am	30 Oct 2001 06:48:37 -0000	1.2
+++ build/win32/dirent/Makefile.am	13 Aug 2004 04:07:34 -0000
@@ -3,4 +3,5 @@ EXTRA_DIST = \
 	dirent.c \
 	dirent.h \
+	wdirent.c \
 	makefile.msc \
 	dirent-zip
Index: build/win32/dirent/README
===================================================================
RCS file: /cvs/gnome/build/win32/dirent/README,v
retrieving revision 1.1
diff -p -u -2 -r1.1 README
--- build/win32/dirent/README	29 Sep 2001 22:09:24 -0000	1.1
+++ build/win32/dirent/README	13 Aug 2004 04:07:34 -0000
@@ -1,2 +1,2 @@
-This is the dirent part from libmingw32, separated for MSVC user's
+This is dirent from mingw-runtime-3.3, separated for MSVC user's
 benefit.
Index: build/win32/dirent/dirent.c
===================================================================
RCS file: /cvs/gnome/build/win32/dirent/dirent.c,v
retrieving revision 1.2
diff -p -u -2 -r1.2 dirent.c
--- build/win32/dirent/dirent.c	6 Mar 2004 03:33:25 -0000	1.2
+++ build/win32/dirent/dirent.c	13 Aug 2004 04:07:34 -0000
@@ -1,4 +1,7 @@
 /*
  * dirent.c
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is a part of the mingw-runtime package.
+ * No warranty is given; refer to the file DISCLAIMER within the package.
  *
  * Derived from DIRLIB.C by Matt J. Weinstein 
@@ -10,11 +13,6 @@
  * Peters <colin@fu.is.saga-u.ac.jp>
  *	
- * $Revision: 1.2 $
- * $Author: federico $
- * $Date: 2004/03/06 03:33:25 $
- *
  */
 
-#include <config.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -22,5 +20,4 @@
 #include <io.h>
 #include <direct.h>
-
 #include <dirent.h>
 
@@ -28,6 +25,29 @@
 #include <windows.h> /* for GetFileAttributes */
 
-#define SUFFIX	"*"
-#define	SLASH	"\\"
+#include <tchar.h>
+
+#ifdef _UNICODE
+#define _tdirent	_wdirent
+#define _TDIR 		_WDIR
+#define _topendir	_wopendir
+#define _tclosedir	_wclosedir
+#define _treaddir	_wreaddir
+#define _trewinddir	_wrewinddir
+#define _ttelldir	_wtelldir
+#define _tseekdir	_wseekdir
+#else
+#define _tdirent	dirent
+#define _TDIR 		DIR
+#define _topendir	opendir
+#define _tclosedir	closedir
+#define _treaddir	readdir
+#define _trewinddir	rewinddir
+#define _ttelldir	telldir
+#define _tseekdir	seekdir
+#endif
+
+#define SUFFIX	_T("*")
+#define	SLASH	_T("\\")
+
 
 /*
@@ -37,9 +57,10 @@
  * searching a directory.
  */
-DIR * 
-opendir (const char *szPath)
+_TDIR * 
+_topendir (const _TCHAR *szPath)
 {
-  DIR *nd;
+  _TDIR *nd;
   unsigned int rc;
+  _TCHAR szFullPath[MAX_PATH];
 	
   errno = 0;
@@ -48,20 +69,20 @@ opendir (const char *szPath)
     {
       errno = EFAULT;
-      return (DIR *) 0;
+      return (_TDIR *) 0;
     }
 
-  if (szPath[0] == '\0')
+  if (szPath[0] == _T('\0'))
     {
       errno = ENOTDIR;
-      return (DIR *) 0;
+      return (_TDIR *) 0;
     }
 
   /* Attempt to determine if the given path really is a directory. */
-  rc = GetFileAttributes(szPath);
-  if (rc == -1)
+  rc = GetFileAttributes (szPath);
+  if (rc == (unsigned int)-1)
     {
       /* call GetLastError for more error info */
       errno = ENOENT;
-      return (DIR *) 0;
+      return (_TDIR *) 0;
     }
   if (!(rc & FILE_ATTRIBUTE_DIRECTORY))
@@ -69,11 +90,14 @@ opendir (const char *szPath)
       /* Error, entry exists but not a directory. */
       errno = ENOTDIR;
-      return (DIR *) 0;
+      return (_TDIR *) 0;
     }
 
+  /* Make an absolute pathname.  */
+  _tfullpath (szFullPath, szPath, MAX_PATH);
+
   /* Allocate enough space to store DIR structure and the complete
    * directory path given. */
-  nd = (DIR *) malloc (sizeof (DIR) + strlen (szPath) + strlen (SLASH) +
-		       strlen (SUFFIX));
+  nd = (_TDIR *) malloc (sizeof (_TDIR) + (_tcslen(szFullPath) + _tcslen (SLASH) +
+			 _tcslen(SUFFIX) + 1) * sizeof(_TCHAR));
 
   if (!nd)
@@ -81,20 +105,20 @@ opendir (const char *szPath)
       /* Error, out of memory. */
       errno = ENOMEM;
-      return (DIR *) 0;
+      return (_TDIR *) 0;
     }
 
   /* Create the search expression. */
-  strcpy (nd->dd_name, szPath);
+  _tcscpy (nd->dd_name, szFullPath);
 
   /* Add on a slash if the path does not end with one. */
-  if (nd->dd_name[0] != '\0' &&
-      nd->dd_name[strlen (nd->dd_name) - 1] != '/' &&
-      nd->dd_name[strlen (nd->dd_name) - 1] != '\\')
+  if (nd->dd_name[0] != _T('\0') &&
+      nd->dd_name[_tcslen (nd->dd_name) - 1] != _T('/') &&
+      nd->dd_name[_tcslen (nd->dd_name) - 1] != _T('\\'))
     {
-      strcat (nd->dd_name, SLASH);
+      _tcscat (nd->dd_name, SLASH);
     }
 
   /* Add on the search pattern */
-  strcat (nd->dd_name, SUFFIX);
+  _tcscat (nd->dd_name, SUFFIX);
 
   /* Initialize handle to -1 so that a premature closedir doesn't try
@@ -111,5 +135,5 @@ opendir (const char *szPath)
   nd->dd_dir.d_reclen = 0;
   nd->dd_dir.d_namlen = 0;
-  nd->dd_dir.d_name = nd->dd_dta.name;
+  memset (nd->dd_dir.d_name, 0, FILENAME_MAX);
 
   return nd;
@@ -123,6 +147,6 @@ opendir (const char *szPath)
  * next entry in the directory.
  */
-struct dirent *
-readdir (DIR * dirp)
+struct _tdirent *
+_treaddir (_TDIR * dirp)
 {
   errno = 0;
@@ -132,12 +156,5 @@ readdir (DIR * dirp)
     {
       errno = EFAULT;
-      return (struct dirent *) 0;
-    }
-
-  if (dirp->dd_dir.d_name != dirp->dd_dta.name)
-    {
-      /* The structure does not seem to be set up correctly. */
-      errno = EINVAL;
-      return (struct dirent *) 0;
+      return (struct _tdirent *) 0;
     }
 
@@ -146,5 +163,5 @@ readdir (DIR * dirp)
       /* We have already returned all files in the directory
        * (or the structure has an invalid dd_stat). */
-      return (struct dirent *) 0;
+      return (struct _tdirent *) 0;
     }
   else if (dirp->dd_stat == 0)
@@ -152,5 +169,5 @@ readdir (DIR * dirp)
       /* We haven't started the search yet. */
       /* Start the search */
-      dirp->dd_handle = _findfirst (dirp->dd_name, &(dirp->dd_dta));
+      dirp->dd_handle = _tfindfirst (dirp->dd_name, &(dirp->dd_dta));
 
   	  if (dirp->dd_handle == -1)
@@ -168,7 +185,12 @@ readdir (DIR * dirp)
     {
       /* Get the next search entry. */
-      if (_findnext (dirp->dd_handle, &(dirp->dd_dta)))
+      if (_tfindnext (dirp->dd_handle, &(dirp->dd_dta)))
 	{
-	  /* We are off the end or otherwise error. */
+	  /* We are off the end or otherwise error.	
+	     _findnext sets errno to ENOENT if no more file
+	     Undo this. */ 
+	  DWORD winerr = GetLastError();
+	  if (winerr == ERROR_NO_MORE_FILES)
+	    errno = 0;	
 	  _findclose (dirp->dd_handle);
 	  dirp->dd_handle = -1;
@@ -188,9 +210,10 @@ readdir (DIR * dirp)
        * already appropriately filled in except the length of the
        * file name. */
-      dirp->dd_dir.d_namlen = strlen (dirp->dd_dir.d_name);
+      dirp->dd_dir.d_namlen = _tcslen (dirp->dd_dta.name);
+      _tcscpy (dirp->dd_dir.d_name, dirp->dd_dta.name);
       return &dirp->dd_dir;
     }
 
-  return (struct dirent *) 0;
+  return (struct _tdirent *) 0;
 }
 
@@ -202,5 +225,5 @@ readdir (DIR * dirp)
  */
 int
-closedir (DIR * dirp)
+_tclosedir (_TDIR * dirp)
 {
   int rc;
@@ -233,5 +256,5 @@ closedir (DIR * dirp)
  */
 void
-rewinddir (DIR * dirp)
+_trewinddir (_TDIR * dirp)
 {
   errno = 0;
@@ -259,5 +282,5 @@ rewinddir (DIR * dirp)
  */
 long
-telldir (DIR * dirp)
+_ttelldir (_TDIR * dirp)
 {
   errno = 0;
@@ -281,5 +304,5 @@ telldir (DIR * dirp)
  */
 void
-seekdir (DIR * dirp, long lPos)
+_tseekdir (_TDIR * dirp, long lPos)
 {
   errno = 0;
@@ -310,7 +333,7 @@ seekdir (DIR * dirp, long lPos)
     {
       /* Rewind and read forward to the appropriate index. */
-      rewinddir (dirp);
+      _trewinddir (dirp);
 
-      while ((dirp->dd_stat < lPos) && readdir (dirp))
+      while ((dirp->dd_stat < lPos) && _treaddir (dirp))
 	;
     }
Index: build/win32/dirent/dirent.h
===================================================================
RCS file: /cvs/gnome/build/win32/dirent/dirent.h,v
retrieving revision 1.1
diff -p -u -2 -r1.1 dirent.h
--- build/win32/dirent/dirent.h	29 Sep 2001 22:09:24 -0000	1.1
+++ build/win32/dirent/dirent.h	13 Aug 2004 04:07:35 -0000
@@ -1,30 +1,13 @@
 /*
  * DIRENT.H (formerly DIRLIB.H)
- *
- * by M. J. Weinstein   Released to public domain 1-Jan-89
- *
- * Because I have heard that this feature (opendir, readdir, closedir)
- * it so useful for programmers coming from UNIX or attempting to port
- * UNIX code, and because it is reasonably light weight, I have included
- * it in the Mingw32 package. I have also added an implementation of
- * rewinddir, seekdir and telldir.
- *   - Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
- *
- *  This code is distributed in the hope that is will be useful but
- *  WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
- *  DISCLAMED. This includeds but is not limited to warranties of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * $Revision: 1.1 $
- * $Author: tml $
- * $Date: 2001/09/29 22:09:24 $
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is a part of the mingw-runtime package.
+ * No warranty is given; refer to the file DISCLAIMER within the package.
  *
  */
-
-#ifndef	__STRICT_ANSI__
-
 #ifndef _DIRENT_H_
 #define _DIRENT_H_
 
+#include <stdio.h>
 #include <io.h>
 
@@ -40,7 +23,5 @@ struct dirent
 	unsigned short	d_reclen;	/* Always zero. */
 	unsigned short	d_namlen;	/* Length of name in d_name. */
-	char*		d_name;		/* File name. */
-	/* NOTE: The name in the dirent structure points to the name in the
-	 *       finddata_t structure in the DIR. */
+	char		d_name[FILENAME_MAX]; /* File name. */
 };
 
@@ -48,4 +29,5 @@ struct dirent
  * This is an internal data structure. Good programmers will not use it
  * except as an argument to one of the functions below.
+ * dd_stat field is now int (was short in older versions).
  */
 typedef struct
@@ -68,5 +50,5 @@ typedef struct
 	 *   positive = 0 based index of next entry
 	 */
-	short			dd_stat;
+	int			dd_stat;
 
 	/* given path for dir with search pattern (struct is extended) */
@@ -74,11 +56,60 @@ typedef struct
 } DIR;
 
+DIR* __cdecl opendir (const char*);
+struct dirent* __cdecl readdir (DIR*);
+int __cdecl closedir (DIR*);
+void __cdecl rewinddir (DIR*);
+long __cdecl telldir (DIR*);
+void __cdecl seekdir (DIR*, long);
+
+
+/* wide char versions */
+
+struct _wdirent
+{
+	long		d_ino;		/* Always zero. */
+	unsigned short	d_reclen;	/* Always zero. */
+	unsigned short	d_namlen;	/* Length of name in d_name. */
+	wchar_t		d_name[FILENAME_MAX]; /* File name. */
+};
+
+/*
+ * This is an internal data structure. Good programmers will not use it
+ * except as an argument to one of the functions below.
+ */
+typedef struct
+{
+	/* disk transfer area for this dir */
+	struct _wfinddata_t	dd_dta;
+
+	/* dirent struct to return from dir (NOTE: this makes this thread
+	 * safe as long as only one thread uses a particular DIR struct at
+	 * a time) */
+	struct _wdirent		dd_dir;
+
+	/* _findnext handle */
+	long			dd_handle;
+
+	/*
+         * Status of search:
+	 *   0 = not started yet (next entry to read is first entry)
+	 *  -1 = off the end
+	 *   positive = 0 based index of next entry
+	 */
+	int			dd_stat;
+
+	/* given path for dir with search pattern (struct is extended) */
+	wchar_t			dd_name[1];
+} _WDIR;
+
+
+
+_WDIR* __cdecl _wopendir (const wchar_t*);
+struct _wdirent*  __cdecl _wreaddir (_WDIR*);
+int __cdecl _wclosedir (_WDIR*);
+void __cdecl _wrewinddir (_WDIR*);
+long __cdecl _wtelldir (_WDIR*);
+void __cdecl _wseekdir (_WDIR*, long);
 
-DIR*		opendir (const char*);
-struct dirent*	readdir (DIR*);
-int		closedir (DIR*);
-void		rewinddir (DIR*);
-long		telldir (DIR*);
-void		seekdir (DIR*, long);
 
 #ifdef	__cplusplus
@@ -89,5 +120,2 @@ void		seekdir (DIR*, long);
 
 #endif	/* Not _DIRENT_H_ */
-
-#endif	/* Not __STRICT_ANSI__ */
-
Index: build/win32/dirent/makefile.msc
===================================================================
RCS file: /cvs/gnome/build/win32/dirent/makefile.msc,v
retrieving revision 1.2
diff -p -u -2 -r1.2 makefile.msc
--- build/win32/dirent/makefile.msc	15 Nov 2003 03:14:35 -0000	1.2
+++ build/win32/dirent/makefile.msc	13 Aug 2004 04:07:35 -0000
@@ -3,5 +3,5 @@ TOP = ..\..\..\..
 !INCLUDE $(TOP)\glib\build\win32\make.msc
 
-dirent_OBJECTS = dirent.obj
+dirent_OBJECTS = dirent.obj wdirent.obj
 
 INCLUDES = -I.
Index: build/win32/dirent/wdirent.c
===================================================================
RCS file: build/win32/dirent/wdirent.c
diff -N build/win32/dirent/wdirent.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ build/win32/dirent/wdirent.c	13 Aug 2004 04:07:35 -0000
@@ -0,0 +1,3 @@
+#define _UNICODE 1
+#define UNICODE 1
+#include "dirent.c"
