Index: trunk/src/emx/ChangeLog.LIBC
===================================================================
--- trunk/src/emx/ChangeLog.LIBC	(revision 2171)
+++ trunk/src/emx/ChangeLog.LIBC	(revision 2172)
@@ -11,4 +11,6 @@
         o Fixed serveral bugs in the C/POSIX locale
         o Implemented the LC_MESSAGES locale.
+        o Fixed mixup in fts.c port.
+        o Replaced the EMX ftw with the BSD one so we implement the SuS specs.
 
 2005-07-01: knut st. osmundsen <bird-gccos2-spam@anduin.net>
Index: trunk/src/emx/include/ftw.h
===================================================================
--- trunk/src/emx/include/ftw.h	(revision 2171)
+++ trunk/src/emx/include/ftw.h	(revision 2172)
@@ -1,28 +1,77 @@
-/* $Id: */
+/*	$OpenBSD: ftw.h,v 1.1 2003/07/21 21:13:18 millert Exp $	*/
+
+/*
+ * Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ *
+ * $FreeBSD: src/include/ftw.h,v 1.1.2.1 2004/08/29 06:10:53 tjr Exp $
+ */
 /** @file
- * EMX
+ * FreeBSD 5.3
+ * @changed bird: Added gnu stuff.
  */
 
-#ifndef _FTW_H
-#define _FTW_H
+#ifndef	_FTW_H
+#define	_FTW_H
 
-#if defined (__cplusplus)
-extern "C" {
+#include <sys/types.h>
+#include <sys/stat.h>
+
+/*
+ * Valid flags for the 3rd argument to the function that is passed as the
+ * second argument to ftw(3) and nftw(3).  Say it three times fast!
+ */
+#define	FTW_F		0	/* File.  */
+#define	FTW_D		1	/* Directory.  */
+#define	FTW_DNR		2	/* Directory without read permission.  */
+#define	FTW_DP		3	/* Directory with subdirectories visited.  */
+#define	FTW_NS		4	/* Unknown type; stat() failed.  */
+#define	FTW_SL		5	/* Symbolic link.  */
+#define	FTW_SLN		6	/* Sym link that names a nonexistent file.  */
+
+/*
+ * Flags for use as the 4th argument to nftw(3).  These may be ORed together.
+ */
+#define	FTW_PHYS	0x01	/* Physical walk, don't follow sym links.  */
+#define	FTW_MOUNT	0x02	/* The walk does not cross a mount point.  */
+#define	FTW_DEPTH	0x04	/* Subdirs visited before the dir itself. */
+#define	FTW_CHDIR	0x08	/* Change to a directory before reading it. */
+
+#if defined(__USE_GNU) && __USE_GNU
+/*
+ * Unfortunately we don't implement the FTW_SKIP_SUBTREE, FTW_SKIP_SIBLINGS
+ * and FTW_ACTIONRETVAL extensions found in GLIBC. FTW_CONTINUE and FTW_STOP
+ * will work even if FTW_ACTIONRETVAL is not supported, so we define them
+ * in case it helps anyone.
+ */
+#define FTW_CONTINUE 0
+#define FTW_STOP 1
 #endif
 
-#include <sys/stat.h>
+struct FTW {
+	int base;
+	int level;
+};
 
-#define FTW_F           0
-#define FTW_D           1
-#define FTW_DNR         2
-#define FTW_NS          3
+__BEGIN_DECLS
+int	ftw(const char *, int (*)(const char *, const struct stat *, int), int);
+int	nftw(const char *, int (*)(const char *, const struct stat *, int,
+	    struct FTW *), int, int);
+__END_DECLS
 
-int ftw (__const__ char *,
-    int (*)(__const__ char *, __const__ struct stat *, int),
-    int);
-
-#if defined (__cplusplus)
-}
-#endif
-
-#endif /* not _FTW_H */
+#endif	/* !_FTW_H */
Index: trunk/src/emx/src/lib/bsd/gen/ftw.c
===================================================================
--- trunk/src/emx/src/lib/bsd/gen/ftw.c	(revision 2171)
+++ trunk/src/emx/src/lib/bsd/gen/ftw.c	(revision 2172)
@@ -27,4 +27,5 @@
 #endif
 
+#include "namespace.h"
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD: src/lib/libc/gen/ftw.c,v 1.4 2004/08/24 13:00:55 tjr Exp $");
@@ -38,5 +39,5 @@
 
 int
-ftw(const char *path, int (*fn)(const char *, const struct stat *, int),
+_STD(ftw)(const char *path, int (*fn)(const char *, const struct stat *, int),
     int nfds)
 {
Index: trunk/src/emx/src/lib/bsd/gen/nftw.c
===================================================================
--- trunk/src/emx/src/lib/bsd/gen/nftw.c	(revision 2171)
+++ trunk/src/emx/src/lib/bsd/gen/nftw.c	(revision 2172)
@@ -27,4 +27,5 @@
 #endif
 
+#include "namespace.h"
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD: src/lib/libc/gen/nftw.c,v 1.1 2004/08/24 13:00:55 tjr Exp $");
@@ -38,5 +39,5 @@
 
 int
-nftw(const char *path, int (*fn)(const char *, const struct stat *, int,
+_STD(nftw)(const char *path, int (*fn)(const char *, const struct stat *, int,
      struct FTW *), int nfds, int ftwflags)
 {
Index: trunk/src/emx/src/lib/libc.def
===================================================================
--- trunk/src/emx/src/lib/libc.def	(revision 2171)
+++ trunk/src/emx/src/lib/libc.def	(revision 2172)
@@ -1890,2 +1890,3 @@
     "__obstack_memory_used" @1890
     "__obstack_newchunk" @1891
+    "__std_nftw" @1892
Index: trunk/src/emx/src/lib/misc/ftw.c
===================================================================
--- trunk/src/emx/src/lib/misc/ftw.c	(revision 2171)
+++ 	(revision )
@@ -1,95 +1,0 @@
-/* ftw.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
-
-#include "libc-alias.h"
-#include <stdlib.h>
-#include <string.h>
-#include <io.h>
-#include <ftw.h>
-#include <errno.h>
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <emx/io.h>
-
-static int ftw_recurse (int (*fn)(const char *name,
-                                  const struct stat *stat_ptr,
-                                  int flag),
-                        char *name_buf, int index)
-{
-  int rc, flag, len;
-  struct stat st;
-  DIR *dir;
-  struct dirent *ent;
-
-  dir = opendir (name_buf);
-  if (dir == NULL)
-    return -1;
-  if (index < 1 || !_trslash (name_buf, index, 0))
-    name_buf[index++] = '/';
-  rc = 0;
-  for (;;)
-    {
-      ent = readdir (dir);     /* emx version never fails */
-      if (ent == NULL)
-        break;
-      len = strlen (ent->d_name);
-      if (index + len >= MAXPATHLEN)
-        {
-          errno = ENAMETOOLONG;
-          rc = -1;
-          break;
-        }
-      strcpy (name_buf + index, ent->d_name);
-      if (stat (name_buf, &st) != 0)
-        flag = FTW_NS;
-      else if ((st.st_mode & S_IFMT) == S_IFDIR)
-        flag = FTW_D;
-      else
-        flag = FTW_F;
-      if (flag != FTW_D || (strcmp (ent->d_name, ".") != 0 &&
-                            strcmp (ent->d_name, "..") != 0))
-        {
-          rc = fn (name_buf, &st, flag);
-          if (rc != 0)
-            break;
-          if (flag == FTW_D)
-            {
-              rc = ftw_recurse (fn, name_buf, index + len);
-              if (rc != 0)
-                break;
-            }
-        }
-    }
-  closedir (dir);
-  return rc;
-}
-
-
-int _STD(ftw) (const char *path,
-  int (*fn)(const char *name, const struct stat *stat_ptr, int flag),
-  int depth)
-{
-  struct stat st;
-  char name_buf[MAXPATHLEN+1];
-  int rc, len;
-
-  len = strlen (path);
-  if (len >= MAXPATHLEN)
-    {
-      errno = ENAMETOOLONG;
-      return -1;
-    }
-  if (stat (path, &st) != 0)
-    return -1;
-  if ((st.st_mode & S_IFMT) != S_IFDIR)
-    {
-      errno = ENOTDIR;
-      return -1;
-    }
-  strcpy (name_buf, path);
-  rc = fn (name_buf, &st, FTW_D);
-  if (rc != 0)
-    return rc;
-  return ftw_recurse (fn, name_buf, len);
-}
