Index: bin/pg_dump/pg_backup_tar.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v
retrieving revision 1.50
diff -c -r1.50 pg_backup_tar.c
*** bin/pg_dump/pg_backup_tar.c	12 Feb 2006 06:11:50 -0000	1.50
--- bin/pg_dump/pg_backup_tar.c	20 Apr 2006 11:17:42 -0000
***************
*** 362,368 ****
--- 362,388 ----
  	{
  		tm = calloc(1, sizeof(TAR_MEMBER));
  
+ #ifndef WIN32
  		tm->tmpFH = tmpfile();
+ #else
+ 		/* on win32, tmpfile() generates a filename in the root directory, which requires
+ 		 * administrative permissions to write to. */
+ 		while (1)
+ 		{
+ 			char *tmpname;
+ 			int fd;
+ 			
+ 			tmpname = tempnam(NULL, NULL);
+ 			if (tmpname == NULL)
+ 				break;
+ 			fd = _open(tmpname, _O_RDWR | _O_CREAT | _O_EXCL | _O_TEMPORARY, 0);
+ 			if (fd == -1 && errno == EEXIST)
+ 				continue; /* Try again with a new name if file exists */
+ 			if (fd != -1)
+ 				tm->tmpFH = fdopen(fd, "w+b");
+ 			break;
+ 		}
+ #endif
  
  		if (tm->tmpFH == NULL)
  			die_horribly(AH, modulename, "could not generate temporary file name: %s\n", strerror(errno));
