Index: include/apr_portable.h
===================================================================
--- include/apr_portable.h	(revision 603256)
+++ include/apr_portable.h	(working copy)
@@ -344,6 +344,21 @@
 /**
  * convert the file from os specific type to apr type.
  * @param file The apr file we are converting to.
+ * @param thefile The os specific file to convert
+ * @param flags The flags that were used to open this file.
+ * @param cont The pool to use if it is needed.
+ * @remark On Unix, it is only possible to put a file descriptor into
+ *         an apr file type.
+ * @remark The default is to register an on-close cleanup handler.
+ */
+APR_DECLARE(apr_status_t) apr_os_file_put_ex(apr_file_t **file,
+                                          apr_os_file_t *thefile,
+                                          apr_int32_t flags,
+                                          apr_pool_t *cont); 
+
+/**
+ * convert the file from os specific type to apr type.
+ * @param file The apr file we are converting to.
  * @param thefile The os specific pipe to convert
  * @param cont The pool to use if it is needed.
  * @remark On Unix, it is only possible to put a file descriptor into
Index: file_io/unix/open.c
===================================================================
--- file_io/unix/open.c	(revision 603256)
+++ file_io/unix/open.c	(working copy)
@@ -86,10 +86,7 @@
 {
     apr_os_file_t fd;
     int oflags = 0;
-#if APR_HAS_THREADS
-    apr_thread_mutex_t *thlock;
     apr_status_t rv;
-#endif
 
     if ((flag & APR_READ) && (flag & APR_WRITE)) {
         oflags = O_RDWR;
@@ -134,16 +131,6 @@
     }
 #endif
 
-#if APR_HAS_THREADS
-    if ((flag & APR_BUFFERED) && (flag & APR_XTHREAD)) {
-        rv = apr_thread_mutex_create(&thlock,
-                                     APR_THREAD_MUTEX_DEFAULT, pool);
-        if (rv) {
-            return rv;
-        }
-    }
-#endif
-
     if (perm == APR_OS_DEFAULT) {
         fd = open(fname, oflags, 0666);
     }
@@ -154,48 +141,13 @@
        return errno;
     }
 
-    (*new) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
-    (*new)->pool = pool;
-    (*new)->flags = flag;
-    (*new)->filedes = fd;
+    if ((rv = apr_os_file_put_ex(new, &fd, flag, pool)) != APR_SUCCESS) {
+        return rv;
+    }
 
     (*new)->fname = apr_pstrdup(pool, fname);
-
     (*new)->blocking = BLK_ON;
-    (*new)->buffered = (flag & APR_BUFFERED) > 0;
 
-    if ((*new)->buffered) {
-        (*new)->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE);
-        (*new)->bufsize = APR_FILE_DEFAULT_BUFSIZE;
-#if APR_HAS_THREADS
-        if ((*new)->flags & APR_XTHREAD) {
-            (*new)->thlock = thlock;
-        }
-#endif
-    }
-    else {
-        (*new)->buffer = NULL;
-    }
-
-    (*new)->is_pipe = 0;
-    (*new)->timeout = -1;
-    (*new)->ungetchar = -1;
-    (*new)->eof_hit = 0;
-    (*new)->filePtr = 0;
-    (*new)->bufpos = 0;
-    (*new)->dataRead = 0;
-    (*new)->direction = 0;
-#ifndef WAITIO_USES_POLL
-    /* Start out with no pollset.  apr_wait_for_io_or_timeout() will
-     * initialize the pollset if needed.
-     */
-    (*new)->pollset = NULL;
-#endif
-    if (!(flag & APR_FILE_NOCLEANUP)) {
-        apr_pool_cleanup_register((*new)->pool, (void *)(*new), 
-                                  apr_unix_file_cleanup, 
-                                  apr_unix_child_file_cleanup);
-    }
     return APR_SUCCESS;
 }
 
@@ -235,6 +187,14 @@
                                           apr_os_file_t *thefile,
                                           apr_int32_t flags, apr_pool_t *pool)
 {
+    return apr_os_file_put_ex(file, thefile, flags|APR_FILE_NOCLEANUP, pool);
+}
+
+APR_DECLARE(apr_status_t) apr_os_file_put_ex(apr_file_t **file, 
+                                          apr_os_file_t *thefile,
+                                          apr_int32_t flags,
+                                          apr_pool_t *pool)
+{
     int *dafile = thefile;
     
     (*file) = apr_pcalloc(pool, sizeof(apr_file_t));
@@ -244,7 +204,7 @@
     (*file)->timeout = -1;
     (*file)->ungetchar = -1; /* no char avail */
     (*file)->filedes = *dafile;
-    (*file)->flags = flags | APR_FILE_NOCLEANUP;
+    (*file)->flags = flags;
     (*file)->buffered = (flags & APR_BUFFERED) > 0;
 
 #ifndef WAITIO_USES_POLL
@@ -268,6 +228,13 @@
         }
 #endif
     }
+
+    if (!((*file)->flags & APR_FILE_NOCLEANUP)) {
+        apr_pool_cleanup_register((*file)->pool, (void *)(*file), 
+                                  apr_unix_file_cleanup, 
+                                  apr_unix_child_file_cleanup);
+    }
+
     return APR_SUCCESS;
 }    
 
