bug-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AC_HEADER_DIRENT


From: Derek R. Price
Subject: Re: AC_HEADER_DIRENT
Date: Fri, 07 Jul 2006 21:47:08 -0400
User-agent: Thunderbird 1.5.0.4 (Windows/20060516)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jim Hyslop wrote:
> Can you live with the current <ndir.h> solution until I (or someone)
> implements a dirent substitute for the Windows build?

It would be nice to simplify.  Does the attached patch do the trick?

2006-07-07  Derek R. Price  <derek@ximbiot.com>

        * ndir.c, ndir.h: Move to...
        * dirent.c, dirent.h: ...here, and modify to meet POSIX dirent.h
        API.
        * Makefile.am (EXTRA_DIST): Rename ndir.{c,h} to dirent.{c,h}.
        * config.h.in.in [HAVE_SYS_DIR_H, HAVE_SYS_NDIR_H]: Remove
        obsolete macros.
        [HAVE_DIRENT_H]: Define.

Cheers,

Derek
- --
Derek R. Price
CVS Solutions Architect
Get CVS support at Ximbiot <http://ximbiot.com>!
v: +1 248.835.1260
f: +1 248.835.1263
<mailto:derek@ximbiot.com>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFErw6bLD1OTBfyMaQRAljPAKDk2J9ykgMrHozY2OujZiIyrCyR2QCgxYkj
+0W01dnoc2GHs8STvidbgQA=
=oOYB
-----END PGP SIGNATURE-----
? win-dirent.diff
Index: windows-NT/Makefile.am
===================================================================
RCS file: /cvsroot/cvs/ccvs/windows-NT/Makefile.am,v
retrieving revision 1.35
diff -u -p -r1.35 Makefile.am
--- windows-NT/Makefile.am      7 Jul 2006 01:11:17 -0000       1.35
+++ windows-NT/Makefile.am      8 Jul 2006 01:29:13 -0000
@@ -31,14 +31,13 @@ EXTRA_DIST = \
        stamp-chi \
        mkconfig.pl \
        fix-msvc-mak.pl \
-       ndir.h \
+       dirent.c dirent.h \
        pwd.h \
        rcmd.h \
        stdbool.h \
        stdint.h \
        filesubr.c \
        mkdir.c \
-       ndir.c \
        netdb.h \
        pwd.c \
        rcmd.c \
Index: windows-NT/Makefile.in
===================================================================
RCS file: /cvsroot/cvs/ccvs/windows-NT/Makefile.in,v
retrieving revision 1.129
diff -u -p -r1.129 Makefile.in
--- windows-NT/Makefile.in      7 Jul 2006 01:11:17 -0000       1.129
+++ windows-NT/Makefile.in      8 Jul 2006 01:29:13 -0000
@@ -331,14 +331,13 @@ EXTRA_DIST = \
        stamp-chi \
        mkconfig.pl \
        fix-msvc-mak.pl \
-       ndir.h \
+       dirent.c dirent.h \
        pwd.h \
        rcmd.h \
        stdbool.h \
        stdint.h \
        filesubr.c \
        mkdir.c \
-       ndir.c \
        netdb.h \
        pwd.c \
        rcmd.c \
Index: windows-NT/config.h
===================================================================
RCS file: /cvsroot/cvs/ccvs/windows-NT/config.h,v
retrieving revision 1.203
diff -u -p -r1.203 config.h
--- windows-NT/config.h 7 Jul 2006 12:27:02 -0000       1.203
+++ windows-NT/config.h 8 Jul 2006 01:29:13 -0000
@@ -400,7 +400,7 @@
 #undef HAVE_DIRECT_H
 
 /* Define to 1 if you have the <dirent.h> header file. */
-#undef HAVE_DIRENT_H
+#define HAVE_DIRENT_H 1
 
 /* Define to 1 if you have the `dup2' function. */
 #define HAVE_DUP2 1
Index: windows-NT/config.h.in
===================================================================
RCS file: /cvsroot/cvs/ccvs/windows-NT/config.h.in,v
retrieving revision 1.131
diff -u -p -r1.131 config.h.in
--- windows-NT/config.h.in      7 Jul 2006 12:27:02 -0000       1.131
+++ windows-NT/config.h.in      8 Jul 2006 01:29:13 -0000
@@ -393,7 +393,7 @@
 #undef HAVE_DIRECT_H
 
 /* Define to 1 if you have the <dirent.h> header file. */
-#undef HAVE_DIRENT_H
+#define HAVE_DIRENT_H 1
 
 /* Define to 1 if you have the `dup2' function. */
 #define HAVE_DUP2 1
Index: windows-NT/config.h.in.in
===================================================================
RCS file: /cvsroot/cvs/ccvs/windows-NT/config.h.in.in,v
retrieving revision 1.54
diff -u -p -r1.54 config.h.in.in
--- windows-NT/config.h.in.in   7 Jul 2006 12:27:02 -0000       1.54
+++ windows-NT/config.h.in.in   8 Jul 2006 01:29:13 -0000
@@ -385,7 +385,7 @@
 
 /* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
    */
-#undef HAVE_DIRENT_H
+#define HAVE_DIRENT_H 1
 
 /* Define to 1 if you have the `dup2' function. */
 #define HAVE_DUP2 1
@@ -834,20 +834,12 @@
 /* Define to 1 if you have the <sys/cdefs.h> header file. */
 #undef HAVE_SYS_CDEFS_H
 
-/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
-   */
-#undef HAVE_SYS_DIR_H
-
 /* Define to 1 if you have the <sys/file.h> header file. */
 #undef HAVE_SYS_FILE_H
 
 /* Define to 1 if you have the <sys/inttypes.h> header file. */
 #undef HAVE_SYS_INTTYPES_H
 
-/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
-   */
-#undef HAVE_SYS_NDIR_H
-
 /* Define to 1 if you have the <sys/param.h> header file. */
 #undef HAVE_SYS_PARAM_H
 
Index: windows-NT/dirent.c
===================================================================
RCS file: windows-NT/dirent.c
diff -N windows-NT/dirent.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ windows-NT/dirent.c 8 Jul 2006 01:29:13 -0000
@@ -0,0 +1,229 @@
+/*  dirent.c - portable directory routines
+    Copyright (C) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
+    Copyright (C) 2006 The Free Software Foundation, Inc.
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 1, or (at your option)
+    any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.  */
+
+/* Everything non trivial in this code is from: @(#)msd_dir.c 1.4
+   87/11/06.  A public domain implementation of BSD directory routines
+   for MS-DOS.  Written by Michael Rendell ({uunet,utai}michael@garfield),
+   August 1897 */
+
+/* Minor adaptations made in 2006 by Derek R. Price <derek@ximbiot.com> to
+ * appear to be <dirent.c> as opposed to its former incarnation as <ndir.c>.
+ */
+
+
+/* Validate API.  */
+#include <sys/types.h>
+#include <dirent.h>
+
+#include <io.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+
+#include <dos.h>
+#include "xalloc.h"
+
+static void free_dircontents (struct _dircontents *);
+
+/* find ALL files! */
+#define ATTRIBUTES     (_A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_SUBDIR)
+
+
+
+DIR *
+opendir (const char *name)
+{
+  struct _finddata_t find_buf;
+  DIR *dirp;
+  struct _dircontents *dp;
+  char name_buf[_MAX_PATH + 1];
+  char *slash = "";
+  long hFile;
+
+  if (!name)
+    name = "";
+  else if (*name)
+    {
+      const char *s;
+      int l = strlen (name);
+
+      s = name + l - 1;
+      if ( !(l == 2 && *s == ':') && *s != '\\' && *s != '/')
+       slash = "/";    /* save to insert slash between path and "*.*" */
+    }
+
+  strcat (strcat (strcpy (name_buf, name), slash), "*.*");
+
+  dirp = xmalloc (sizeof (DIR));
+  if (!dirp) return NULL;
+
+  dirp->dd_loc = 0;
+  dirp->dd_contents = dirp->dd_cp = NULL;
+
+  if ((hFile = _findfirst (name_buf, &find_buf)) < 0)
+    {
+      free (dirp);
+      return NULL;
+    }
+
+  do
+    {
+      dp = xmalloc (sizeof (struct _dircontents));
+      if (!dp)
+       {
+         free_dircontents (dirp->dd_contents);
+         return NULL;
+       }
+
+      dp->_d_entry = xmalloc (strlen (find_buf.name) + 1);
+      if (!dp->_d_entry)
+       {
+         free (dp);
+         free_dircontents (dirp->dd_contents);
+         return NULL;
+       }
+
+      if (dirp->dd_contents)
+       dirp->dd_cp = dirp->dd_cp->_d_next = dp;
+      else
+       dirp->dd_contents = dirp->dd_cp = dp;
+
+      strcpy (dp->_d_entry, find_buf.name);
+
+      dp->_d_next = NULL;
+
+    } while (!_findnext (hFile, &find_buf));
+
+  dirp->dd_cp = dirp->dd_contents;
+
+  _findclose(hFile);
+
+  return dirp;
+}
+
+
+void
+closedir (DIR *dirp)
+{
+  free_dircontents (dirp->dd_contents);
+  free (dirp);
+}
+
+
+
+int
+readdir_r (DIR *dirp, struct dirent *restrict dp,
+          struct dirent **restrict result)
+{
+  if (!dirp->dd_cp)
+    *result = NULL;
+  else
+    {
+      strcpy (dp->d_name, dirp->dd_cp->_d_entry);
+      dp.d_ino = 0;
+      dirp->dd_cp = dirp->dd_cp->_d_next;
+      dirp->dd_loc++;
+      *result = dp;
+    }
+
+  return 0;
+}
+
+
+
+struct dirent *
+readdir (DIR *dirp)
+{
+  static struct dirent dp;
+  static struct dirent *retval;
+  int err = readdir_r (dirp, &dp, &retval);
+  if (err)
+    {
+      errno = err;
+      retval = NULL;
+    }
+  return retval;
+}
+
+
+void
+seekdir (DIR *dirp, long off)
+{
+  long i = off;
+  struct _dircontents *dp;
+
+  if (off < 0)
+    return;
+  for (dp = dirp->dd_contents; --i >= 0 && dp; dp = dp->_d_next)
+    ;
+  dirp->dd_loc = off - (i + 1);
+  dirp->dd_cp = dp;
+}
+
+
+long
+telldir (DIR *dirp)
+{
+  return dirp->dd_loc;
+}
+
+
+/* Garbage collection */
+
+static void
+free_dircontents (struct _dircontents *dp)
+{
+  struct _dircontents *odp;
+
+  while (dp)
+    {
+      if (dp->_d_entry)
+       free (dp->_d_entry);
+      dp = (odp = dp)->_d_next;
+      free (odp);
+    }
+}
+
+
+#ifdef TEST
+
+void main (int argc, char *argv[]);
+
+void
+main (int argc, char *argv[])
+{
+  static DIR *directory;
+  struct dirent *entry = NULL;
+
+  char *name = "";
+
+  if (argc > 1)
+    name = argv[1];
+
+  directory = opendir (name);
+
+  if (!directory)
+    {
+      fprintf (stderr, "can't open directory `%s'.\n", name);
+      exit (2);
+    }
+
+  while (entry = readdir (directory))
+    printf ("> %s\n", entry->d_name);
+
+  printf ("done.\n");
+}
+
+#endif /* TEST */
Index: windows-NT/dirent.h
===================================================================
RCS file: windows-NT/dirent.h
diff -N windows-NT/dirent.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ windows-NT/dirent.h 8 Jul 2006 01:29:13 -0000
@@ -0,0 +1,56 @@
+/*  dirent.h - portable directory routines
+    Copyright (C) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
+    Copyright (C) 2006 The Free Software Foundation, Inc.
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 1, or (at your option)
+    any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.  */
+
+/* Everything non trivial in this code is taken from: @(#)msd_dir.c 1.4
+   87/11/06.  A public domain implementation of BSD directory routines
+   for MS-DOS.  Written by Michael Rendell ({uunet,utai}michael@garfield),
+   August 1897 */
+
+/* Minor adaptations made in 2006 by Derek R. Price <derek@ximbiot.com> to
+ * appear to be <dirent.h> as opposed to its former incarnation as <ndir.h>.
+ */
+
+#define        rewinddir(dirp) seekdir (dirp, 0L)
+
+/* 255 is said to be big enough for Windows NT.  The more elegant
+   solution would be declaring d_name as one byte long and allocating
+   it to the actual size needed.  */
+#define        MAXNAMLEN       255
+
+struct dirent
+{
+  ino_t d_ino;                 /* a bit of a farce */
+  char d_name[MAXNAMLEN + 1];  /* garentee null termination */
+};
+
+struct _dircontents
+{
+  char *_d_entry;
+  struct _dircontents *_d_next;
+};
+
+typedef struct _dirdesc
+{
+  int dd_id;                   /* uniquely identify each open directory */
+  long dd_loc;                 /* where we are in directory entry is this */
+  struct _dircontents *dd_contents;    /* pointer to contents of dir */
+  struct _dircontents *dd_cp;  /* pointer to current position */
+} DIR;
+
+int closedir (DIR *);
+DIR *opendir (const char *);
+struct dirent *readdir (DIR *);
+int readdir_r (DIR *, struct dirent *restrict, struct dirent **restrict);
+void seekdir (DIR *, long);
+long telldir (DIR *);
Index: windows-NT/ndir.c
===================================================================
RCS file: windows-NT/ndir.c
diff -N windows-NT/ndir.c
--- windows-NT/ndir.c   26 May 2005 16:07:12 -0000      1.8
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,214 +0,0 @@
-/*  msd_dir.c - portable directory routines
-    Copyright (C) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 1, or (at your option)
-    any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.  */
-
-/* Everything non trivial in this code is from: @(#)msd_dir.c 1.4
-   87/11/06.  A public domain implementation of BSD directory routines
-   for MS-DOS.  Written by Michael Rendell ({uunet,utai}michael@garfield),
-   August 1897 */
-
-
-#include <io.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <dos.h>
-
-#include <ndir.h>
-#include "xalloc.h"
-
-static void free_dircontents (struct _dircontents *);
-
-/* find ALL files! */
-#define ATTRIBUTES     (_A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_SUBDIR)
-
-
-
-DIR *
-opendir (const char *name)
-{
-  struct _finddata_t find_buf;
-  DIR *dirp;
-  struct _dircontents *dp;
-  char name_buf[_MAX_PATH + 1];
-  char *slash = "";
-  long hFile;
-
-  if (!name)
-    name = "";
-  else if (*name)
-    {
-      const char *s;
-      int l = strlen (name);
-
-      s = name + l - 1;
-      if ( !(l == 2 && *s == ':') && *s != '\\' && *s != '/')
-       slash = "/";    /* save to insert slash between path and "*.*" */
-    }
-
-  strcat (strcat (strcpy (name_buf, name), slash), "*.*");
-
-  dirp = xmalloc (sizeof (DIR));
-  if (!dirp) return NULL;
-
-  dirp->dd_loc = 0;
-  dirp->dd_contents = dirp->dd_cp = NULL;
-
-  if ((hFile = _findfirst (name_buf, &find_buf)) < 0)
-    {
-      free (dirp);
-      return NULL;
-    }
-
-  do
-    {
-      dp = xmalloc (sizeof (struct _dircontents));
-      if (!dp)
-       {
-         free_dircontents (dirp->dd_contents);
-         return NULL;
-       }
-
-      dp->_d_entry = xmalloc (strlen (find_buf.name) + 1);
-      if (!dp->_d_entry)
-       {
-         free (dp);
-         free_dircontents (dirp->dd_contents);
-         return NULL;
-       }
-
-      if (dirp->dd_contents)
-       dirp->dd_cp = dirp->dd_cp->_d_next = dp;
-      else
-       dirp->dd_contents = dirp->dd_cp = dp;
-
-      strcpy (dp->_d_entry, find_buf.name);
-
-      dp->_d_next = NULL;
-
-    } while (!_findnext (hFile, &find_buf));
-
-  dirp->dd_cp = dirp->dd_contents;
-
-  _findclose(hFile);
-
-  return dirp;
-}
-
-
-void
-closedir (DIR *dirp)
-{
-  free_dircontents (dirp->dd_contents);
-  free (dirp);
-}
-
-
-struct direct *
-readdir (DIR *dirp)
-{
-  static struct direct dp;
-
-  if (!dirp->dd_cp) return NULL;
-  dp.d_namlen = dp.d_reclen =
-    strlen (strcpy (dp.d_name, dirp->dd_cp->_d_entry));
-#if 0 /* JB */
-  strlwr (dp.d_name);          /* JF */
-#endif
-  dp.d_ino = 0;
-  dirp->dd_cp = dirp->dd_cp->_d_next;
-  dirp->dd_loc++;
-
-  return &dp;
-}
-
-
-void
-seekdir (DIR *dirp, long off)
-{
-  long i = off;
-  struct _dircontents *dp;
-
-  if (off < 0)
-    return;
-  for (dp = dirp->dd_contents; --i >= 0 && dp; dp = dp->_d_next)
-    ;
-  dirp->dd_loc = off - (i + 1);
-  dirp->dd_cp = dp;
-}
-
-
-long
-telldir (DIR *dirp)
-{
-  return dirp->dd_loc;
-}
-
-
-/* Garbage collection */
-
-static void
-free_dircontents (struct _dircontents *dp)
-{
-  struct _dircontents *odp;
-
-  while (dp)
-    {
-      if (dp->_d_entry)
-       free (dp->_d_entry);
-      dp = (odp = dp)->_d_next;
-      free (odp);
-    }
-}
-
-
-#ifdef TEST
-
-void main (int argc, char *argv[]);
-
-void
-main (int argc, char *argv[])
-{
-  static DIR *directory;
-  struct direct *entry = NULL;
-
-  char *name = "";
-
-  if (argc > 1)
-    name = argv[1];
-
-  directory = opendir (name);
-
-  if (!directory)
-    {
-      fprintf (stderr, "can't open directory `%s'.\n", name);
-      exit (2);
-    }
-
-  while (entry = readdir (directory))
-    printf ("> %s\n", entry->d_name);
-
-  printf ("done.\n");
-}
-
-#endif /* TEST */
-
-/* 
- * Local Variables:
- * mode:C
- * ChangeLog:ChangeLog
- * compile-command:make
- * End:
- */
Index: windows-NT/ndir.h
===================================================================
RCS file: windows-NT/ndir.h
diff -N windows-NT/ndir.h
--- windows-NT/ndir.h   26 May 2005 16:07:12 -0000      1.7
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,62 +0,0 @@
-/*  ndir.c - portable directory routines
-    Copyright (C) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 1, or (at your option)
-    any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.  */
-
-/* Everything non trivial in this code is taken from: @(#)msd_dir.c 1.4
-   87/11/06.  A public domain implementation of BSD directory routines
-   for MS-DOS.  Written by Michael Rendell ({uunet,utai}michael@garfield),
-   August 1897 */
-
-#include <sys/types.h> /* ino_t definition */
-
-#define        rewinddir(dirp) seekdir(dirp, 0L)
-
-/* 255 is said to be big enough for Windows NT.  The more elegant
-   solution would be declaring d_name as one byte long and allocating
-   it to the actual size needed.  */
-#define        MAXNAMLEN       255
-
-struct direct
-{
-  ino_t d_ino;                 /* a bit of a farce */
-  int d_reclen;                        /* more farce */
-  int d_namlen;                        /* length of d_name */
-  char d_name[MAXNAMLEN + 1];  /* garentee null termination */
-};
-
-struct _dircontents
-{
-  char *_d_entry;
-  struct _dircontents *_d_next;
-};
-
-typedef struct _dirdesc
-{
-  int dd_id;                   /* uniquely identify each open directory */
-  long dd_loc;                 /* where we are in directory entry is this */
-  struct _dircontents *dd_contents;    /* pointer to contents of dir */
-  struct _dircontents *dd_cp;  /* pointer to current position */
-} DIR;
-
-void seekdir (DIR *, long);
-long telldir (DIR *);
-DIR *opendir (const char *);
-void closedir (DIR *);
-struct direct *readdir (DIR *);
-
-/* 
- * Local Variables:
- * mode:C
- * ChangeLog:ChangeLog
- * compile-command:make
- * End:
- */
Index: windows-NT/stamp-chi
===================================================================
RCS file: /cvsroot/cvs/ccvs/windows-NT/stamp-chi,v
retrieving revision 1.114
diff -u -p -r1.114 stamp-chi
--- windows-NT/stamp-chi        7 Jul 2006 02:47:10 -0000       1.114
+++ windows-NT/stamp-chi        8 Jul 2006 01:29:14 -0000
@@ -393,7 +393,7 @@
 #undef HAVE_DIRECT_H
 
 /* Define to 1 if you have the <dirent.h> header file. */
-#undef HAVE_DIRENT_H
+#define HAVE_DIRENT_H 1
 
 /* Define to 1 if you have the `dup2' function. */
 #define HAVE_DUP2 1

reply via email to

[Prev in Thread] Current Thread [Next in Thread]