system() patch for Win32

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема system() patch for Win32
Дата
Msg-id 200304030533.h335XXq26061@candle.pha.pa.us
обсуждение исходный текст
Ответы Re: system() patch for Win32  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-patches
Here is a patch to handle 'rm', 'cp', and 'exec' usage by system();
again very small.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.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);
      }

В списке pgsql-patches по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Win32 path patch
Следующее
От: Bruce Momjian
Дата:
Сообщение: Win32 defines