Index: /branches/prototype-v0/zoo-project/zoo-kernel/caching.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/caching.c	(revision 889)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/caching.c	(revision 890)
@@ -49,5 +49,5 @@
   for(i = 0; i < len; i++){
     if(i>0){
-      char *tmp=strdup(fresult);
+      char *tmp=zStrdup(fresult);
       sprintf(fresult,"%s%02x", tmp,result[i]);
       free(tmp);
@@ -73,5 +73,5 @@
   int bytes;
   int dlen=65536;
-  unsigned char data[dlen+1];
+  unsigned char data[65537];
   FILE *inFile = fopen (file, "rb");
   EVP_DigestInit(md5ctx, EVP_md5());
@@ -356,29 +356,69 @@
  */
 char* isInCache(maps* conf,char* request){
+  map* tmpUrl=getMapFromMaps(conf,"main","tmpUrl");
   map* tmpM=getMapFromMaps(conf,"main","cacheDir");
-  if(tmpM!=NULL){
-    if(strncasecmp(request,"file://",7)==0){
-      char* tmpStr=zStrdup(request+7);
-      fprintf(stderr,"**** %s %d %s \n",__FILE__,__LINE__,tmpStr);
-      return tmpStr;
-    }
-    else{
-      char* myRequest=getFilenameForRequest(conf,request);
-      char* md5str=getMd5(myRequest);
-      free(myRequest);
-#ifdef DEBUG
-      fprintf(stderr,"MD5STR : (%s)\n\n",md5str);
-#endif
-      char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+strlen(md5str)+6));
-      sprintf(fname,"%s/%s.zca",tmpM->value,md5str);
-      struct stat f_status;
-      int s=stat(fname, &f_status);
-      if(s==0 && f_status.st_size>0){
-	free(md5str);
-	return fname;
-      }
+  if(tmpM==NULL)
+    tmpM=getMapFromMaps(conf,"main","tmpPath");
+  if(strstr(request,tmpUrl->value)!=NULL){
+    map* tmpPath=getMapFromMaps(conf,"main","tmpPath");
+    char* tmpStr=strstr(request,tmpUrl->value);
+    char* tmpStr1=zStrdup(tmpStr+strlen(tmpUrl->value));
+    char* res=(char*) malloc((strlen(tmpPath->value)+strlen(tmpStr1)+2)*sizeof(char));
+    sprintf(res,"%s/%s",tmpPath->value,tmpStr1);
+    free(tmpStr1);
+    return res;
+  }
+#ifdef MS_FORCE_LOCAL_FILE_USE
+  map* msUrl=getMapFromMaps(conf,"main","mapserverAddress");
+  if(msUrl!=NULL && strstr(request,msUrl->value)!=NULL){
+    char *tmpStr=strstr(request,"?");
+    char *cursor=zStrdup(tmpStr+1);
+    char *token, *saveptr;
+    token = strtok_r (cursor, "&", &saveptr);
+    while(token!=NULL){
+      char *token1, *saveptr1;
+      token1 = strtok_r (token, "=", &saveptr1);
+      char *name=NULL;
+      while(token1!=NULL){
+	if(name==NULL)
+	  name=zStrdup(token1);
+	else
+	  if(strcasecmp(name,"map")==0){
+	    mapObj *myMap=msLoadMap(token1,NULL);
+	    char * res=zStrdup(myMap->layers[0]->data);
+	    free(name);
+	    free(cursor);
+	    msFreeMap(myMap);
+	    return res;
+	  }
+	token1 = strtok_r (NULL, "=", &saveptr1);
+      }
+      token = strtok_r (NULL, "&", &saveptr);
+    }
+    free(cursor);
+  }
+#endif  
+  if(strncasecmp(request,"file://",7)==0){
+    char* tmpStr=zStrdup(request+7);
+    fprintf(stderr,"**** %s %d %s \n",__FILE__,__LINE__,tmpStr);
+    return tmpStr;
+  }
+  else{
+    char* myRequest=getFilenameForRequest(conf,request);
+    char* md5str=getMd5(myRequest);
+    free(myRequest);
+#ifdef DEBUG
+    fprintf(stderr,"MD5STR : (%s)\n\n",md5str);
+#endif
+    char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+strlen(md5str)+6));
+    sprintf(fname,"%s/%s.zca",tmpM->value,md5str);
+    zStatStruct f_status;
+    int s=zStat(fname, &f_status);
+    if(s==0 && f_status.st_size>0){
       free(md5str);
-      free(fname);
-    }
+      return fname;
+    }
+    free(md5str);
+    free(fname);
   }
   return NULL;
@@ -609,5 +649,5 @@
  */
 void addRequestToQueue(maps** m,HINTERNET* hInternet,const char* url,bool req){
-  hInternet->waitingRequests[hInternet->nb]=strdup(url);
+  hInternet->waitingRequests[hInternet->nb]=zStrdup(url);
   if(req)
     InternetOpenUrl(hInternet,hInternet->waitingRequests[hInternet->nb],NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0,*m);
@@ -648,6 +688,6 @@
 
   if(cached!=NULL){
-    struct stat f_status;
-    int s=stat(cached, &f_status);
+    zStatStruct f_status;
+    int s=zStat(cached, &f_status);
     if(s==0){
       zooLock* lck=lockFile(*m,cached,'r');
@@ -668,5 +708,5 @@
     }
     cached[strlen(cached)-1]='m';
-    s=stat(cached, &f_status);
+    s=zStat(cached, &f_status);
     if(s==0){
       zooLock* lck=lockFile(*m,cached,'r');
@@ -681,5 +721,5 @@
     }
     cached[strlen(cached)-1]='p';
-    s=stat(cached, &f_status);
+    s=zStat(cached, &f_status);
     if(s==0){
       zooLock* lck=lockFile(*m,cached,'r');
@@ -728,5 +768,6 @@
     addToMap(*content,"isCached","true");
     map* tmp=getMapFromMaps(*m,"main","cacheDir");
-    if(tmp!=NULL){
+    map* tmp1=getMap((*content),"cache_file");
+    if(tmp!=NULL && tmp1==NULL){
       map *c=getMap((*content),"xlink:href");
       if(strncasecmp(c->value,"file://",7)!=0){
Index: /branches/prototype-v0/zoo-project/zoo-kernel/request_parser.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/request_parser.c	(revision 889)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/request_parser.c	(revision 890)
@@ -154,5 +154,5 @@
       addToMap(cursor->content,"base64_value",tmp->value);
       int size=0;
-      char *s=strdup(tmp->value);
+      char *s=zStrdup(tmp->value);
       free(tmp->value);
       tmp->value=base64d(s,strlen(s),&size);
@@ -174,5 +174,5 @@
 	  addToMap(cursor->content,key,tmp->value);
 	  int size=0;
-	  char *s=strdup(tmp->value);
+	  char *s=zStrdup(tmp->value);
 	  free(tmp->value);
 	  tmp->value=base64d(s,strlen(s),&size);
@@ -795,5 +795,5 @@
 #endif
 				bInternet.waitingRequests[0] =
-				  strdup ((char *) val);
+				  zStrdup ((char *) val);
 				res1 =
 				  InternetOpenUrl (&bInternet,
@@ -1806,5 +1806,5 @@
 #endif
                   targetFile =
-                    open (storageNameOnServer, O_RDWR | O_CREAT | O_TRUNC,
+                    zOpen (storageNameOnServer, O_RDWR | O_CREAT | O_TRUNC,
                           S_IRWXU | S_IRGRP | S_IROTH);
                   if (targetFile < 0)
@@ -1826,5 +1826,5 @@
                   addToMap (tmpReqI->content, "lref", storageNameOnServer);
                   cgiFormFileClose (file);
-                  close (targetFile);
+                  zClose (targetFile);
 		  free(fileNameOnServer);
 		  free(storageNameOnServer);
Index: /branches/prototype-v0/zoo-project/zoo-kernel/response_print.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/response_print.c	(revision 889)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/response_print.c	(revision 890)
@@ -79,5 +79,5 @@
     }
     if(prefix!=NULL){
-      char* tmp0=strdup(serv->name);
+      char* tmp0=zStrdup(serv->name);
       free(serv->name);
       serv->name=(char*)malloc((strlen(prefix)+strlen(tmp0)+1)*sizeof(char));
@@ -183,5 +183,5 @@
     nbNs++;
     currId=0;
-    nsName[currId]=strdup(name);
+    nsName[currId]=zStrdup(name);
     usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name);
   }else{
@@ -190,5 +190,5 @@
       nbNs++;
       currId=nbNs-1;
-      nsName[currId]=strdup(name);
+      nsName[currId]=zStrdup(name);
       usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name);
     }
@@ -255,12 +255,12 @@
   if(soap!=NULL && strcasecmp(soap->value,"true")==0){
     int lNbNs=nbNs;
-    nsName[lNbNs]=strdup("soap");
+    nsName[lNbNs]=zStrdup("soap");
     usedNs[lNbNs]=xmlNewNs(NULL,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap");
     nbNs++;
     xmlNodePtr nr = xmlNewNode(usedNs[lNbNs], BAD_CAST "Envelope");
-    nsName[nbNs]=strdup("soap");
+    nsName[nbNs]=zStrdup("soap");
     usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap");
     nbNs++;
-    nsName[nbNs]=strdup("xsi");
+    nsName[nbNs]=zStrdup("xsi");
     usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
     nbNs++;
@@ -594,11 +594,11 @@
     map* tmp=getMap(toto1->content,"serverAddress");
     if(tmp!=NULL){
-      SERVICE_URL = strdup(tmp->value);
+      SERVICE_URL = zStrdup(tmp->value);
     }
     else
-      SERVICE_URL = strdup("not_defined");
+      SERVICE_URL = zStrdup("not_defined");
   }
   else
-    SERVICE_URL = strdup("not_defined");
+    SERVICE_URL = zStrdup("not_defined");
 
   for(j=0;j<nbSupportedRequests;j++){
@@ -1269,5 +1269,5 @@
 	    while(token!=NULL){
 	      nc7 = xmlNewNode(ns_ows, BAD_CAST "Value");
-	      char *tmps=strdup(token);
+	      char *tmps=zStrdup(token);
 	      tmps[strlen(tmps)]=0;
 	      nc8 = xmlNewText(BAD_CAST tmps);
@@ -1746,5 +1746,5 @@
       while(cursor!=NULL){
 	elements* ccursor=cursor;
-	char* tmp=strdup(ccursor->name);
+	char* tmp=zStrdup(ccursor->name);
 	free(ccursor->name);
 	ccursor->name=(char*)malloc((strlen(tmp)+strlen(e->name)+2)*sizeof(char));
@@ -2671,5 +2671,5 @@
       else
 	sprintf(session_file_path,"%s",strstr(_tmp->value,"=")+1);
-      sessId=strdup(session_file_path);
+      sessId=zStrdup(session_file_path);
     }else{
       maps* t=getMaps(m,"senv");
@@ -2677,5 +2677,5 @@
       while(p!=NULL){
 	if(strstr(p->name,"ID")!=NULL){
-	  sessId=strdup(p->value);
+	  sessId=zStrdup(p->value);
 	  break;
 	}
Index: /branches/prototype-v0/zoo-project/zoo-kernel/server_internal.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/server_internal.c	(revision 889)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/server_internal.c	(revision 890)
@@ -367,4 +367,5 @@
  */
 void readGeneratedFile(maps* m,map* content,char* filename){
+  char rsize[1024];
   FILE * file=fopen(filename,"rb");
   if(file==NULL){
@@ -374,7 +375,6 @@
   fseek(file, 0, SEEK_END);
   long count = ftell(file);
+  sprintf(rsize,"%lld",ftell(file));
   rewind(file);
-  struct stat file_status; 
-  stat(filename, &file_status);
   if(getMap(content,"storage")==NULL){
     map* tmpMap1=getMap(content,"value");
@@ -391,7 +391,5 @@
     tmpMap1->value[count]=0;
   }
-  fclose(file);
-  char rsize[1000];
-  sprintf(rsize,"%ld",count);
+  fclose(file);  
   addToMap(content,"size",rsize);
 }
@@ -760,5 +758,5 @@
 	      map* tmpV=getMap(tmpI->content,"value");
 	      if(tmpV!=NULL){
-		char *tmpVS=strdup(tmpV->value);
+		char *tmpVS=zStrdup(tmpV->value);
 		map* tmp=parseBoundingBox(tmpVS);
 		free(tmpVS);
@@ -797,5 +795,5 @@
 	      map* length=getMap(tmpMaps->content,"length");
 	      int i;
-	      char *tcn=strdup(tmpContent->name);
+	      char *tcn=zStrdup(tmpContent->name);
 	      for(i=1;i<atoi(length->value);i++){
 #ifdef DEBUG
@@ -1007,6 +1005,6 @@
 	  char* tmpStr=_getStatus(conf,pid);
 	  if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){
-	    char *tmpStr1=strdup(tmpStr);
-	    char *tmpStr0=strdup(strstr(tmpStr,"|")+1);
+	    char *tmpStr1=zStrdup(tmpStr);
+	    char *tmpStr0=zStrdup(strstr(tmpStr,"|")+1);
 	    free(tmpStr);
 	    tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0';
@@ -1043,6 +1041,6 @@
 	  char* tmpStr=_getStatus(conf,pid);
 	  if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){
-	    char *tmpStr1=strdup(tmpStr);
-	    char *tmpStr0=strdup(strstr(tmpStr,"|")+1);
+	    char *tmpStr1=zStrdup(tmpStr);
+	    char *tmpStr0=zStrdup(strstr(tmpStr,"|")+1);
 	    free(tmpStr);
 	    tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0';
Index: /branches/prototype-v0/zoo-project/zoo-kernel/service.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/service.c	(revision 889)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/service.c	(revision 890)
@@ -759,5 +759,7 @@
   map* toload=getMap(in,"to_load");
   if(toload!=NULL && strcasecmp(toload->value,"false")==0){
+#ifdef DEBUG
     fprintf(stderr,"NO LOAD %s %d \n",__FILE__,__LINE__);
+#endif
     return ;
   }
Index: /branches/prototype-v0/zoo-project/zoo-kernel/service.h
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/service.h	(revision 889)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/service.h	(revision 890)
@@ -43,5 +43,10 @@
 #define zStrdup _strdup
 #define zMkdir _mkdir
+#define zGetpid _getpid
 #define zOpen _open
+#define zClose _close
+#define zUnlink _unlink
+#define zDup _dup
+#define zDup2 _dup2
 #define zWrite _write
 #define zSleep Sleep
@@ -65,4 +70,7 @@
 }
 
+#define zStatStruct struct _stati64
+#define zStat _stati64
+
 #else
 /**
@@ -78,4 +86,20 @@
  */
 #define zOpen open
+/**
+ * The crossplatform close alias
+ */
+#define zClose close
+/**
+ * The crossplatform unlink alias
+ */
+#define zUnlink unlink
+/**
+ * The crossplatform dup alias
+ */
+#define zDup dup
+/**
+ * The crossplatform dup2 alias
+ */
+#define zDup2 dup2
 /**
  * The crossplatform write alias
@@ -97,4 +121,12 @@
  */
 #define ztimeval timeval
+/**
+ * The crossplatform getpid alias
+ */
+#define zGetpid getpid
+
+#define zStatStruct struct stat64
+#define zStat stat64
+
 #endif 
 
Index: /branches/prototype-v0/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/service_internal.c	(revision 889)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/service_internal.c	(revision 890)
@@ -31,146 +31,57 @@
 #include "service_internal.h"
 
-#ifndef TRUE
-#define TRUE 1
-#endif
-#ifndef FALSE
-#define FALSE -1
-#endif
-
 #ifdef WIN32
-// cf. https://stackoverflow.com/questions/3168504/lockfileex-read-write-upgrade-downgrade
-// only works for (SEEK_SET, start=0, len=0) file locking.
+// ref. https://docs.microsoft.com/en-us/windows/desktop/fileio/locking-and-unlocking-byte-ranges-in-files
 __inline int fcntl(int fd, int cmd, ...)
 {
-    va_list a;
-    va_start(a, cmd);
-    switch(cmd)
+  va_list a;
+  va_start(a, cmd);
+  switch(cmd)
     {
     case F_SETLK:
-        {
-            struct flock *l = va_arg(a, struct flock*);
-            switch(l->l_type)
-            {
-            case F_RDLCK:
-                {
-                    LPOVERLAPPED o = { 0 };
-                    HANDLE h = (HANDLE)_get_osfhandle(fd);
-                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
-                    {
-                        _set_errno(ENOTSUP);
-                        return -1;
-                    }
-                    if (!LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY, 0, 0, 1, o)) // read lock
-                    {
-                        unsigned long x = GetLastError();
-                        _set_errno(GetLastError() == ERROR_LOCK_VIOLATION ? EAGAIN : EBADF);
-                        return -1;
-                    }
-                    UnlockFile(h, 0, 0, 1, 1); // write lock
-                }
-                break;
-            case F_WRLCK:
-                {
-                    LPOVERLAPPED o = { 0 };
-                    HANDLE h = (HANDLE)_get_osfhandle(fd);
-                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
-                    {
-                        _set_errno(ENOTSUP);
-                        return -1;
-                    }
-                    if (!LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY|LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 1, o)) // write lock
-                    {
-                        unsigned long x = GetLastError();
-                        _set_errno(GetLastError() == ERROR_LOCK_VIOLATION ? EAGAIN : EBADF);
-                        return -1;
-                    }
-                    UnlockFile(h, 0, 0, 0, 1); // read lock
-                }
-                break;
-            case F_UNLCK:
-                {
-                    HANDLE h = (HANDLE)_get_osfhandle(fd);
-                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
-                    {
-                        _set_errno(ENOTSUP);
-                        return -1;
-                    }
-                    UnlockFile(h, 0, 0, 0, 1); // read lock
-                    UnlockFile(h, 0, 0, 1, 1); // write lock
-                }
-                break;
-            default:
-                _set_errno(ENOTSUP);
-                return -1;
-            }
-        }
-        break;
-    case F_SETLKW:
-        {
-            struct flock *l = va_arg(a, struct flock*);
-            switch(l->l_type)
-            {
-            case F_RDLCK:
-                {
-                    LPOVERLAPPED o = { 0 };
-                    HANDLE h = (HANDLE)_get_osfhandle(fd);
-                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
-                    {
-                        _set_errno(ENOTSUP);
-                        return -1;
-                    }
-                    if(!LockFileEx(h, 0, 0, 0, 1, o)) // read lock
-                    {
-                        unsigned long x = GetLastError();
-                        return -1;
-                    }
-                    UnlockFile(h, 0, 0, 1, 1); // write lock
-                }
-                break;
-            case F_WRLCK:
-                {
-                    LPOVERLAPPED o = { 0 };
-                    HANDLE h = (HANDLE)_get_osfhandle(fd);
-                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
-                    {
-                        _set_errno(ENOTSUP);
-                        return -1;
-                    }
-                    if (!LockFileEx(h, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 1, o)) // write lock
-                    {
-                        unsigned long x = GetLastError();
-                        return -1;
-                    }
-                    UnlockFile(h, 0, 0, 0, 1); // read lock
-                }
-                break;
-            case F_UNLCK:
-                {
-                    flock *l = va_arg(a, flock*);
-                    HANDLE h = (HANDLE)_get_osfhandle(fd);
-                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
-                    {
-                        _set_errno(ENOTSUP);
-                        return -1;
-                    }
-                    UnlockFile(h, 0, 0, 0, 1); // read lock
-                    UnlockFile(h, 0, 0, 1, 1); // write lock
-                }
-                break;
-            default:
-                _set_errno(ENOTSUP);
-                return -1;
-            }
-        }
-        break;
+      {
+	HANDLE h = (HANDLE)_get_osfhandle(fd);
+	struct flock* l= va_arg(a, struct flock*);
+	OVERLAPPED sOverlapped;
+	sOverlapped.Offset = 0;
+	sOverlapped.OffsetHigh = 0;
+	switch(l->l_type)
+	  {
+	  case F_RDLCK:
+	    {
+	      if (!LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY, 0, l->l_len, 0, &sOverlapped)) 
+		{
+		  _set_errno(GetLastError() == ERROR_LOCK_VIOLATION ? EAGAIN : EBADF);
+		  return -1;
+		}
+	    }
+	    break;
+	  case F_WRLCK:
+	    {
+	      if (!LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY|LOCKFILE_EXCLUSIVE_LOCK, 0, l->l_len, 0, &sOverlapped))
+		{
+		  _set_errno(GetLastError() == ERROR_LOCK_VIOLATION ? EAGAIN : EBADF);
+		  return -1;
+		}
+	    }
+	    break;
+	  case F_UNLCK:
+	    {
+	      UnlockFileEx(h, 0, l->l_len, 0, &sOverlapped);
+	    }
+	    break;
+	  default:
+	    _set_errno(ENOTSUP);
+	    return -1;
+	  }
+      }
+      break;
     default:
-        _set_errno(ENOTSUP);
-        return -1;
-    }
-
-    return 0;
-}
-#endif
-
+      _set_errno(ENOTSUP);
+      return -1;
+    }
+  return 0;
+}
+#endif
 #define ERROR_MSG_MAX_LENGTH 1024
 
@@ -197,6 +108,8 @@
     if(itn<ZOO_LOCK_MAX_RETRY){
       itn++;
-      fprintf(stderr,"(%d) Wait for write lock on %s, tried %d times (sleep) ... \n",getpid(),myLock->filename,itn);
+#ifdef DEBUG
+      fprintf(stderr,"(%d) Wait for write lock on %s, tried %d times (sleep) ... \n",zGetpid(),myLock->filename,itn);
       fflush(stderr);
+#endif
       zSleep(5);
       free(myLock->filename);
@@ -216,5 +129,5 @@
     myLock->lockfile=fopen(myLock->filename,local_mode);
     char tmp[512];
-    sprintf(tmp,"%d",getpid());
+    sprintf(tmp,"%d",zGetpid());
     if(myLock->lockfile==NULL){
       myLock->lockfile=fopen(myLock->filename,"w+");
@@ -249,6 +162,8 @@
 	    return NULL;
 	  }
-	  fprintf(stderr,"(%d) Wait for lock on  %s, tried %d times ... \n",getpid(),myLock->filename,cnt);
+#ifdef DEBUG
+	  fprintf(stderr,"(%d) Wait for lock on  %s, tried %d times ... \n",zGetpid(),myLock->filename,cnt);
 	  fflush(stderr);
+#endif
 	  zSleep(1);
 	  cnt++;
@@ -265,5 +180,7 @@
 	else
 	  tmp="The system has run out of file lock resources; there are already too many file locks in place.";
+#ifdef DEBUG
       fprintf(stderr,"Unable to get the lock on %s due to the following error: %s\n",myLock->filename,tmp);
+#endif
       return NULL;
     }
@@ -285,10 +202,14 @@
     if(res==-1)
       return res;
+    fclose(s->lockfile);
+#ifndef WIN32
     // Check if there is any process locking a file and delete the lock if not.
     s->lock.l_type = F_WRLCK;
     if(fcntl(fileno(s->lockfile), F_GETLK, &s->lock)!=-1 && s->lock.l_type == F_UNLCK){
-      unlink(s->filename);
-    }
-    fclose(s->lockfile);
+#endif
+      zUnlink(s->filename);
+#ifndef WIN32
+    }
+#endif
     free(s->filename);
     free(s);
@@ -507,5 +428,5 @@
 		     * sizeof (char));
   sprintf (fbkpid, "%s/%s.status", r_inputs->value, usid->value);
-  unlink(fbkpid);
+  zUnlink(fbkpid);
   free(fbkpid);
 }
Index: /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c	(revision 889)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c	(revision 890)
@@ -1162,5 +1162,8 @@
       char tmpMm[100],tmpMp[100];
       sprintf(tmpMm,"%.3f %.3f",pdfMin,pdfMax);
-      sprintf(tmpMp,"SCALE_%d=%.3f,%.3f",iBand+1,pdfMean-(2*pdfStdDev),pdfMean+(2*pdfStdDev));
+      if(pdfMin!=pdfMax)
+	sprintf(tmpMp,"SCALE_%d=%.3f,%.3f",iBand+1,pdfMean-(2*pdfStdDev),pdfMean+(2*pdfStdDev));
+      /*else
+	sprintf(tmpMp,"SCALE_%d=%.3f,%.3f",iBand+1,pdfMin,pdfMax);*/
       char tmpI[31];      
       sprintf(tmpI,"%s_interval",tmpN);
Index: /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_python.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_python.c	(revision 889)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_python.c	(revision 890)
@@ -201,5 +201,5 @@
   char* toto=(char*)malloc((strlen(pythonpath)+12)*sizeof(char));
   sprintf(toto,"PYTHONPATH=%s",pythonpath);
-  putenv(toto);
+  _putenv(toto);
   free(toto);
 #endif
Index: /branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c	(revision 889)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c	(revision 890)
@@ -419,5 +419,5 @@
     for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){
       if( poFeature->IsFieldSet( iField ) ){
-	tmp1=strdup(poFeature->GetFieldAsString( iField ));
+	tmp1=zStrdup(poFeature->GetFieldAsString( iField ));
       }
       else
@@ -463,5 +463,5 @@
 	for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){
 	  if( poFeature->IsFieldSet( iField ) ){
-	    tmp1=strdup(poFeature->GetFieldAsString( iField ));
+	    tmp1=zStrdup(poFeature->GetFieldAsString( iField ));
 	    hasRes=1;
 	  }
Index: /branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c	(revision 889)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c	(revision 890)
@@ -161,5 +161,5 @@
     if (hpc_public_key != NULL) {
       public_key = hpc_public_key->value;
-      private_key = strdup(hpc_public_key->value);
+      private_key = zStrdup(hpc_public_key->value);
       private_key[strlen(public_key)-4]=0;
     }else{
Index: /branches/prototype-v0/zoo-project/zoo-kernel/ulinet.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/ulinet.c	(revision 889)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/ulinet.c	(revision 890)
@@ -238,5 +238,5 @@
   HINTERNET ret;
   ret.handle=curl_multi_init();
-  ret.agent=strdup(lpszAgent);
+  ret.agent=zStrdup(lpszAgent);
   ret.nb=0;
   ret.waitingRequests[ret.nb] = NULL;
@@ -269,20 +269,28 @@
 char* getProvenance(maps* conf,const char* url){
   map* sharedCache=getMapFromMaps(conf,"security","shared");
+  char *res="OTHER";
+  char *paths[2]={
+    "mapserverAddress",
+    "tmpUrl"
+  };
   if(sharedCache!=NULL){
-    char *res=NULL;
     char *hosts=sharedCache->value;
     char *curs=strtok(hosts,",");
     while(curs!=NULL){
-      if(strstr(url,curs)==NULL)
-	res="OTHER";
-      else{
-	res="SHARED";
-	return res;
+      if(strstr(url,curs)==NULL){
+	return "SHARED";
       }
       curs=strtok(NULL,",");
     }
-    return res;
-  }
-  return "OTHER";
+  }
+  for(int i=0;i<2;i++){
+    sharedCache=getMapFromMaps(conf,"main",paths[i]);
+    if(sharedCache!=NULL){
+      if(strstr(url,sharedCache->value)!=NULL){
+	return "LOCAL";
+      }
+    }
+  }
+  return res;
 }
 
@@ -482,5 +490,5 @@
 #endif
 
-  if(memUse!=NULL && strcasecmp(memUse->value,"load")==0)
+  if(memUse==NULL || strcasecmp(memuse->value,"load")==0)
     ldwFlags=INTERNET_FLAG_NO_CACHE_WRITE;
   
@@ -502,7 +510,7 @@
 	sprintf(filename,"/tmp/ZOO_Cache%s", tmpUuid);
       else
-	sprintf(filename,"/%s/ZOO_Cache%s", tmpPath->value,tmpUuid);
+	sprintf(filename,"%s/ZOO_Cache%s", tmpPath->value,tmpUuid);
       free(tmpUuid);
-      hInternet->ihandle[hInternet->nb].filename=strdup(filename);
+      hInternet->ihandle[hInternet->nb].filename=zStrdup(filename);
       hInternet->ihandle[hInternet->nb].file=fopen(hInternet->ihandle[hInternet->nb].filename,"w+");
       hInternet->ihandle[hInternet->nb].hasCacheFile=1;
@@ -524,5 +532,5 @@
     curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_VERBOSE,1);
 #endif
-    hInternet->ihandle[hInternet->nb].post=strdup(lpszHeaders);
+    hInternet->ihandle[hInternet->nb].post=zStrdup(lpszHeaders);
     curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_POSTFIELDS,hInternet->ihandle[hInternet->nb].post);
     curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_POSTFIELDSIZE,(long)dwHeadersLength);
@@ -602,5 +610,5 @@
     curl_easy_getinfo(hInternet->ihandle[i].handle,CURLINFO_CONTENT_TYPE,&tmp);
     if(tmp!=NULL)
-      hInternet->ihandle[i].mimeType=strdup(tmp);
+      hInternet->ihandle[i].mimeType=zStrdup(tmp);
     curl_easy_getinfo(hInternet->ihandle[i].handle,CURLINFO_RESPONSE_CODE,&hInternet->ihandle[i].code);
     curl_multi_remove_handle(hInternet->handle, hInternet->ihandle[i].handle);
@@ -618,5 +626,5 @@
  */
 int freeCookieList(HINTERNET hInternet){
-  hInternet.ihandle[hInternet.nb].cookie=strdup("");
+  hInternet.ihandle[hInternet.nb].cookie=zStrdup("");
 #ifndef TIGER
   curl_easy_setopt(hInternet.ihandle[hInternet.nb].handle, CURLOPT_COOKIELIST, "ALL");
Index: /branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 889)
+++ /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);
