apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lucian Adrian Grijincu" <lucian.griji...@gmail.com>
Subject Re: apr_os_dir_put fixes
Date Thu, 13 Dec 2007 12:54:34 GMT
On Dec 11, 2007 6:27 PM, Lucian Adrian Grijincu
<lucian.grijincu@gmail.com> wrote:
> On Dec 11, 2007 6:02 PM, Michael Clark <michael@metaparadigm.com> wrote:
> >
> > Lucian Adrian Grijincu wrote:
> > > apart from the versioning detail, Iain raises a valid problem (bug) in APR:
> > Yes, although even with the allocation fixed, without dirname set
> > correctly, it will also not be able to do the apr_stat calls if they are
> > 'wanted' in apr_dir_read.
> >
>
> A few things can still be found without changing the interface.
>           struct dirent {
>               ino_t          d_ino;       /* inode number */
>               off_t          d_off;       /* offset to the next dirent */
>               unsigned short d_reclen;    /* length of this record */
>               unsigned char  d_type;      /* type of file */
>               char           d_name[256]; /* filename */
>           };
>
> The ino, type and name of the file can still be found, but not more.
> so, if you only need APR_FINFO_NAME|APR_FINFO_INODE|DIRENT_TYPE or
> less, you could go from here.
> Also, if you have the dirname to begin with, you can concatenate that
> with the .name member set up by apr_dir_read in apr_finfo_t and do it
> manually.

This is against the 1.2.x HEAD.
It adds allocation for ->entry for unix.
There's a comment for the doxygen header files stating the limitation.





Index: file_io/unix/dir.c
===================================================================
--- file_io/unix/dir.c	(revision 603897)
+++ file_io/unix/dir.c	(working copy)
@@ -312,12 +312,15 @@
 apr_status_t apr_os_dir_put(apr_dir_t **dir, apr_os_dir_t *thedir,
                           apr_pool_t *pool)
 {
+    const apr_size_t dirent_size =
+        (sizeof((*dir)->entry->d_name) > 1 ?
+         sizeof(struct dirent) : sizeof (struct dirent) + 255);
     if ((*dir) == NULL) {
         (*dir) = (apr_dir_t *)apr_pcalloc(pool, sizeof(apr_dir_t));
         (*dir)->pool = pool;
+        (*dir)->entry = apr_pcalloc(pool, dirent_size);
     }
     (*dir)->dirstruct = thedir;
     return APR_SUCCESS;
 }

-

Index: include/apr_portable.h
===================================================================
--- include/apr_portable.h	(revision 603897)
+++ include/apr_portable.h	(working copy)
@@ -373,6 +373,11 @@
  * @param dir The apr dir we are converting to.
  * @param thedir The os specific dir to convert
  * @param cont The pool to use when creating to apr directory.
+ * @bug If you use *dir with apr_dir_read, you can only ask for
+ *      APR_FINFO_INODE, APR_FINFO_TYPE and APR_FINFO_NAME.
+ *      If you want other fields you should concatenate the
+ *      name of the file with the directory name and issue a
+ *      apr_stat on the full path to the file.
  */
 APR_DECLARE(apr_status_t) apr_os_dir_put(apr_dir_t **dir,
                                          apr_os_dir_t *thedir,

-- 
Lucian

Mime
View raw message