* readdir_r
@ 2004-03-25 22:29 Kevin Ryde
0 siblings, 0 replies; only message in thread
From: Kevin Ryde @ 2004-03-25 22:29 UTC (permalink / 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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-03-25 22:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-25 22:29 readdir_r Kevin Ryde
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).