Index: branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 882)
+++ branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 890)
@@ -340,5 +340,5 @@
               if (s1 == NULL)
                 {
-                  dup2 (saved_stdout, fileno (stdout));
+                  zDup2 (saved_stdout, fileno (stdout));
                   errorException (m, _("Unable to allocate memory"),
                                   "InternalError", NULL);
@@ -361,5 +361,5 @@
                     sprintf (tmp01, _("Unable to parse the ZCFG file: %s."),
                              dp->d_name);
-                  dup2 (saved_stdout, fileno (stdout));
+                  zDup2 (saved_stdout, fileno (stdout));
                   errorException (m, tmp01, "InternalError", NULL);
                   return -1;
@@ -1101,5 +1101,5 @@
       char tmp1[13];
       sprintf (tmp1, "LC_ALL=%s", tmp);
-      putenv (tmp1);
+      _putenv (tmp1);
 #endif
       free (tmp);
@@ -1113,5 +1113,5 @@
       char tmp1[13];
       sprintf (tmp1, "LC_ALL=en_US");
-      putenv (tmp1);
+      _putenv (tmp1);
 #endif
       setMapInMaps (m, "main", "language", "en-US");
@@ -1123,5 +1123,5 @@
   char tmp1[17];
   sprintf (tmp1, "LC_NUMERIC=C");
-  putenv (tmp1);
+  _putenv (tmp1);
 #endif
   bind_textdomain_codeset ("zoo-kernel", "UTF-8");
@@ -1306,16 +1306,16 @@
   registry* zooRegistry=NULL;
   if(reg!=NULL){
-    int saved_stdout = dup (fileno (stdout));
-    dup2 (fileno (stderr), fileno (stdout));
+    int saved_stdout = zDup (fileno (stdout));
+    zDup2 (fileno (stderr), fileno (stdout));
     if(createRegistry (m,&zooRegistry,reg->value)<0){
       map *message=getMapFromMaps(m,"lenv","message");
       map *type=getMapFromMaps(m,"lenv","type");
-      dup2 (saved_stdout, fileno (stdout));
+      zDup2 (saved_stdout, fileno (stdout));
       errorException (m, message->value,
 		      type->value, NULL);
       return 0;
     }
-    dup2 (saved_stdout, fileno (stdout));
-    close(saved_stdout);
+    zDup2 (saved_stdout, fileno (stdout));
+    zClose(saved_stdout);
   }
 
@@ -1331,6 +1331,6 @@
        * has been found in the zcfg and then printed on stdout
        */
-      int saved_stdout = dup (fileno (stdout));
-      dup2 (fileno (stderr), fileno (stdout));
+      int saved_stdout = zDup (fileno (stdout));
+      zDup2 (fileno (stderr), fileno (stdout));
 
       maps* imports = getMaps(m, IMPORTSERVICE);
@@ -1371,10 +1371,10 @@
         }
       fflush (stdout);
-      dup2 (saved_stdout, fileno (stdout));
+      zDup2 (saved_stdout, fileno (stdout));
 #ifdef META_DB
       fetchServicesFromDb(zooRegistry,m,doc,n,printGetCapabilitiesForProcess,1);
       close_sql(m,0);
 #endif      
-      printDocument (m, doc, getpid ());
+      printDocument (m, doc, zGetpid ());
       freeMaps (&m);
       free (m);
@@ -1466,6 +1466,6 @@
 	    char *orig = zStrdup (r_inputs->value);
 
-	    int saved_stdout = dup (fileno (stdout));
-	    dup2 (fileno (stderr), fileno (stdout));
+	    int saved_stdout = zDup (fileno (stdout));
+	    zDup2 (fileno (stderr), fileno (stdout));
 	    if (strcasecmp ("all", orig) == 0)
 	      {
@@ -1535,5 +1535,5 @@
 				sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), import->value);
 			      
-			      dup2 (saved_stdout, fileno (stdout));
+			      zDup2 (saved_stdout, fileno (stdout));
 			      errorException (m, tmp01, "InternalError", NULL);
 			      
@@ -1602,5 +1602,5 @@
 				       ("Unable to parse the ZCFG file for the following ZOO-Service: %s."),
 				       tmps);
-			    dup2 (saved_stdout, fileno (stdout));
+			    zDup2 (saved_stdout, fileno (stdout));
 			    errorException (m, tmp01, "InvalidParameterValue",
 					    "identifier");
@@ -1674,5 +1674,5 @@
 				  if (s1 == NULL)
 				    {
-				      dup2 (saved_stdout, fileno (stdout));
+				      zDup2 (saved_stdout, fileno (stdout));
 				      return errorException (m,
 							     _
@@ -1705,5 +1705,5 @@
 						 ("Unable to parse the ZCFG file: %s."),
 						 dp->d_name);
-				      dup2 (saved_stdout, fileno (stdout));
+				      zDup2 (saved_stdout, fileno (stdout));
 				      errorException (m, tmp01, "InternalError",
 						      NULL);
@@ -1757,5 +1757,5 @@
 				   _("Unable to parse the ZCFG file: %s."),
 				   buff);
-			dup2 (saved_stdout, fileno (stdout));
+			zDup2 (saved_stdout, fileno (stdout));
 			errorException (m, tmp01, "InvalidParameterValue",
 					"Identifier");
@@ -1782,7 +1782,7 @@
 	    closedir (dirp);
 	    fflush (stdout);
-	    dup2 (saved_stdout, fileno (stdout));
+	    zDup2 (saved_stdout, fileno (stdout));
 	    free (orig);
-	    printDocument (m, doc, getpid ());
+	    printDocument (m, doc, zGetpid ());
 	    freeMaps (&m);
 	    free (m);
@@ -1942,6 +1942,6 @@
       }
 
-    int saved_stdout = dup (fileno (stdout));
-    dup2 (fileno (stderr), fileno (stdout));
+    int saved_stdout = zDup (fileno (stdout));
+    zDup2 (fileno (stderr), fileno (stdout));
     t = readServiceFile (m, tmps1, &s1, r_inputs->value);
     fprintf(stderr,"%d %s %d",t,__FILE__,__LINE__);
@@ -1958,5 +1958,5 @@
     }
     fflush (stdout);
-    dup2 (saved_stdout, fileno (stdout));
+    zDup2 (saved_stdout, fileno (stdout));
     if (t < 0)
       {
@@ -1975,5 +1975,5 @@
 	return 0;
       }
-    close (saved_stdout);
+    zClose (saved_stdout);
 #ifdef META_DB
   }
@@ -2058,5 +2058,5 @@
                      2) * sizeof (char));
           sprintf (toto, "%s=%s", mapcs->name, mapcs->value);
-          putenv (toto);
+          _putenv (toto);
 #ifdef DEBUG
           fflush (stderr);
@@ -2155,5 +2155,5 @@
 
   int eres = SERVICE_STARTED;
-  int cpid = getpid ();
+  int cpid = zGetpid ();
 
   // Create a map containing a copy of the request map
@@ -2241,12 +2241,12 @@
           if (istat == 0 && file_status.st_size > 0)
             {
-	      int saved_stdout = dup (fileno (stdout));
-	      dup2 (fileno (stderr), fileno (stdout));
+	      int saved_stdout = zDup (fileno (stdout));
+	      zDup2 (fileno (stderr), fileno (stdout));
               conf_read (session_file_path, tmpSess);
               addMapsToMaps (&m, tmpSess);
               freeMaps (&tmpSess);
 	      fflush(stdout);
-	      dup2 (saved_stdout, fileno (stdout));
-	      close(saved_stdout);
+	      zDup2 (saved_stdout, fileno (stdout));
+	      zClose(saved_stdout);
             }
 	  free (tmpSess);
@@ -2271,5 +2271,14 @@
 
   _tmpMaps = createMaps("renv");
-  for (; s; ei++) {
+if(orig!=NULL)
+  for (; 
+#ifdef WIN32
+       *s;
+       s++
+#else
+       s;
+       ei++
+#endif
+       ) {
     if(strstr(s,"=")!=NULL && strlen(strstr(s,"="))>1){
       int len=strlen(s);
@@ -2285,7 +2294,5 @@
       free(tmpName);
     }
-#ifdef WIN32
-    s++;
-#else
+#ifndef WIN32
     s = *(orig+ei);
 #endif
@@ -2297,5 +2304,7 @@
   freeMaps (&_tmpMaps);
   free (_tmpMaps);
-  
+#ifdef WIN32
+  FreeEnvironmentStrings((LPCH)orig);
+#endif
   if(postRequest!=NULL)
     setMapInMaps (m, "renv", "xrequest", postRequest->value);
@@ -2389,5 +2398,5 @@
 #ifdef DEBUG
 	  fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid,
-		   getpid ());
+		   zGetpid ());
 #endif
 	  eres = SERVICE_ACCEPTED;
@@ -2417,5 +2426,5 @@
 	  bmap->content=createMap("usid",usid->value);
 	  addToMap(bmap->content,"sid",tmpm->value);
-	  addIntToMap(bmap->content,"pid",getpid());
+	  addIntToMap(bmap->content,"pid",zGetpid());
 	  
 	  // Create PID file referencing the OS process identifier
@@ -2428,5 +2437,5 @@
 
 	  f0 = freopen (fbkpid, "w+",stdout);
-	  printf("%d",getpid());
+	  printf("%d",zGetpid());
 	  fflush(stdout);
 
@@ -2460,5 +2469,5 @@
 	  fprintf (stderr, "RUN IN BACKGROUND MODE \n");
 	  fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid,
-		   getpid ());
+		   zGetpid ());
 	  fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value);
 #endif
@@ -2539,5 +2548,5 @@
 #endif
 #endif
-	    unlink (fbkpid);
+	    zUnlink (fbkpid);
 	    unhandleStatus (m);
 #ifdef RELY_ON_DB
@@ -2617,5 +2626,5 @@
 #endif
 
-  if (((int) getpid ()) != cpid || cgiSid != NULL)
+  if (((int) zGetpid ()) != cpid || cgiSid != NULL)
     {
       if (eres == SERVICE_SUCCEEDED)
@@ -2633,5 +2642,5 @@
       if(dumpBackFinalFile(m,fbkp,fbkp1)<0)
 	return -1;
-      unlink (fbkpid);
+      zUnlink (fbkpid);
       switch(eres){
       default:
@@ -2657,5 +2666,5 @@
       freeMaps(&bmap);
       free(bmap);
-      unlink (fbkp1);
+      zUnlink (fbkp1);
       unhandleStatus (m);
 #ifdef RELY_ON_DB
@@ -2676,5 +2685,5 @@
       fflush(stderr);
       fclose (stderr);
-      unlink (flog);
+      zUnlink (flog);
       free (flog);
     }
@@ -2705,5 +2714,5 @@
 #endif
 
-  if (((int) getpid ()) != cpid || cgiSid != NULL)
+  if (((int) zGetpid ()) != cpid || cgiSid != NULL)
     {
       exit (0);
