You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Mladen Turk <mt...@mappingsoft.com> on 2001/10/06 14:02:19 UTC

[PATCH] apr_file_mktemp

Hi all,

apr_file_mktemp behaves differenty on WIN platform then on UNIX.
When you call the apr_file_mktemp on UNIX you'll get the opened apr_file_t.

Here is the patch that solves that behavior. When you call the
apr_file_mktem with valid
apr_file_t param you'll get the file opened file, and if you use the NULL as
apr_file_t param,
only the fname will be filled with temporyry file name.

MT.


Index: mktemp.c
===================================================================
RCS file: /home/cvspublic/apr/file_io/unix/mktemp.c,v
retrieving revision 1.11
diff -u -r1.11 mktemp.c
--- mktemp.c	2001/10/01 19:12:49	1.11
+++ mktemp.c	2001/10/06 11:44:09
@@ -68,7 +68,7 @@
 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 static apr_uint32_t randseed=0;

-static int gettemp(char *path, apr_file_t *doopen, int domkdir, int slen,
+static int gettemp(char *path, apr_file_t **doopen, int domkdir, int slen,
                    apr_pool_t *p)
 {
 	register char *start, *trv, *suffp;
@@ -128,7 +128,7 @@
 	for (;;) {
 		errno = 0;
 		if (doopen) {
-			if ((rv = apr_file_open(&doopen, path,
APR_CREATE|APR_EXCL|APR_READ|APR_WRITE,
+			if ((rv = apr_file_open(doopen, path,
APR_CREATE|APR_EXCL|APR_READ|APR_WRITE|APR_DELONCLOSE,
                                     APR_UREAD | APR_UWRITE, p)) ==
APR_SUCCESS)
 				return(1);
 			if (errno != EEXIST)
@@ -176,8 +176,10 @@
     int fd;
 #endif

+
 #ifndef HAVE_MKSTEMP
-    rv = gettemp(template, (*fp), 0, 0, p);
+
+    rv = gettemp(template, fp, 0, 0, p);
     if (rv == 0) {
         return errno;
     }
@@ -196,13 +198,7 @@
     (*fp)->filedes = fd;

 #endif
-#ifdef WIN32
-    apr_pool_cleanup_register((*fp)->cntxt, (void *)(*fp),
-                              file_cleanup, file_cleanup);
-#elif defined(OS2)
-    apr_pool_cleanup_register((*fp)->cntxt, (void *)(*fp),
-                              apr_file_cleanup, apr_file_cleanup);
-#else
+#if !defined(WIN32) && !defined(OS2)
     apr_pool_cleanup_register((*fp)->cntxt, (void *)(*fp),
                               apr_unix_file_cleanup,
apr_unix_file_cleanup);
 #endif

Mladen Turk
MCSE/GIS Specialist
MappingSoft
mailto: [ mturk@mappingsoft.com ]
http://apache.mappingsoft.com



Re: [PATCH] apr_file_mktemp

Posted by Cliff Woolley <cl...@yahoo.com>.
On Sat, 6 Oct 2001, Mladen Turk wrote:

> Hi all,
>
> apr_file_mktemp behaves differenty on WIN platform then on UNIX.
> When you call the apr_file_mktemp on UNIX you'll get the opened apr_file_t.
>
> Here is the patch that solves that behavior. When you call the
> apr_file_mktem with valid
> apr_file_t param you'll get the file opened file, and if you use the NULL as
> apr_file_t param,
> only the fname will be filled with temporyry file name.

I'm looking into this.  You bring up a good point that the file cleanups
are being run twice on systems that don't have mkstemp.  I'll fix that and
clean up some other cruft while I'm at it.  Thanks for the patch!

--Cliff


--------------------------------------------------------------
   Cliff Woolley
   cliffwoolley@yahoo.com
   Charlottesville, VA