--- plplot-9548/lib/qsastime/qsastime_testlib.c	2009-02-18 06:16:21.245981000 +0000
+++ plplot-dev/lib/qsastime/qsastime_testlib.c	2009-02-18 13:17:09.734375000 +0000
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
+#include <errno.h>
 
 #define TEST01 0x1
 #define TEST02 0x2
@@ -42,6 +43,95 @@
 #define TEST15 0x4000
 #define TEST16 0x8000
 
+
+/* 
+   MCVC and possibly other systems do not have functions setenv and unsetenv.
+
+   Below are versions of setenv and unsetenv implemented in terms of putenv.
+   
+   Configuration : 
+   1. Macro HAVE_SETENV 
+   #define to 1 if system has SETENV Otherwise set to 0.
+
+   2. Macro HAVE_PUTENV 
+   #define to 1 if system has PUTENV Otherwise set to 0.
+   Not used if HAVE_SETENV 1
+
+   3. Macro CAN_FREE_PUTENV_BUFFER
+
+   For some systems the string pointed to by the putenv argument becomes
+   part of the environment.  A program should not alter or free the string,
+   and should not use stack or other transient string variables as arguments
+   to putenv().
+
+   For MSVC it appears from testing that putenv copies its values,
+   so we can cleanup as we go.
+
+   Where the system copies the value, #define CAN_FREE_PUTENV_BUFFER 1
+
+   KNOWN PROBLEM 
+   For MSVC setenv("ev","",1) UNSETS the environment variable rather than
+   setting it to and empty string. 
+
+   */
+#ifdef _MSC_VER
+#define HAVE_SETENV 0
+#define HAVE_PUTENV 1
+#define CAN_FREE_PUTENV_BUFFER 1
+#else
+#define HAVE_SETENV 1
+#define HAVE_PUTENV 0
+#endif
+
+
+#if defined(HAVE_SETENV) && defined(HAVE_PUTENV) && (!HAVE_SETENV && HAVE_PUTENV) 
+
+static int putenv_wrapper(const char *name, const char *value)
+{
+  int rc = -1;
+  int len;
+  char* penvArg;
+
+  len = strlen(name) + strlen(value) +2;
+  penvArg = (char*)malloc(len);
+  if(!penvArg){
+    errno =ENOMEM;
+    return -1;
+  }
+
+  sprintf(penvArg,"%s=%s",name,value);
+  rc = _putenv(penvArg);
+
+#ifdef CAN_FREE_PUTENV_BUFFER
+  free(penvArg);
+#else
+  /* without more knowledge of putenv implementation 
+     we cannot free penvArg */
+#endif
+
+  return rc;
+}
+int setenv(const char *name, const char *value, int overwrite)
+{
+  if (!overwrite && getenv(name)) {
+     /* what should errno be set to in this case*/
+    errno = EINVAL;
+    return -1;
+  }
+  return putenv_wrapper(name,value);
+}
+ 
+int unsetenv(const char *name)
+{
+  if (!getenv(name)) {
+    errno = EINVAL;
+    return -1;
+  }
+  return putenv_wrapper(name,"");
+}
+
+#endif
+
 /* Recommended (by Linux timegm man page) POSIX equivalent of Linux timegm C library function */
 time_t my_timegm(struct tm *tm)
 {
