[前][次][番号順一覧][スレッド一覧]

ruby-changes:11604

From: nobu <ko1@a...>
Date: Tue, 21 Apr 2009 09:25:58 +0900 (JST)
Subject: [ruby-changes:11604] Ruby:r23241 (trunk): * dir.c (dir_path, dir_each, glob_helper): use readdir_r() if

nobu	2009-04-21 09:25:43 +0900 (Tue, 21 Apr 2009)

  New Revision: 23241

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23241

  Log:
    * dir.c (dir_path, dir_each, glob_helper): use readdir_r() if
      available.

  Modified files:
    trunk/ChangeLog
    trunk/configure.in
    trunk/dir.c

Index: configure.in
===================================================================
--- configure.in	(revision 23240)
+++ configure.in	(revision 23241)
@@ -1068,7 +1068,7 @@
                  strlcpy strlcat)
 AC_CHECK_FUNCS(fmod killpg wait4 waitpid fork spawnv syscall chroot fsync getcwd eaccess\
 	      truncate ftruncate chsize times utimes utimensat fcntl lockf lstat\
-	      link symlink readlink\
+	      link symlink readlink readdir_r\
 	      setitimer setruid seteuid setreuid setresuid setproctitle socketpair\
 	      setrgid setegid setregid setresgid issetugid pause lchown lchmod\
 	      getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 23240)
+++ ChangeLog	(revision 23241)
@@ -1,3 +1,8 @@
+Tue Apr 21 09:25:41 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* dir.c (dir_path, dir_each, glob_helper): use readdir_r() if
+	  available.
+
 Tue Apr 21 09:20:21 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/mkmf.rb (init_mkmf): needs default library path even if
Index: dir.c
===================================================================
--- dir.c	(revision 23240)
+++ dir.c	(revision 23241)
@@ -478,6 +478,19 @@
     return rb_str_dup(dirp->path);
 }
 
+#if defined HAVE_READDIR_R
+# define READDIR(dir, enc, entry, dp) (readdir_r(dir, entry, &(dp)) == 0 && dp != 0)
+#elif defined _WIN32
+# define READDIR(dir, enc, entry, dp) ((dp = rb_w32_readdir_with_enc(dir, enc)) != 0)
+#else
+# define READDIR(dir, enc, entry, dp) ((dp = readdir(dir)) != 0)
+#endif
+#if defined HAVE_READDIR_R
+# define IF_HAVE_READDIR_R(something) something
+#else
+# define IF_HAVE_READDIR_R(something) /* nothing */
+#endif
+
 /*
  *  call-seq:
  *     dir.read => string or nil
@@ -493,19 +506,13 @@
 static VALUE
 dir_read(VALUE dir)
 {
-#ifdef _WIN32
-# define READDIR(dir, enc) rb_w32_readdir_with_enc(dir, enc)
-#else
-# define READDIR(dir, enc) readdir(dir)
-#endif
-
     struct dir_data *dirp;
     struct dirent *dp;
+    IF_HAVE_READDIR_R(struct dirent entry);
 
     GetDIR(dir, dirp);
     errno = 0;
-    dp = READDIR(dirp->dir, dirp->enc);
-    if (dp) {
+    if (READDIR(dirp->dir, dirp->enc, &entry, dp)) {
 	return rb_external_str_new_with_enc(dp->d_name, NAMLEN(dp), dirp->enc);
     }
     else if (errno == 0) {	/* end of stream */
@@ -539,11 +546,12 @@
 {
     struct dir_data *dirp;
     struct dirent *dp;
+    IF_HAVE_READDIR_R(struct dirent entry);
 
     RETURN_ENUMERATOR(dir, 0, 0);
     GetDIR(dir, dirp);
     rewinddir(dirp->dir);
-    for (dp = READDIR(dirp->dir, dirp->enc); dp != NULL; dp = READDIR(dirp->dir, dirp->enc)) {
+    while (READDIR(dirp->dir, dirp->enc, &entry, dp)) {
 	rb_yield(rb_external_str_new_with_enc(dp->d_name, NAMLEN(dp), dirp->enc));
 	if (dirp->dir == NULL) dir_closed();
     }
@@ -1259,10 +1267,11 @@
 
     if (magical || recursive) {
 	struct dirent *dp;
+	IF_HAVE_READDIR_R(struct dirent entry);
 	DIR *dirp = do_opendir(*path ? path : ".", flags);
 	if (dirp == NULL) return 0;
 
-	for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
+	while (READDIR(dirp, enc, &entry, dp)) {
 	    char *buf = join_path(path, dirsep, dp->d_name);
 	    enum answer new_isdir = UNKNOWN;
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]