Re: system() patch for Win32
- From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
- To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
- Cc: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
- Subject: Re: system() patch for Win32
- Date: Fri, 4 Apr 2003 15:39:21 -0500 (EST)
- Message-id: <200304042039.h34KdLp28712@candle.pha.pa.us> <text/plain>
OK, I have modified the use of "exec" to be more local to the snprintf.
---------------------------------------------------------------------------
Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > Here is a patch to handle 'rm', 'cp', and 'exec' usage by system();
> > again very small.
>
> This part seems unnecessarily obscurantist:
>
> > ! #ifndef WIN32
> > ! #define EXEC "exec "
> > ! #else
> > ! #define EXEC ""
> > ! #endif
>
> > ! sprintf(sys, "%s%s '%s'", EXEC, editorName, fname);
>
> I like the other style (just #ifdef to choose one of two sprintf
> commands) better. It seems easier to understand, as well as less
> fragile --- the way you have it here makes it *real* easy to break
> the computation of the buffer size for the command string.
>
> regards, tom lane
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>
--
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 4 Apr 2003 14:49:19 -0000
***************
*** 302,308 ****
--- 302,312 ----
}
/* Copy the template database to the new location */
+ #ifndef WIN32
snprintf(buf, sizeof(buf), "cp -r '%s' '%s'", src_loc, target_dir);
+ #else
+ snprintf(buf, sizeof(buf), "xcopy /e /i /q '%s' '%s'", src_loc, target_dir);
+ #endif
if (system(buf) != 0)
{
***************
*** 751,757 ****
--- 755,765 ----
}
}
+ #ifndef WIN32
snprintf(buf, sizeof(buf), "rm -rf '%s'", target_dir);
+ #else
+ snprintf(buf, sizeof(buf), "rmdir /s /q \"%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 4 Apr 2003 14:49:37 -0000
***************
*** 66,73 ****
static bool do_connect(const char *new_dbname, const char *new_user);
static bool do_shell(const char *command);
-
-
/*----------
* HandleSlashCmds:
*
--- 66,71 ----
***************
*** 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);
--- 1513,1523 ----
sys = malloc(strlen(editorName) + strlen(fname) + 10 + 1);
if (!sys)
return false;
! sprintf(sys,
! #ifndef WIN32
! "exec "
! #endif
! "%s '%s'", 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);
}
--- 1946,1956 ----
else
exit(EXIT_FAILURE);
}
! sprintf(sys,
! #ifndef WIN32
! "exec "
! #endif
! "%s", shellName);
result = system(sys);
free(sys);
}
Home |
Main Index |
Thread Index