no setenv/unsetenv on Solaris

Alex S Moore <[email protected]>
Newsgroups gmane.mail.libetpan.user
Message-ID <[email protected]>
Since there is no setenv or unsetenv on Solaris, I made a patch which 
may work ok.  Please see attached.

Functionally, I think that the Solaris function putenv with no value 
assigned to the environment variable will leave the variable without a 
value in the environment list.  Not sure about that, but if it is true, 
does that work for libetpan?

I used my previous defines for __SUNPRO_CC, since if someone is using 
that compiler, they are probably on Solaris.  This may not be the best 
way, but I do not know how to add code to configure to determine if the 
setenv and unsetenv or putenv functions are available.  Maybe a 
HAVE_SETENV defines?  Could someone do this?  I am having the same 
problem with sylpheed-claws, so I will see what the claws developers 
recommend.

I am not a C programmer by trade, so please check my code carefully to 
make sure that it passes security protocols, etc.

Would you add this logic, or your revision, to the base source?

Thanks, Alex
patch-mailstorage_tools.diff (text/x-patch, 1.3 KB)
--- ./src/driver/interface/orig-mailstorage_tools.c	2005-07-26 17:45:26.039192000 -0500
+++ ./src/driver/interface/mailstorage_tools.c	2005-07-26 20:05:19.241229000 -0500
@@ -101,11 +101,13 @@
 /* connection through a shell command */
 /* SEB unsupported on Windows */
 #ifndef WIN32
+#define LINE_LEN 80
 
 static void do_exec_command(int fd, const char *command,
     char *servername, uint16_t port)
 {
   int i, maxopen;
+  char *s;
   
   if (fork() > 0) {
     /* Fork again to become a child of init rather than
@@ -113,11 +115,37 @@
     exit(0);
   }
   
+#if defined (__SUNPRO_CC)
+  if (servername) {
+    strcpy(s, "ETPANSERVER=");
+    strlcat(s, servername, LINE_LEN);
+    putenv(s);
+  }
+  else {
+    strcpy(s, "ETPANSERVER=");
+    putenv(s);
+  }
+#else
   if (servername)
     setenv("ETPANSERVER", servername, 1);
   else
     unsetenv("ETPANSERVER");
+#endif
   
+#if defined (__SUNPRO_CC)
+  if (port) {
+    char porttext[20];
+    
+    snprintf(porttext, sizeof(porttext), "%d", port);
+    strcpy(s, "ETPANPORT=");
+    strlcat(s, porttext, LINE_LEN);
+    putenv(s);
+  }
+  else {
+    strcpy(s, "ETPANPORT=");
+    putenv(s);
+  }
+#else
   if (port) {
     char porttext[20];
     
@@ -127,6 +155,7 @@
   else {
     unsetenv("ETPANPORT");
   }
+#endif
   
   /* Not a lot we can do if there's an error other than bail. */
   if (dup2(fd, 0) == -1)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.