"Bill Schottstaedt" <[EMAIL PROTECTED]> writes: > > I found some examples by Googling for readdir_r and _PC_NAME_MAX.
Incomplete bit of code below, it's not pretty but I guess it's what has to be done. #if HAVE_READDIR_R /* On Solaris 2.7, struct dirent only contains "char d_name[1]" and the application 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". On Solaris 2.10, there's no NAME_MAX because it varies according to the filesystem, one is expected to use pathconf(). So the code below tries a plain struct dirent, plus all three of the above possibly bigger sizes, to establish the buffer. If we're not using pathconf then the size is a constant and we don't need to malloc/free, but let's assume for modern systems pathconf is usual so most of the time we'll be wanting a dynamic size. */ size_t bufsize = sizeof (struct dirent); char *buf; int old_errno; #ifdef NAME_MAX bufsize = SCM_MAX (bufsize, sizeof(struct dirent) + NAME_MAX); bufsize = SCM_MAX (bufsize, offsetof (struct dirent, d_name) + NAME_MAX + 1\); #endif #ifdef _PC_NAME_MAX { char *c_dirname = scm_to_locale_string (SCM_FILENAME (port)); long name_max = pathconf (c_dirname, _PC_NAME_MAX); old_errno = errno; free (c_dirname); errno = old_errno; if (name_max == -1) SCM_SYSERROR; bufsize = SCM_MAX (bufsize, name_max); } #endif buf = scm_malloc (bufsize); SCM_SYSCALL (readdir_r ((DIR *) SCM_CELL_WORD_1 (port), (struct dirent *) buf, &rdent)); ... _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel