unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
Subject: readdir_r
Date: Fri, 26 Mar 2004 08:29:53 +1000	[thread overview]
Message-ID: <878yhoftlq.fsf@zip.com.au> (raw)

[-- Attachment #1: Type: text/plain, Size: 93 bytes --]

        * filesys.c (scm_readdir): Use readdir_r when available, for thread
        safety.


[-- Attachment #2: filesys.c.readdir_r.diff --]
[-- Type: text/plain, Size: 1635 bytes --]

--- 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;
 

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel

                 reply	other threads:[~2004-03-25 22:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878yhoftlq.fsf@zip.com.au \
    --to=user42@zip.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).