Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

system() patch for Win32


  • From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
  • To: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
  • Subject: system() patch for Win32
  • Date: Thu, 3 Apr 2003 00:33:33 -0500 (EST)
  • Message-id: <200304030533(dot)h335XXq26061(at)candle(dot)pha(dot)pa(dot)us>

Here is a patch to handle 'rm', 'cp', and 'exec' usage by system(); 
again very small.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: src/backend/commands/dbcommands.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/commands/dbcommands.c,v
retrieving revision 1.110
diff -c -c -r1.110 dbcommands.c
*** src/backend/commands/dbcommands.c	27 Jan 2003 00:46:41 -0000	1.110
--- src/backend/commands/dbcommands.c	3 Apr 2003 05:24:39 -0000
***************
*** 302,308 ****
--- 302,312 ----
  	}
  
  	/* Copy the template database to the new location */
+ #ifdef WIN32
+ 	snprintf(buf, sizeof(buf), "xcopy /e /i /q '%s' '%s'", src_loc, target_dir);
+ #else
  	snprintf(buf, sizeof(buf), "cp -r '%s' '%s'", src_loc, target_dir);
+ #endif
  
  	if (system(buf) != 0)
  	{
***************
*** 751,757 ****
--- 755,765 ----
  		}
  	}
  
+ #ifdef WIN32
+ 	snprintf(buf, sizeof(buf), "rmdir /s /q \"%s\"", target_dir);
+ #else
  	snprintf(buf, sizeof(buf), "rm -rf '%s'", target_dir);
+ #endif
  
  	if (system(buf) != 0)
  	{
Index: src/bin/psql/command.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/command.c,v
retrieving revision 1.94
diff -c -c -r1.94 command.c
*** src/bin/psql/command.c	20 Mar 2003 06:43:35 -0000	1.94
--- src/bin/psql/command.c	3 Apr 2003 05:24:45 -0000
***************
*** 66,72 ****
  static bool do_connect(const char *new_dbname, const char *new_user);
  static bool do_shell(const char *command);
  
! 
  
  /*----------
   * HandleSlashCmds:
--- 66,76 ----
  static bool do_connect(const char *new_dbname, const char *new_user);
  static bool do_shell(const char *command);
  
! #ifndef	WIN32
! #define	EXEC	"exec "
! #else
! #define	EXEC	""
! #endif
  
  /*----------
   * HandleSlashCmds:
***************
*** 1515,1521 ****
  	sys = malloc(strlen(editorName) + strlen(fname) + 10 + 1);
  	if (!sys)
  		return false;
! 	sprintf(sys, "exec  %s '%s'", editorName, fname);
  	result = system(sys);
  	if (result == -1)
  		psql_error("could not start editor %s\n", editorName);
--- 1519,1525 ----
  	sys = malloc(strlen(editorName) + strlen(fname) + 10 + 1);
  	if (!sys)
  		return false;
! 	sprintf(sys, "%s%s '%s'", EXEC, editorName, fname);
  	result = system(sys);
  	if (result == -1)
  		psql_error("could not start editor %s\n", editorName);
***************
*** 1944,1950 ****
  			else
  				exit(EXIT_FAILURE);
  		}
! 		sprintf(sys, "exec %s", shellName);
  		result = system(sys);
  		free(sys);
  	}
--- 1948,1954 ----
  			else
  				exit(EXIT_FAILURE);
  		}
! 		sprintf(sys, "%s%s", EXEC, shellName);
  		result = system(sys);
  		free(sys);
  	}


Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group