[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Guile 1.7.91 has been released.

From: Kevin Ryde
Subject: Re: Guile 1.7.91 has been released.
Date: Tue, 14 Feb 2006 11:58:54 +1100
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)

"Bill Schottstaedt" <address@hidden> 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.

    /* 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 + 
#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)
      bufsize = SCM_MAX (bufsize, name_max);
    buf = scm_malloc (bufsize);
    SCM_SYSCALL (readdir_r ((DIR *) SCM_CELL_WORD_1 (port),
                            (struct dirent *) buf,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]