From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: readdir_r Date: Fri, 26 Mar 2004 08:29:53 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <878yhoftlq.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1080254244 30611 80.91.224.253 (25 Mar 2004 22:37:24 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 25 Mar 2004 22:37:24 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Mar 25 23:37:15 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1B6dTP-0003ti-00 for ; Thu, 25 Mar 2004 23:37:15 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1B6dOP-0006XV-Hq for guile-devel@m.gmane.org; Thu, 25 Mar 2004 17:32:05 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1B6dNo-0006Wg-3j for guile-devel@gnu.org; Thu, 25 Mar 2004 17:31:28 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1B6dN7-0005wt-6U for guile-devel@gnu.org; Thu, 25 Mar 2004 17:31:16 -0500 Original-Received: from [61.8.0.84] (helo=mailout1.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.30) id 1B6dN6-0005rd-Fk for guile-devel@gnu.org; Thu, 25 Mar 2004 17:30:44 -0500 Original-Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87]) by mailout1.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i2PMUa4u027343 for ; Fri, 26 Mar 2004 09:30:36 +1100 Original-Received: from localhost (ppp20.dyn10.pacific.net.au [61.8.10.20]) by mailproxy2.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i2PMUZsf013003 for ; Fri, 26 Mar 2004 09:30:35 +1100 Original-Received: from gg by localhost with local (Exim 3.36 #1 (Debian)) id 1B6dMJ-0001jH-00; Fri, 26 Mar 2004 08:29:55 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:3573 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3573 --=-=-= * filesys.c (scm_readdir): Use readdir_r when available, for thread safety. --=-=-= Content-Disposition: inline; filename=filesys.c.readdir_r.diff --- filesys.c.~1.120.~ 2004-03-25 14:16:28.000000000 +1000 +++ filesys.c 2004-03-26 08:26:38.000000000 +1000 @@ -803,6 +803,11 @@ #undef FUNC_NAME +/* FIXME: The glibc manual has a portability note that readdir_r may not + null-terminate its return string. The circumstances outlined for this + are not clear, nor is it clear what should be done about it. Lets worry + about this if/when someone can figure it out. */ + SCM_DEFINE (scm_readdir, "readdir", 1, 0, 0, (SCM port), "Return (as a string) the next directory entry from the directory stream\n" @@ -810,6 +815,16 @@ "end of file object is returned.") #define FUNC_NAME s_scm_readdir { + /* On Solaris 2.7, struct dirent only contains "char d_name[1]" and one is + expected to provide a buffer of "sizeof(struct dirent) + NAME_MAX" + bytes. The glibc 2.3.2 manual notes this sort of thing too, and + advises "offsetof(struct dirent,d_name) + NAME_MAX + 1". Either should + suffice, we give both to be certain. */ + union { + struct dirent ent; + char pad1 [sizeof(struct dirent) + NAME_MAX]; + char pad2 [offsetof (struct dirent, d_name) + NAME_MAX + 1]; + } u; struct dirent *rdent; SCM_VALIDATE_DIR (1, port); @@ -817,7 +832,12 @@ SCM_MISC_ERROR ("Directory ~S is not open.", scm_list_1 (port)); errno = 0; +#if HAVE_READDIR_R + SCM_SYSCALL (readdir_r ((DIR *) SCM_CELL_WORD_1 (port), &u.ent, &rdent)); +#else + rdent = &u.ent; /* suppress warning about u unused */ SCM_SYSCALL (rdent = readdir ((DIR *) SCM_CELL_WORD_1 (port))); +#endif if (errno != 0) SCM_SYSERROR; --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel --=-=-=--