--- include/apr_portable.h	2006-08-03 21:05:27.000000000 +1000
+++ include/apr_portable.h	2007-12-10 13:30:06.000000000 +1100
@@ -371,10 +371,12 @@
 /**
  * convert the dir from os specific type to apr type.
  * @param dir The apr dir we are converting to.
+ * @param dirname The full path to the directory (use / on all systems)
  * @param thedir The os specific dir to convert
  * @param cont The pool to use when creating to apr directory.
  */
 APR_DECLARE(apr_status_t) apr_os_dir_put(apr_dir_t **dir,
+                                         const char *dirname,
                                          apr_os_dir_t *thedir,
                                          apr_pool_t *cont); 
 
--- file_io/unix/dir.c	2006-08-03 21:05:27.000000000 +1000
+++ file_io/unix/dir.c	2007-12-10 13:28:05.000000000 +1100
@@ -24,6 +24,15 @@
 #include <limits.h>
 #endif
 
+/* On some platforms (e.g., Linux+GNU libc), d_name[] in struct 
+ * dirent is declared with enough storage for the name.  On other
+ * platforms (e.g., Solaris 8 for Intel), d_name is declared as a
+ * one-byte array.  Note: gcc evaluates this at compile time.
+ */
+static apr_size_t dirent_size = 
+    (sizeof(((apr_dir_t *)0)->entry->d_name) > 1 ? 
+    sizeof(struct dirent) : sizeof (struct dirent) + 255);
+
 static apr_status_t dir_cleanup(void *thedir)
 {
     apr_dir_t *dir = thedir;
@@ -71,14 +80,6 @@
 apr_status_t apr_dir_open(apr_dir_t **new, const char *dirname, 
                           apr_pool_t *pool)
 {
-    /* On some platforms (e.g., Linux+GNU libc), d_name[] in struct 
-     * dirent is declared with enough storage for the name.  On other
-     * platforms (e.g., Solaris 8 for Intel), d_name is declared as a
-     * one-byte array.  Note: gcc evaluates this at compile time.
-     */
-    apr_size_t dirent_size = 
-        (sizeof((*new)->entry->d_name) > 1 ? 
-         sizeof(struct dirent) : sizeof (struct dirent) + 255);
     DIR *dir = opendir(dirname);
 
     if (!dir) {
@@ -309,14 +310,22 @@
     return APR_SUCCESS;
 }
 
-apr_status_t apr_os_dir_put(apr_dir_t **dir, apr_os_dir_t *thedir,
+apr_status_t apr_os_dir_put(apr_dir_t **dir,
+                          const char *dirname,
+                          apr_os_dir_t *thedir,
                           apr_pool_t *pool)
 {
     if ((*dir) == NULL) {
         (*dir) = (apr_dir_t *)apr_pcalloc(pool, sizeof(apr_dir_t));
         (*dir)->pool = pool;
+        (*dir)->entry = apr_pcalloc(pool, dirent_size);
+        apr_pool_cleanup_register((*dir)->pool, *dir, dir_cleanup, apr_pool_cleanup_null);
+    }
+    else {
+        apr_pool_cleanup_run((*dir)->pool, *dir, dir_cleanup);
     }
     (*dir)->dirstruct = thedir;
+    (*dir)->dirname = apr_pstrdup(pool, dirname);
     return APR_SUCCESS;
 }
 
--- file_io/os2/dir.c	2006-08-03 21:05:27.000000000 +1000
+++ file_io/os2/dir.c	2007-12-10 13:31:51.000000000 +1100
@@ -155,13 +155,20 @@
 
 
 
-APR_DECLARE(apr_status_t) apr_os_dir_put(apr_dir_t **dir, apr_os_dir_t *thedir,
+APR_DECLARE(apr_status_t) apr_os_dir_put(apr_dir_t **dir,
+                                         const char *dirname,
+                                         apr_os_dir_t *thedir,
                                          apr_pool_t *pool)
 {
     if ((*dir) == NULL) {
         (*dir) = (apr_dir_t *)apr_pcalloc(pool, sizeof(apr_dir_t));
         (*dir)->pool = pool;
+        apr_pool_cleanup_register((*dir)->pool, *dir, dir_cleanup, apr_pool_cleanup_null);
+    }
+    else {
+        apr_pool_cleanup_run((*dir)->pool, *dir, dir_cleanup);
     }
     (*dir)->handle = *thedir;
+    (*dir)->dirname = apr_pstrdup(pool, dirname);
     return APR_SUCCESS;
 }
--- file_io/win32/dir.c	2006-08-03 21:05:27.000000000 +1000
+++ file_io/win32/dir.c	2007-12-10 13:32:23.000000000 +1100
@@ -386,6 +386,7 @@
 }
 
 APR_DECLARE(apr_status_t) apr_os_dir_put(apr_dir_t **dir,
+                                         const char *dirname,
                                          apr_os_dir_t *thedir,
                                          apr_pool_t *pool)
 {
