From 05249b045a95310a3e9fb687d651a292f4d71403 Mon Sep 17 00:00:00 2001
From: Andy Cedilnik <andy.cedilnik@kitware.com>
Date: Mon, 7 Jul 2003 08:36:40 -0400
Subject: [PATCH] ENH: Start working on Working Directory support

---
 Process.h.in  |  8 ++++++++
 ProcessUNIX.c | 26 ++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/Process.h.in b/Process.h.in
index 4e78c4b7..48da46db 100644
--- a/Process.h.in
+++ b/Process.h.in
@@ -31,6 +31,7 @@
 #define kwsysProcess_Delete              kwsys(Process_Delete)
 #define kwsysProcess_SetCommand          kwsys(Process_SetCommand)
 #define kwsysProcess_SetTimeout          kwsys(Process_SetTimeout)
+#define kwsysProcess_SetWorkingDirectory kwsys(Process_SetWorkingDirectory)
 #define kwsysProcess_State_Starting      kwsys(Process_State_Starting)
 #define kwsysProcess_State_Error         kwsys(Process_State_Error)
 #define kwsysProcess_State_Exception     kwsys(Process_State_Exception)
@@ -97,6 +98,12 @@ kwsysEXPORT void kwsysProcess_SetCommand(kwsysProcess* cp,
  */
 kwsysEXPORT void kwsysProcess_SetTimeout(kwsysProcess* cp, double timeout);
 
+/**
+ * Set the working directory for the child process. The working directory can
+ * be absolute or relative to the current directory. 
+ */
+kwsysEXPORT void kwsysProcess_SetWorkingDirectory(kwsysProcess* cp, const char* dir);
+
 /**
  * Get the current state of the Process instance.  Possible states are:
  *
@@ -254,6 +261,7 @@ kwsysEXPORT void kwsysProcess_Kill(kwsysProcess* cp);
 # undef kwsysProcess_Delete
 # undef kwsysProcess_SetCommand
 # undef kwsysProcess_SetTimeout
+# undef kwsysProcess_SetWorkingDirectory
 # undef kwsysProcess_State_Starting
 # undef kwsysProcess_State_Error
 # undef kwsysProcess_State_Exception
diff --git a/ProcessUNIX.c b/ProcessUNIX.c
index 492a2954..16960837 100644
--- a/ProcessUNIX.c
+++ b/ProcessUNIX.c
@@ -99,6 +99,9 @@ struct kwsysProcess_s
   
   /* The timeout length.  */
   double Timeout;
+
+  /* The working directory for the process. */
+  char* WorkingDirectory;
   
   /* Time at which the child started.  Negative for no timeout.  */
   kwsysProcessTime StartTime;
@@ -206,6 +209,29 @@ void kwsysProcess_SetTimeout(kwsysProcess* cp, double timeout)
     }
 }
 
+/*--------------------------------------------------------------------------*/
+void kwsysProcess_SetWorkingDirectory(kwsysProcess* cp, const char* dir)
+{
+  if(cp->WorkingDirectory == dir)
+    {
+    return;
+    }
+  if(cp->WorkingDirectory && dir && strcmp(cp->WorkingDirectory, dir) == 0)
+    {
+    return;
+    }
+  if(cp->WorkingDirectory)
+    {
+    free(cp->WorkingDirectory);
+    cp->WorkingDirectory = 0;
+    }
+  if(dir)
+    {
+    cp->WorkingDirectory = (char*) malloc(strlen(dir) + 1);
+    strcpy(cp->WorkingDirectory, dir);
+    }
+}
+
 /*--------------------------------------------------------------------------*/
 int kwsysProcess_GetState(kwsysProcess* cp)
 {
-- 
GitLab