Re: I port polipo to VS2008 under Win32

honglei junan <[email protected]>
Newsgroups gmane.comp.web.polipo.user
Message-ID <[email protected]>
Many thanks for your advises, I've learn a lot.

>
> Please do not dispatch on #ifdef WIN32, as this will break compilation
> under Cygwin.
>

I've test it under Cygwin ,it works fine. There is not macro WIN32 under
Cygwin.could you give me more detail's?

>
> >>Please do not use CC++-style comments, they break compilation under SYSV.
>

 i have changed in the new patch.

>
> Please do not change the behaviour of Polipo -- if you want to make an
> incompatible change, please make it into a separate patch and discuss it
> on this list.  There are good reasons why Polipo doesn't allow relative
> paths in the web server's root directory, and why it doesn't silently
> create the directory when it doesn't exist -- doing otherwise raises
> some significant security issues.
>
 I've changed in the new patch. thanks,i will remember it.

>
> Please do not include unrelated changes in your portability patch, send
> a separate patch instead -- I've noticed the change to the ETag parser,
> and the typo fix in object.c which don't belong in this patch, since
> they are not specific to Windows.
>
 I've accepted in the new patch.

>
> The change to mktime_gmt is wrong -- an empty TZ variable is different
> from no TZ variable at all.
>
yes,but an empty TZ  variable will cause crash under VC2008/2010 when using
sprintf_a. so i rewrite a new one for VC:

 time_t
mktime_gmt(struct tm *tm)
{
    time_t t;
    static int bias = -1;
    if(bias == -1)
    {
        time_t   curr   =   time(NULL);
        struct   tm   *   p   = gmtime(&curr);
        time_t   gmtcurr     =   mktime(p);
        bias = curr-gmtcurr ;
    }
    t = mktime(tm)+bias;
    / * printf("mktime_gmt2: %d\n", t ); */
    return t;
}

>
> Please remove the stdint.h emulation file.  Instead, you should just
> typedef my_uint32_t in md5import.c.
>
 I've changed in the new patch.

>
> Please do not unconditionally remove the compatibility macro for va_copy.
>
> What's Iphlpapi.lib?  Will it break compilation under mingw?
>
 I've remove dependency on  Iphlpapi.lib.it will not break compilation under
mingw+win32api.

i add the new port patch as an attach file.now it can be compiled under
Mingw+MSYS/VC2008/VC2010/Cygwin, all work fine .

------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev

_______________________________________________
Polipo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/polipo-users
vcpolipo.patch (application/octet-stream, 36.3 KB)
diff -ruNa polipo-harden-test/Makefile polipoo/Makefile
--- polipo-harden-test/Makefile	2009-12-12 07:39:48 +0800
+++ polipoo/Makefile	2010-01-22 18:38:41 +0800
@@ -11,7 +11,7 @@
 
 # To compile with GCC:
 
-# CC = gcc
+CC = gcc
 # CDEBUGFLAGS = -Os -g -Wall -std=gnu99
 CDEBUGFLAGS = -Os -g -Wall -Wextra
 # CDEBUGFLAGS = -Os -Wall
@@ -47,8 +47,8 @@
 
 # On mingw, you need
 
-# EXE=.exe
-# LDLIBS = -lwsock32
+EXE=.exe
+LDLIBS = -lwsock32
 
 FILE_DEFINES = -DLOCAL_ROOT=\"$(LOCAL_ROOT)/\" \
                -DDISK_CACHE_ROOT=\"$(DISK_CACHE_ROOT)/\"
diff -ruNa polipo-harden-test/chunk.c polipoo/chunk.c
--- polipo-harden-test/chunk.c	2009-12-12 07:39:48 +0800
+++ polipoo/chunk.c	2010-01-22 14:48:40 +0800
@@ -184,7 +184,7 @@
 }
 #else
 
-#ifdef MINGW
+#ifdef WIN32 /*MINGW*/
 #define MAP_FAILED NULL
 #define getpagesize() (64 * 1024)
 static void *
diff -ruNa polipo-harden-test/dirent.c polipoo/dirent.c
--- polipo-harden-test/dirent.c	1970-01-01 08:00:00 +0800
+++ polipoo/dirent.c	2010-01-22 14:58:22 +0800
@@ -0,0 +1,214 @@
+/** dirent.c: emulates POSIX directory readin functions: opendir(), readdir(),
+ *           etc. under Win32   
+ */
+
+#include <windows.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <malloc.h>
+#include "dirent.h"
+
+struct DIR
+{
+  HANDLE hFind;
+  char   szDirName[1];
+};
+
+/*--------------------------------------------------------------------------
+ Name         countslashes
+
+ Description  
+--------------------------------------------------------------------------*/
+
+static int countslashes(const char *dirname)
+{
+  const char *p;
+  int n;
+
+  n = 0;
+  p = dirname;
+
+  while (*p)
+    if (*p++ == '\\')
+      ++n;
+
+  return n;
+}
+
+/*--------------------------------------------------------------------------
+* Name         opendir
+*
+* Description  
+--------------------------------------------------------------------------*/
+DIR * opendir ( const char * dirname )
+{
+  DIR * dir;
+  int   nameLen;
+  struct stat st;
+  unsigned char flagNetPath;
+  unsigned char flagRootOnly;
+
+  if (dirname == NULL || *dirname == 0)
+  {
+    errno = EINVAL;
+    return NULL;
+  }
+
+  nameLen = strlen( dirname );
+  flagNetPath = 0;
+  if (dirname[0] == '\\' && dirname[1] == '\\')
+    flagNetPath = 1;
+  /* we have to check for root-dir-only case */
+  flagRootOnly = 0;
+  if (flagNetPath)
+  {
+    if (countslashes(&dirname[2]) == 2)  /* only the separation for server_name and the root*/
+      flagRootOnly = 1;
+  }
+
+  if ((dirname[nameLen-1] == '/' || dirname[nameLen-1] == '\\') &&
+      (nameLen != 3 || dirname[1] != ':') && nameLen != 1 && !flagRootOnly)
+  {
+    char * t = alloca( nameLen );
+    memcpy( t, dirname, nameLen );
+    t[nameLen-1] = 0;
+    dirname = t;
+    --nameLen;
+  }
+
+  if (stat( dirname, &st ))
+    return NULL;
+
+  if ((st.st_mode & S_IFDIR) == 0)
+  {
+    /* this is not a DIR */
+    errno = ENOTDIR;
+    return NULL;
+  }
+
+  if ((dir = malloc( sizeof( DIR ) + nameLen + 2 )) == NULL)
+  {
+    errno = ENOMEM;
+    return NULL;
+  }
+
+  dir->hFind = INVALID_HANDLE_VALUE;
+
+  memcpy( dir->szDirName, dirname, nameLen );
+  if (nameLen && dirname[nameLen-1] != ':' && dirname[nameLen-1] != '\\' &&
+      dirname[nameLen-1] != '/')
+  {
+    dir->szDirName[nameLen++] = '\\';
+  }
+  dir->szDirName[nameLen] = '*';
+  dir->szDirName[nameLen+1] = 0;
+
+  return dir;
+};
+
+/*--------------------------------------------------------------------------
+ * Name         readdir
+ *
+ * Description  
+--------------------------------------------------------------------------*/
+struct dirent * readdir ( DIR * dir )
+{
+  static WIN32_FIND_DATA fData;
+
+  if (dir == NULL)
+  {
+    errno = EBADF;
+    return NULL;
+  }
+
+  do
+  {
+    int ok = 1;
+
+    if (dir->hFind == INVALID_HANDLE_VALUE)
+    {
+      dir->hFind = FindFirstFile( dir->szDirName, &fData );
+      if (dir->hFind == INVALID_HANDLE_VALUE)
+        ok = 0;
+    }
+    else
+    if (!FindNextFile( dir->hFind, &fData ))
+      ok = 0;
+
+    if (!ok)
+    {
+      switch (GetLastError())
+      {
+        case ERROR_NO_MORE_FILES:
+        case ERROR_FILE_NOT_FOUND:
+        case ERROR_PATH_NOT_FOUND:
+          errno = ENOENT;
+          break;
+
+        case ERROR_NOT_ENOUGH_MEMORY:
+          errno = ENOMEM;
+          break;
+
+        default:
+          errno = EINVAL;
+          break;
+      }
+      return NULL;
+    }
+  }
+  while (fData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN);
+
+  return (struct dirent *)&fData.cFileName;
+};
+
+/*--------------------------------------------------------------------------
+ * Name         closedir
+--------------------------------------------------------------------------*/
+int closedir ( DIR * dir )
+{
+  if (dir == NULL)
+  {
+    errno = EBADF;
+    return -1;
+  }
+  if (dir->hFind != INVALID_HANDLE_VALUE)
+    FindClose( dir->hFind );
+  free( dir );
+  return 0;
+};
+
+/*--------------------------------------------------------------------------
+ Name         rewinddir
+ Description  
+--------------------------------------------------------------------------*/
+void rewinddir ( DIR * dir )
+{
+  if (dir)
+  {
+    if (dir->hFind != INVALID_HANDLE_VALUE)
+      FindClose( dir->hFind );
+    dir->hFind = INVALID_HANDLE_VALUE;
+  }
+};
+
+/*
+int main ( int argc, char ** argv )
+{
+  DIR * dir;
+  struct dirent * de;
+  char * arg;
+
+  arg = argc > 1 ? argv[1] : ".";
+
+  if (dir = opendir( arg ))
+  {
+    while (de = readdir( dir ))
+    {
+      puts( de->d_name );
+    }
+    closedir( dir );
+  }
+  return 0;
+};
+*/
diff -ruNa polipo-harden-test/dirent.h polipoo/dirent.h
--- polipo-harden-test/dirent.h	1970-01-01 08:00:00 +0800
+++ polipoo/dirent.h	2010-01-22 15:02:52 +0800
@@ -0,0 +1,22 @@
+
+#ifndef DIRENT_H
+#define DIRENT_H
+
+#include <stdio.h>
+
+struct dirent
+{
+	long		d_ino;		/* Always zero. */
+	unsigned short	d_reclen;	/* Always zero. */
+	unsigned short	d_namlen;	/* Length of name in d_name. */
+	char		d_name[FILENAME_MAX+1]; /* File name. */
+};
+
+typedef struct DIR DIR;
+
+DIR * opendir ( const char * dirname );
+struct dirent * readdir ( DIR * dir );
+int closedir ( DIR * dir );
+void rewinddir ( DIR * dir );
+
+#endif /* DIRENT_H */
diff -ruNa polipo-harden-test/event.h polipoo/event.h
--- polipo-harden-test/event.h	2009-12-12 07:39:48 +0800
+++ polipoo/event.h	2010-01-12 20:55:05 +0800
@@ -52,7 +52,10 @@
 
 void initEvents(void);
 void uninitEvents(void);
+
+#ifdef HAVE_FORK
 void interestingSignals(sigset_t *ss);
+#endif
 
 TimeEventHandlerPtr scheduleTimeEvent(int seconds,
                                       int (*handler)(TimeEventHandlerPtr),
diff -ruNa polipo-harden-test/fts_compat.c polipoo/fts_compat.c
--- polipo-harden-test/fts_compat.c	2009-12-12 07:39:48 +0800
+++ polipoo/fts_compat.c	2010-01-22 14:48:40 +0800
@@ -25,13 +25,23 @@
 
 #include <stdlib.h>
 #include <errno.h>
-#include <unistd.h>
+
+#ifdef _MSC_VER
+ #include "polipo.h"
+ #include <direct.h>
+#else
+ #include <unistd.h>
+ #include <dirent.h>
+#endif
+
 #include <sys/types.h>
-#include <dirent.h>
+
 #include <sys/stat.h>
 #include <errno.h>
 #include <string.h>
 
+
+
 #include "fts_compat.h"
 
 static char *
@@ -127,7 +137,7 @@
 /*
  * Make the directory identified by the argument the current directory.
  */
-#ifdef MINGW
+#ifdef WIN32 /*MINGW*/
 int
 change_to_dir(DIR *dir)
 {
@@ -281,13 +291,13 @@
     name = dirent->d_name;
 
  again2:
-    rc = stat(name, &fts->stat);
+    rc = stat(name, &fts->istat);
     if(rc < 0) {
         fts->ftsent.fts_info = FTS_NS;
         goto error2;
     }
 
-    if(S_ISDIR(fts->stat.st_mode)) {
+    if(S_ISDIR(fts->istat.st_mode)) {
         char *newcwd;
         DIR *dir;
 
@@ -318,11 +328,11 @@
         fts->depth++;
         fts->dir[fts->depth] = dir;
         goto done;
-    } else if(S_ISREG(fts->stat.st_mode)) {
+    } else if(S_ISREG(fts->istat.st_mode)) {
         fts->ftsent.fts_info = FTS_F;
         goto done;
 #ifdef S_ISLNK
-    } else if(S_ISLNK(fts->stat.st_mode)) {
+    } else if(S_ISLNK(fts->istat.st_mode)) {
         int rc;
         rc = readlink(name, buf, 1024);
         if(rc < 0)
@@ -350,7 +360,7 @@
     fts->ftsent.fts_path = mkfilename(fts->cwd, name);
     if(fts->ftsent.fts_path == NULL) goto error;
     fts->ftsent.fts_accpath = name;
-    fts->ftsent.fts_statp = &fts->stat;
+    fts->ftsent.fts_statp = &fts->istat;
     return &fts->ftsent;
 
  error:
diff -ruNa polipo-harden-test/fts_compat.h polipoo/fts_compat.h
--- polipo-harden-test/fts_compat.h	2009-12-12 07:39:48 +0800
+++ polipoo/fts_compat.h	2010-01-22 15:03:06 +0800
@@ -50,12 +50,18 @@
 
 typedef struct _FTSENT FTSENT;
 
+#ifdef _MSC_VER
+#include "dirent.h"
+#else
+#include <dirent.h>
+#endif
+
 struct _FTS {
     int depth;
     DIR *dir[FTS_MAX_DEPTH];
     char *cwd0, *cwd;
     struct _FTSENT ftsent;
-    struct stat stat;
+	struct stat istat;  
     char *dname;
 };
 
diff -ruNa polipo-harden-test/io.c polipoo/io.c
--- polipo-harden-test/io.c	2009-12-12 07:39:48 +0800
+++ polipoo/io.c	2010-01-22 14:48:40 +0800
@@ -801,8 +801,8 @@
 int
 setNonblocking(int fd, int nonblocking)
 {
-#ifdef MINGW
-    return mingw_setnonblocking(fd, nonblocking);
+#ifdef WIN32 /*MINGW*/
+    return win32_setnonblocking(fd, nonblocking);
 #else
     int rc;
     rc = fcntl(fd, F_GETFL, 0);
diff -ruNa polipo-harden-test/local.h polipoo/local.h
--- polipo-harden-test/local.h	2009-12-12 07:39:48 +0800
+++ polipoo/local.h	2010-01-12 16:13:56 +0800
@@ -20,6 +20,11 @@
 THE SOFTWARE.
 */
 
+#ifdef _MSC_VER
+  typedef int pid_t;
+#endif
+
+
 typedef struct _SpecialRequest {
     ObjectPtr object;
     int fd;
diff -ruNa polipo-harden-test/log.c polipoo/log.c
--- polipo-harden-test/log.c	2009-12-12 07:39:48 +0800
+++ polipoo/log.c	2010-01-13 20:47:45 +0800
@@ -304,10 +304,6 @@
     }
 }
 
-#ifndef va_copy
-#define va_copy(a, b) do { a = b; } while(0)
-#endif
-
 static void
 accumulateSyslogV(int type, const char *f, va_list args)
 {
diff -ruNa polipo-harden-test/main.c polipoo/main.c
--- polipo-harden-test/main.c	2009-12-12 07:39:48 +0800
+++ polipoo/main.c	2010-01-22 11:42:51 +0800
@@ -38,6 +38,13 @@
     fprintf(stderr, "  -c: specify the configuration file to use.\n");
 }
 
+#ifndef WIN32
+  #define DEFAULT_CONFIG_PATH "/etc/polipo/config"
+#else
+  #define  DEFAULT_CONFIG_PATH "./config"
+#endif
+
+
 int
 main(int argc, char **argv)
 {
@@ -107,8 +114,8 @@
     }
 
     if(configFile == NULL) {
-        if(access("/etc/polipo/config", F_OK) >= 0)
-            configFile = internAtom("/etc/polipo/config");
+        if(access( DEFAULT_CONFIG_PATH, F_OK) >= 0)
+            configFile = internAtom( DEFAULT_CONFIG_PATH );
         if(configFile && access(configFile->string, F_OK) < 0) {
             releaseAtom(configFile);
             configFile = NULL;
diff -ruNa polipo-harden-test/md5.h polipoo/md5.h
--- polipo-harden-test/md5.h	2009-12-12 07:39:48 +0800
+++ polipoo/md5.h	2010-01-22 15:00:57 +0800
@@ -35,7 +35,19 @@
 #ifdef HAS_STDINT_H
 #include <stdint.h>
 #elif defined(HAS_INTTYPES_H)
-#include <inttypes.h>
+#ifdef _MSC_VER
+typedef __int8            int8_t;
+typedef __int16           int16_t;
+typedef __int32           int32_t;
+typedef __int64           int64_t;
+typedef unsigned __int8   uint8_t;
+typedef unsigned __int16  uint16_t;
+typedef unsigned __int32  uint32_t;
+typedef unsigned __int64  uint64_t;
+#else
+  #include <inttypes.h>
+#endif
+
 #endif
 
 /* typedef a 32-bit type */
diff -ruNa polipo-harden-test/mingw.c polipoo/mingw.c
--- polipo-harden-test/mingw.c	2009-12-12 07:39:48 +0800
+++ polipoo/mingw.c	2010-01-22 14:48:40 +0800
@@ -23,7 +23,7 @@
 
 #include "polipo.h"
 
-#ifndef MINGW
+#ifndef WIN32 /*MINGW*/
 
 static int dummy ATTRIBUTE((unused));
 
@@ -53,7 +53,7 @@
  * (with trivial modifications) from the OpenBSD project.
  */
 int
-mingw_inet_aton(const char *cp, struct in_addr *addr)
+win32_inet_aton(const char *cp, struct in_addr *addr)
 {
     register unsigned int val;
     register int base, n;
@@ -148,14 +148,14 @@
 }
 
 unsigned int
-mingw_sleep(unsigned int seconds)
+win32_sleep(unsigned int seconds)
 {
     Sleep(seconds * 1000);
     return 0;
 }
 
 int
-mingw_gettimeofday(struct timeval *tv, char *tz)
+win32_gettimeofday(struct timeval *tv, char *tz)
 {
     const long long EPOCHFILETIME = (116444736000000000LL);
     FILETIME        ft;
@@ -183,7 +183,7 @@
     return 0;
 }
 
-int mingw_poll(struct pollfd *fds, unsigned int nfds, int timo)
+int win32_poll(struct pollfd *fds, unsigned int nfds, int timo)
 {
     struct timeval timeout, *toptr;
     fd_set ifds, ofds, efds, *ip, *op;
@@ -248,7 +248,7 @@
     return rc;
 }
 
-int mingw_close_socket(SOCKET fd) {
+int win32_close_socket(SOCKET fd) {
     int rc;
 
     rc = closesocket(fd);
@@ -268,7 +268,7 @@
     }
 }
 
-int mingw_write_socket(SOCKET fd, void *buf, int n)
+int win32_write_socket(SOCKET fd, void *buf, int n)
 {
     int rc = send(fd, buf, n, 0);
     if(rc == SOCKET_ERROR) {
@@ -277,7 +277,7 @@
     return rc;
 }
 
-int mingw_read_socket(SOCKET fd, void *buf, int n)
+int win32_read_socket(SOCKET fd, void *buf, int n)
 {
     int rc = recv(fd, buf, n, 0);
     if(rc == SOCKET_ERROR) {
@@ -294,7 +294,7 @@
  * is successful, other -1.
  */
 int
-mingw_setnonblocking(SOCKET fd, int nonblocking)
+win32_setnonblocking(SOCKET fd, int nonblocking)
 {
     int rc;
 
@@ -312,7 +312,7 @@
  * even if we are using winsock.
  */
 SOCKET
-mingw_socket(int domain, int type, int protocol)
+win32_socket(int domain, int type, int protocol)
 {
     SOCKET fd = socket(domain, type, protocol);
     if(fd == INVALID_SOCKET) {
@@ -342,7 +342,7 @@
  * even if we are using winsock.
  */
 int
-mingw_connect(SOCKET fd, struct sockaddr *addr, socklen_t addr_len)
+win32_connect(SOCKET fd, struct sockaddr *addr, socklen_t addr_len)
 {
     int rc = connect(fd, addr, addr_len);
     assert(rc == 0 || rc == SOCKET_ERROR);
@@ -358,7 +358,7 @@
  * even if we are using winsock.
  */
 SOCKET
-mingw_accept(SOCKET fd, struct sockaddr *addr, socklen_t *addr_len)
+win32_accept(SOCKET fd, struct sockaddr *addr, socklen_t *addr_len)
 {
     SOCKET newfd = accept(fd, addr, addr_len);
     if(newfd == INVALID_SOCKET) {
@@ -374,7 +374,7 @@
  * even if we are using winsock.
  */
 int
-mingw_shutdown(SOCKET fd, int mode)
+win32_shutdown(SOCKET fd, int mode)
 {
     int rc = shutdown(fd, mode);
     assert(rc == 0 || rc == SOCKET_ERROR);
@@ -390,7 +390,7 @@
  * even if we are using winsock.
  */
 int
-mingw_getpeername(SOCKET fd, struct sockaddr *name, socklen_t *namelen)
+win32_getpeername(SOCKET fd, struct sockaddr *name, socklen_t *namelen)
 {
     int rc = getpeername(fd, name, namelen);
     assert(rc == 0 || rc == SOCKET_ERROR);
@@ -403,7 +403,7 @@
 /* Stat doesn't work on directories if the name ends in a slash. */
 
 int
-mingw_stat(const char *filename, struct stat *ss)
+win32_stat(const char *filename, struct stat *ss)
 {
     int len, rc, saved_errno;
     char *noslash;
@@ -425,7 +425,7 @@
     errno = saved_errno;
     return rc;
 }
-#endif /* #ifdef MINGW */
+#endif /* #ifdef WIN32 MINGW */
 
 #ifndef HAVE_READV_WRITEV
 
diff -ruNa polipo-harden-test/mingw.h polipoo/mingw.h
--- polipo-harden-test/mingw.h	2009-12-12 07:39:48 +0800
+++ polipoo/mingw.h	2010-01-22 15:11:56 +0800
@@ -32,7 +32,7 @@
  * symbol. For Unix or Unix-like systems, leave it undefined.
  */
 
-#ifdef MINGW
+#ifdef WIN32 /*MINGW*/
 
 /* Unfortunately, there's no hiding it. */
 #define HAVE_WINSOCK 1
@@ -74,7 +74,7 @@
     short events;     /* requested events */
     short revents;    /* returned events */
 };
-#define poll(x, y, z)        mingw_poll(x, y, z)
+#define poll(x, y, z)        win32_poll(x, y, z)
 
 /* These wrappers do nothing special except set the global errno variable if
  * an error occurs (winsock doesn't do this by default). They set errno
@@ -82,17 +82,17 @@
  * outside of this file "shouldn't" have to worry about winsock specific error
  * handling.
  */
-#define socket(x, y, z)      mingw_socket(x, y, z)
-#define connect(x, y, z)     mingw_connect(x, y, z)
-#define accept(x, y, z)      mingw_accept(x, y, z)
-#define shutdown(x, y)       mingw_shutdown(x, y)
-#define getpeername(x, y, z) mingw_getpeername(x, y, z)
+#define socket(x, y, z)      win32_socket(x, y, z)
+#define connect(x, y, z)     win32_connect(x, y, z)
+#define accept(x, y, z)      win32_accept(x, y, z)
+#define shutdown(x, y)       win32_shutdown(x, y)
+#define getpeername(x, y, z) win32_getpeername(x, y, z)
 
 /* Wrapper macros to call misc. functions mingw is missing */
-#define sleep(x)             mingw_sleep(x)
-#define inet_aton(x, y)      mingw_inet_aton(x, y)
-#define gettimeofday(x, y)   mingw_gettimeofday(x, y)
-#define stat(x, y)           mingw_stat(x, y)
+#define sleep(x)             win32_sleep(x)
+#define inet_aton(x, y)      win32_inet_aton(x, y)
+#define gettimeofday(x, y)   win32_gettimeofday(x, y)
+#define stat(x, y)           win32_stat(x, y)
 
 #define mkdir(x, y) mkdir(x)
 
@@ -100,27 +100,27 @@
 typedef int socklen_t;
 
 /* Function prototypes for functions in mingw.c */
-unsigned int mingw_sleep(unsigned int);
-int     mingw_inet_aton(const char *, struct in_addr *);
-int     mingw_gettimeofday(struct timeval *, char *);
-int     mingw_poll(struct pollfd *, unsigned int, int);
-SOCKET  mingw_socket(int, int, int);
-int     mingw_connect(SOCKET, struct sockaddr*, socklen_t);
-SOCKET  mingw_accept(SOCKET, struct sockaddr*, socklen_t *);
-int     mingw_shutdown(SOCKET, int);
-int     mingw_getpeername(SOCKET, struct sockaddr*, socklen_t *);
+unsigned int win32_sleep(unsigned int);
+int     win32_inet_aton(const char *, struct in_addr *);
+int     win32_gettimeofday(struct timeval *, char *);
+int     win32_poll(struct pollfd *, unsigned int, int);
+SOCKET  win32_socket(int, int, int);
+int     win32_connect(SOCKET, struct sockaddr*, socklen_t);
+SOCKET  win32_accept(SOCKET, struct sockaddr*, socklen_t *);
+int     win32_shutdown(SOCKET, int);
+int     win32_getpeername(SOCKET, struct sockaddr*, socklen_t *);
 
 /* Three socket specific macros */
-#define READ(x, y, z)  mingw_read_socket(x, y, z)
-#define WRITE(x, y, z) mingw_write_socket(x, y, z)
-#define CLOSE(x)       mingw_close_socket(x)
-
-int mingw_read_socket(SOCKET, void *, int);
-int mingw_write_socket(SOCKET, void *, int);
-int mingw_close_socket(SOCKET);
+#define READ(x, y, z)  win32_read_socket(x, y, z)
+#define WRITE(x, y, z) win32_write_socket(x, y, z)
+#define CLOSE(x)       win32_close_socket(x)
+
+int win32_read_socket(SOCKET, void *, int);
+int win32_write_socket(SOCKET, void *, int);
+int win32_close_socket(SOCKET);
 
-int mingw_setnonblocking(SOCKET, int);
-int mingw_stat(const char*, struct stat*);
+int win32_setnonblocking(SOCKET, int);
+int win32_stat(const char*, struct stat*);
 #endif
 
 #ifndef HAVE_READV_WRITEV
diff -ruNa polipo-harden-test/object.c polipoo/object.c
--- polipo-harden-test/object.c	2009-12-12 07:39:48 +0800
+++ polipoo/object.c	2010-01-22 14:46:52 +0800
@@ -809,7 +809,7 @@
 discardObjects(int all, int force)
 {
     ObjectPtr object;
-    int i;
+    int i=0;
     static int in_discardObjects = 0;
     TimeEventHandlerPtr event;
 
@@ -838,7 +838,7 @@
                     dispose_chunk(object->chunks[j].data);
                     object->chunks[j].data = NULL;
                     object->chunks[j].size = 0;
-                    i++;
+                   /** i++; jiang :it seems no use here */
                 }
             }
             object = object->previous;
diff -ruNa polipo-harden-test/polipo.h polipoo/polipo.h
--- polipo-harden-test/polipo.h	2009-12-12 07:39:48 +0800
+++ polipoo/polipo.h	2010-01-22 14:49:35 +0800
@@ -24,7 +24,9 @@
 #define _GNU_SOURCE
 #endif
 
+#ifndef WIN32
 #include <sys/param.h>
+#endif
 
 #ifdef __MINGW32_VERSION
 #define MINGW
@@ -37,13 +39,15 @@
 #include <errno.h>
 #include <string.h>
 #include <assert.h>
-#include <unistd.h>
 #include <fcntl.h>
 #include <time.h>
-#include <sys/time.h>
 #include <sys/stat.h>
+#ifndef _MSC_VER
+#include <unistd.h>
+#include <sys/time.h>
 #include <dirent.h>
-#ifndef MINGW
+#endif
+#ifndef WIN32 /*MINGW*/
 #include <sys/mman.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -58,6 +62,14 @@
 #include <signal.h>
 #endif
 
+#if defined(va_copy)
+#elif defined(__va_copy)
+#  define va_copy(dst, src) __va_copy((dst), (src))
+#else
+/* #  define va_copy(dst, src) (memcpy(&(dst), &(src), sizeof (va_list))) */
+#  define va_copy(dst, src) do{((dst) = (src)) ;} while(0) 
+#endif
+
 #ifndef MAP_ANONYMOUS
 #define MAP_ANONYMOUS MAP_ANON
 #endif
@@ -165,7 +177,7 @@
 #define UNALIGNED_ACCESS
 #endif
 
-#ifndef MINGW
+#ifndef WIN32 /*MINGW*/
 #define HAVE_FORK
 #ifndef NO_SYSLOG
 #define HAVE_SYSLOG
@@ -181,6 +193,15 @@
 #endif
 #endif
 
+#ifdef _MSC_VER
+
+#define F_OK 00
+#define snprintf _snprintf
+#define S_ISDIR(x) (S_IFDIR&(x))
+#define S_ISREG(x) (S_IFREG&(x))
+
+#endif
+
 #ifdef HAVE_READV_WRITEV
 #define WRITEV(x, y, z) writev(x, y, z)
 #define READV(x, y, z)  readv(x, y, z)
diff -ruNa polipo-harden-test/polipo.vcproj polipoo/polipo.vcproj
--- polipo-harden-test/polipo.vcproj	1970-01-01 08:00:00 +0800
+++ polipoo/polipo.vcproj	2010-01-22 18:36:00 +0800
@@ -0,0 +1,391 @@
+<?xml version="1.0" encoding="gb2312"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="9.00"
+	Name="polipo"
+	ProjectGUID="{B4E72DB8-4BA8-44D9-83F4-84162140CC91}"
+	RootNamespace="polipo"
+	TargetFrameworkVersion="196613"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="2"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				PreprocessorDefinitions="WIN32;HAS_INTTYPES_H"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				WarningLevel="3"
+				DebugInformationFormat="4"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="ws2_32.lib Iphlpapi.lib"
+				GenerateDebugInformation="true"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="2"
+			WholeProgramOptimization="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="2"
+				EnableIntrinsicFunctions="true"
+				AdditionalIncludeDirectories=""
+				PreprocessorDefinitions="WIN32;HAS_INTTYPES_H"
+				RuntimeLibrary="2"
+				EnableFunctionLevelLinking="true"
+				WarningLevel="3"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="ws2_32.lib Iphlpapi.lib"
+				GenerateDebugInformation="true"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Ô´Îļþ"
+			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+			>
+			<File
+				RelativePath=".\atom.c"
+				>
+			</File>
+			<File
+				RelativePath=".\auth.c"
+				>
+			</File>
+			<File
+				RelativePath=".\chunk.c"
+				>
+			</File>
+			<File
+				RelativePath=".\client.c"
+				>
+			</File>
+			<File
+				RelativePath=".\config.c"
+				>
+			</File>
+			<File
+				RelativePath=".\diskcache.c"
+				>
+			</File>
+			<File
+				RelativePath=".\dns.c"
+				>
+			</File>
+			<File
+				RelativePath=".\event.c"
+				>
+			</File>
+			<File
+				RelativePath=".\forbidden.c"
+				>
+			</File>
+			<File
+				RelativePath=".\fts_compat.c"
+				>
+			</File>
+			<File
+				RelativePath=".\http.c"
+				>
+			</File>
+			<File
+				RelativePath=".\http_parse.c"
+				>
+			</File>
+			<File
+				RelativePath=".\io.c"
+				>
+			</File>
+			<File
+				RelativePath=".\local.c"
+				>
+			</File>
+			<File
+				RelativePath=".\log.c"
+				>
+			</File>
+			<File
+				RelativePath=".\main.c"
+				>
+			</File>
+			<File
+				RelativePath=".\md5.c"
+				>
+			</File>
+			<File
+				RelativePath=".\mingw.c"
+				>
+			</File>
+			<File
+				RelativePath=".\object.c"
+				>
+			</File>
+			<File
+				RelativePath=".\parse_time.c"
+				>
+			</File>
+			<File
+				RelativePath=".\server.c"
+				>
+			</File>
+			<File
+				RelativePath=".\socks.c"
+				>
+			</File>
+			<File
+				RelativePath=".\tunnel.c"
+				>
+			</File>
+			<File
+				RelativePath=".\util.c"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Í·Îļþ"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+			>
+			<File
+				RelativePath=".\atom.h"
+				>
+			</File>
+			<File
+				RelativePath=".\auth.h"
+				>
+			</File>
+			<File
+				RelativePath=".\chunk.h"
+				>
+			</File>
+			<File
+				RelativePath=".\client.h"
+				>
+			</File>
+			<File
+				RelativePath=".\config.h"
+				>
+			</File>
+			<File
+				RelativePath=".\diskcache.h"
+				>
+			</File>
+			<File
+				RelativePath=".\dns.h"
+				>
+			</File>
+			<File
+				RelativePath=".\event.h"
+				>
+			</File>
+			<File
+				RelativePath=".\forbidden.h"
+				>
+			</File>
+			<File
+				RelativePath=".\fts_compat.h"
+				>
+			</File>
+			<File
+				RelativePath=".\ftsimport.h"
+				>
+			</File>
+			<File
+				RelativePath=".\http.h"
+				>
+			</File>
+			<File
+				RelativePath=".\http_parse.h"
+				>
+			</File>
+			<File
+				RelativePath=".\io.h"
+				>
+			</File>
+			<File
+				RelativePath=".\local.h"
+				>
+			</File>
+			<File
+				RelativePath=".\log.h"
+				>
+			</File>
+			<File
+				RelativePath=".\md5.h"
+				>
+			</File>
+			<File
+				RelativePath=".\md5import.h"
+				>
+			</File>
+			<File
+				RelativePath=".\mingw.h"
+				>
+			</File>
+			<File
+				RelativePath=".\object.h"
+				>
+			</File>
+			<File
+				RelativePath=".\parse_time.h"
+				>
+			</File>
+			<File
+				RelativePath=".\polipo.h"
+				>
+			</File>
+			<File
+				RelativePath=".\server.h"
+				>
+			</File>
+			<File
+				RelativePath=".\socks.h"
+				>
+			</File>
+			<File
+				RelativePath=".\tunnel.h"
+				>
+			</File>
+			<File
+				RelativePath=".\util.h"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="port"
+			>
+			<File
+				RelativePath=".\dirent.c"
+				>
+			</File>
+			<File
+				RelativePath=".\dirent.h"
+				>
+			</File>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
diff -ruNa polipo-harden-test/polipo.vcxproj polipoo/polipo.vcxproj
--- polipo-harden-test/polipo.vcxproj	1970-01-01 08:00:00 +0800
+++ polipoo/polipo.vcxproj	2010-01-22 15:05:16 +0800
@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{B4E72DB8-4BA8-44D9-83F4-84162140CC91}</ProjectGuid>
+    <RootNamespace>polipo</RootNamespace>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <CharacterSet>MultiByte</CharacterSet>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup>
+    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>WIN32;HAS_INTTYPES_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <MinimalRebuild>true</MinimalRebuild>
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+    </ClCompile>
+    <Link>
+      <AdditionalDependencies>ws2_32.lib;Iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <TargetMachine>MachineX86</TargetMachine>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <Optimization>MaxSpeed</Optimization>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>WIN32;HAS_INTTYPES_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+    </ClCompile>
+    <Link>
+      <AdditionalDependencies>ws2_32.lib;Iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <OptimizeReferences>true</OptimizeReferences>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <TargetMachine>MachineX86</TargetMachine>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="atom.c" />
+    <ClCompile Include="auth.c" />
+    <ClCompile Include="chunk.c" />
+    <ClCompile Include="client.c" />
+    <ClCompile Include="config.c" />
+    <ClCompile Include="diskcache.c" />
+    <ClCompile Include="dns.c" />
+    <ClCompile Include="event.c" />
+    <ClCompile Include="forbidden.c" />
+    <ClCompile Include="fts_compat.c" />
+    <ClCompile Include="http.c" />
+    <ClCompile Include="http_parse.c" />
+    <ClCompile Include="io.c" />
+    <ClCompile Include="local.c" />
+    <ClCompile Include="log.c" />
+    <ClCompile Include="main.c" />
+    <ClCompile Include="md5.c" />
+    <ClCompile Include="mingw.c" />
+    <ClCompile Include="object.c" />
+    <ClCompile Include="parse_time.c" />
+    <ClCompile Include="server.c" />
+    <ClCompile Include="socks.c" />
+    <ClCompile Include="tunnel.c" />
+    <ClCompile Include="util.c" />
+    <ClCompile Include="dirent.c" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="atom.h" />
+    <ClInclude Include="auth.h" />
+    <ClInclude Include="chunk.h" />
+    <ClInclude Include="client.h" />
+    <ClInclude Include="config.h" />
+    <ClInclude Include="diskcache.h" />
+    <ClInclude Include="dns.h" />
+    <ClInclude Include="event.h" />
+    <ClInclude Include="forbidden.h" />
+    <ClInclude Include="fts_compat.h" />
+    <ClInclude Include="ftsimport.h" />
+    <ClInclude Include="http.h" />
+    <ClInclude Include="http_parse.h" />
+    <ClInclude Include="io.h" />
+    <ClInclude Include="local.h" />
+    <ClInclude Include="log.h" />
+    <ClInclude Include="md5.h" />
+    <ClInclude Include="md5import.h" />
+    <ClInclude Include="mingw.h" />
+    <ClInclude Include="object.h" />
+    <ClInclude Include="parse_time.h" />
+    <ClInclude Include="polipo.h" />
+    <ClInclude Include="server.h" />
+    <ClInclude Include="socks.h" />
+    <ClInclude Include="tunnel.h" />
+    <ClInclude Include="util.h" />
+    <ClInclude Include="dirent.h" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file
diff -ruNa polipo-harden-test/util.c polipoo/util.c
--- polipo-harden-test/util.c	2009-12-12 07:39:48 +0800
+++ polipoo/util.c	2010-01-22 18:22:50 +0800
@@ -278,11 +278,13 @@
 
 #else
 
-/* This is not going to work if va_list is interesting.  But then, if you
+/*** This is not going to work if va_list is interesting.  But then, if you
    have a non-trivial implementation of va_list, you should have va_copy. */
+/*
 #ifndef va_copy
 #define va_copy(a, b) do { a = b; } while(0)
-#endif
+#endif 
+*/
 
 char*
 vsprintf_a(const char *f, va_list args)
@@ -392,7 +394,7 @@
     default: s = NULL; break;
     }
     if(!s) s = strerror(e);
-#ifdef MINGW
+#ifdef WIN32 /*MINGW*/
     if(!s) {
         if(e >= WSABASEERR && e <= WSABASEERR + 2000) {
             /* This should be okay, as long as the caller discards the
@@ -451,12 +453,29 @@
     tzset();
     return t;
 }
+#elif defined(_MSC_VER)
+ time_t
+mktime_gmt(struct tm *tm)
+{
+	time_t t;
+	static int bias = -1;
+	if(bias == -1)
+	{
+		time_t   curr   =   time(NULL);   
+		struct   tm   *  p   = gmtime(&curr);   
+		time_t   gmtcurr     =   mktime(p);  
+		bias = curr-gmtcurr ; 
+	}
+	t = mktime(tm)+bias;
+	/* printf("mktime_gmt2: %d\n", t ); */
+    return t;
+}
 #else
 time_t
 mktime_gmt(struct tm *tm)
 {
     time_t t;
-    char *tz;
+    char *tz=NULL;
     static char *old_tz = NULL;
 
     tz = getenv("TZ");
@@ -466,6 +485,7 @@
     if(old_tz)
         free(old_tz);
     if(tz)
+   /* if( tz && tz[0]>0 ) */
         old_tz = sprintf_a("TZ=%s", tz);
     else
         old_tz = strdup("TZ");  /* XXX - non-portable? */
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.