Index: src/bin/pg_dump/pg_backup_tar.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v
retrieving revision 1.52
diff -c -c -r1.52 pg_backup_tar.c
*** src/bin/pg_dump/pg_backup_tar.c	7 Jun 2006 22:24:44 -0000	1.52
--- src/bin/pg_dump/pg_backup_tar.c	27 Jun 2006 00:32:06 -0000
***************
*** 359,365 ****
--- 359,393 ----
  	{
  		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 on certain systems.
+ 		 *	Loop until we find a unique file name we can create.
+ 		 */
+ 		while (1)
+ 		{
+ 			char *name;
+ 			int fd;
+ 			
+ 			name = _tempnam(NULL, "pg_temp_");
+ 			if (name == NULL)
+ 				break;
+ 			fd = open(name, O_RDWR | O_CREAT | O_EXCL | O_BINARY |
+ 					  O_TEMPORARY, S_IREAD | S_IWRITE);
+ 			free(name);
+ 
+ 			if (fd != -1)	/* created a file */
+ 			{
+ 				tm->tmpFH = fdopen(fd, "w+b");
+ 				break;
+ 			}
+ 			else if (errno != EEXIST)	/* failure other than file exists */
+ 				break;
+ 		}
+ #endif
  
  		if (tm->tmpFH == NULL)
  			die_horribly(AH, modulename, "could not generate temporary file name: %s\n", strerror(errno));
