gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r8541 - in gnunet/src: include util


From: gnunet
Subject: [GNUnet-SVN] r8541 - in gnunet/src: include util
Date: Wed, 10 Jun 2009 16:24:54 -0600

Author: durner
Date: 2009-06-10 16:24:54 -0600 (Wed, 10 Jun 2009)
New Revision: 8541

Added:
   gnunet/src/util/win.cc
   gnunet/src/util/winproc.c
Modified:
   gnunet/src/include/plibc.h
   gnunet/src/util/Makefile.am
   gnunet/src/util/crypto_rsa.c
   gnunet/src/util/disk.c
   gnunet/src/util/network.c
   gnunet/src/util/os_priority.c
   gnunet/src/util/scheduler.c
   gnunet/src/util/server.c
   gnunet/src/util/time.c
Log:
MinGW

Modified: gnunet/src/include/plibc.h
===================================================================
--- gnunet/src/include/plibc.h  2009-06-10 18:48:17 UTC (rev 8540)
+++ gnunet/src/include/plibc.h  2009-06-10 22:24:54 UTC (rev 8541)
@@ -1,17 +1,17 @@
 /*
      This file is part of PlibC.
-     (C) 2005, 2006, 2007, 2008 Nils Durner (and other contributing authors)
+     (C) 2005, 2006, 2007, 2008, 2009 Nils Durner (and other contributing 
authors)
 
           This library is free software; you can redistribute it and/or
           modify it under the terms of the GNU Lesser General Public
           License as published by the Free Software Foundation; either
           version 2.1 of the License, or (at your option) any later version.
-       
+
           This library is distributed in the hope that it will be useful,
           but WITHOUT ANY WARRANTY; without even the implied warranty of
           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
           Lesser General Public License for more details.
-       
+
           You should have received a copy of the GNU Lesser General Public
           License along with this library; if not, write to the Free Software
           Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 
 USA
@@ -22,33 +22,33 @@
  * @brief PlibC header
  * @attention This file is usually not installed under Unix,
  *            so ship it with your application
- * @version $Revision: 1.46 $
+ * @version $Revision: 39 $
  */
 
 #ifndef _PLIBC_H_
 #define _PLIBC_H_
 
 #ifndef SIGALRM
-#define SIGALRM 14
-#endif /*  */
+ #define SIGALRM 14
+#endif
 
 #ifdef __cplusplus
-extern "C"
-{
+extern "C" {
+#endif
 
-#endif                          /*  */
+#include <stddef.h>
 
 #ifdef Q_OS_WIN32
-#define WINDOWS 1
-#endif                          /*  */
+ #define WINDOWS 1
+#endif
 
 #define HAVE_PLIBC_FD 0
 
 #ifdef WINDOWS
 
 #if ENABLE_NLS
-#include "langinfo.h"
-#endif                          /*  */
+  #include "langinfo.h"
+#endif
 
 #include <windows.h>
 #include <Ws2tcpip.h>
@@ -68,14 +68,16 @@
 
 /* Convert LARGE_INTEGER to double */
 #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \
-  (double) ((x).LowPart))
+  (double)((x).LowPart))
+
 #define socklen_t int
 #define ssize_t int
 #define off_t int
 #define int64_t long long
 #define int32_t long
-  struct stat64
-  {
+
+struct stat64
+{
     _dev_t st_dev;
     _ino_t st_ino;
     _mode_t st_mode;
@@ -87,112 +89,116 @@
     __time64_t st_atime;
     __time64_t st_mtime;
     __time64_t st_ctime;
-  };
+};
 
 #ifndef pid_t
-#define pid_t int
-#endif                          /*  */
+       #define pid_t int
+#endif
 
 #ifndef WEXITSTATUS
-#define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
-#endif                          /*  */
+       #define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
+#endif
 
+#ifndef MSG_DONTWAIT
+  #define MSG_DONTWAIT 0
+#endif
+
 /* Thanks to the Cygwin project */
-#define ENOCSI 43               /* No CSI structure available */
-#define EL2HLT 44               /* Level 2 halted */
+#define ENOCSI 43      /* No CSI structure available */
+#define EL2HLT 44      /* Level 2 halted */
 #ifndef  EDEADLK
-#define EDEADLK 45              /* Deadlock condition */
-#endif                          /*  */
+       #define EDEADLK 45      /* Deadlock condition */
+#endif
 #ifndef  ENOLCK
-#define ENOLCK 46               /* No record locks available */
-#endif                          /*  */
-#define EBADE 50                /* Invalid exchange */
-#define EBADR 51                /* Invalid request descriptor */
-#define EXFULL 52               /* Exchange full */
-#define ENOANO 53               /* No anode */
-#define EBADRQC 54              /* Invalid request code */
-#define EBADSLT 55              /* Invalid slot */
+       #define ENOLCK 46       /* No record locks available */
+#endif
+#define EBADE 50       /* Invalid exchange */
+#define EBADR 51       /* Invalid request descriptor */
+#define EXFULL 52      /* Exchange full */
+#define ENOANO 53      /* No anode */
+#define EBADRQC 54     /* Invalid request code */
+#define EBADSLT 55     /* Invalid slot */
 #ifndef  EDEADLOCK
-#define EDEADLOCK EDEADLK       /* File locking deadlock error */
-#endif                          /*  */
-#define EBFONT 57               /* Bad font file fmt */
-#define ENOSTR 60               /* Device not a stream */
-#define ENODATA 61              /* No data (for no delay io) */
-#define ETIME 62                /* Timer expired */
-#define ENOSR 63                /* Out of streams resources */
-#define ENONET 64               /* Machine is not on the network */
-#define ENOPKG 65               /* Package not installed */
-#define EREMOTE 66              /* The object is remote */
-#define ENOLINK 67              /* The link has been severed */
-#define EADV 68                 /* Advertise error */
-#define ESRMNT 69               /* Srmount error */
-#define ECOMM 70                /* Communication error on send */
-#define EPROTO 71               /* Protocol error */
-#define EMULTIHOP 74            /* Multihop attempted */
-#define ELBIN 75                /* Inode is remote (not really error) */
-#define EDOTDOT 76              /* Cross mount point (not really error) */
-#define EBADMSG 77              /* Trying to read unreadable message */
-#define ENOTUNIQ 80             /* Given log. name not unique */
-#define EBADFD 81               /* f.d. invalid for this operation */
-#define EREMCHG 82              /* Remote address changed */
-#define ELIBACC 83              /* Can't access a needed shared lib */
-#define ELIBBAD 84              /* Accessing a corrupted shared lib */
-#define ELIBSCN 85              /* .lib section in a.out corrupted */
-#define ELIBMAX 86              /* Attempting to link in too many libs */
-#define ELIBEXEC 87             /* Attempting to exec a shared library */
+       #define EDEADLOCK EDEADLK       /* File locking deadlock error */
+#endif
+#define EBFONT 57      /* Bad font file fmt */
+#define ENOSTR 60      /* Device not a stream */
+#define ENODATA 61     /* No data (for no delay io) */
+#define ETIME 62       /* Timer expired */
+#define ENOSR 63       /* Out of streams resources */
+#define ENONET 64      /* Machine is not on the network */
+#define ENOPKG 65      /* Package not installed */
+#define EREMOTE 66     /* The object is remote */
+#define ENOLINK 67     /* The link has been severed */
+#define EADV 68                /* Advertise error */
+#define ESRMNT 69      /* Srmount error */
+#define ECOMM 70       /* Communication error on send */
+#define EPROTO 71      /* Protocol error */
+#define EMULTIHOP 74   /* Multihop attempted */
+#define ELBIN 75       /* Inode is remote (not really error) */
+#define EDOTDOT 76     /* Cross mount point (not really error) */
+#define EBADMSG 77     /* Trying to read unreadable message */
+#define ENOTUNIQ 80    /* Given log. name not unique */
+#define EBADFD 81      /* f.d. invalid for this operation */
+#define EREMCHG 82     /* Remote address changed */
+#define ELIBACC 83     /* Can't access a needed shared lib */
+#define ELIBBAD 84     /* Accessing a corrupted shared lib */
+#define ELIBSCN 85     /* .lib section in a.out corrupted */
+#define ELIBMAX 86     /* Attempting to link in too many libs */
+#define ELIBEXEC 87    /* Attempting to exec a shared library */
 #ifndef  ENOSYS
-#define ENOSYS 88               /* Function not implemented */
-#endif                          /*  */
-#define ENMFILE 89              /* No more files */
+       #define ENOSYS 88       /* Function not implemented */
+#endif
+#define ENMFILE 89      /* No more files */
 #ifndef  ENOTEMPTY
-#define ENOTEMPTY 90            /* Directory not empty */
-#endif                          /*  */
+       #define ENOTEMPTY 90    /* Directory not empty */
+#endif
 #ifndef  ENAMETOOLONG
-#define ENAMETOOLONG 91         /* File or path name too long */
-#endif                          /*  */
-#define ELOOP 92                /* Too many symbolic links */
-#define EOPNOTSUPP 95           /* Operation not supported on transport 
endpoint */
-#define EPFNOSUPPORT 96         /* Protocol family not supported */
-#define ECONNRESET 104          /* Connection reset by peer */
-#define ENOBUFS 105             /* No buffer space available */
-#define EAFNOSUPPORT 106        /* Address family not supported by protocol 
family */
-#define EPROTOTYPE 107          /* Protocol wrong type for socket */
-#define ENOTSOCK 108            /* Socket operation on non-socket */
-#define ENOPROTOOPT 109         /* Protocol not available */
-#define ESHUTDOWN 110           /* Can't send after socket shutdown */
-#define ECONNREFUSED 111        /* Connection refused */
-#define EADDRINUSE 112          /* Address already in use */
-#define ECONNABORTED 113        /* Connection aborted */
-#define ENETUNREACH 114         /* Network is unreachable */
-#define ENETDOWN 115            /* Network interface is not configured */
+       #define ENAMETOOLONG 91 /* File or path name too long */
+#endif
+#define ELOOP 92       /* Too many symbolic links */
+#define EOPNOTSUPP 95  /* Operation not supported on transport endpoint */
+#define EPFNOSUPPORT 96 /* Protocol family not supported */
+#define ECONNRESET 104  /* Connection reset by peer */
+#define ENOBUFS 105    /* No buffer space available */
+#define EAFNOSUPPORT 106 /* Address family not supported by protocol family */
+#define EPROTOTYPE 107 /* Protocol wrong type for socket */
+#define ENOTSOCK 108   /* Socket operation on non-socket */
+#define ENOPROTOOPT 109        /* Protocol not available */
+#define ESHUTDOWN 110  /* Can't send after socket shutdown */
+#define ECONNREFUSED 111       /* Connection refused */
+#define EADDRINUSE 112         /* Address already in use */
+#define ECONNABORTED 113       /* Connection aborted */
+#define ENETUNREACH 114                /* Network is unreachable */
+#define ENETDOWN 115           /* Network interface is not configured */
 #ifndef  ETIMEDOUT
-#define ETIMEDOUT 116           /* Connection timed out */
-#endif                          /*  */
-#define EHOSTDOWN 117           /* Host is down */
-#define EHOSTUNREACH 118        /* Host is unreachable */
-#define EINPROGRESS 119         /* Connection already in progress */
-#define EALREADY 120            /* Socket already connected */
-#define EDESTADDRREQ 121        /* Destination address required */
-#define EMSGSIZE 122            /* Message too long */
-#define EPROTONOSUPPORT 123     /* Unknown protocol */
-#define ESOCKTNOSUPPORT 124     /* Socket type not supported */
-#define EADDRNOTAVAIL 125       /* Address not available */
-#define ENETRESET 126           /* Connection aborted by network */
-#define EISCONN 127             /* Socket is already connected */
-#define ENOTCONN 128            /* Socket is not connected */
-#define ETOOMANYREFS 129        /* Too many references: cannot splice */
-#define EPROCLIM 130            /* Too many processes */
-#define EUSERS 131              /* Too many users */
-#define EDQUOT 132              /* Disk quota exceeded */
-#define ESTALE 133              /* Unknown error */
+       #define ETIMEDOUT 116           /* Connection timed out */
+#endif
+#define EHOSTDOWN 117          /* Host is down */
+#define EHOSTUNREACH 118       /* Host is unreachable */
+#define EINPROGRESS 119                /* Connection already in progress */
+#define EALREADY 120           /* Socket already connected */
+#define EDESTADDRREQ 121       /* Destination address required */
+#define EMSGSIZE 122           /* Message too long */
+#define EPROTONOSUPPORT 123    /* Unknown protocol */
+#define ESOCKTNOSUPPORT 124    /* Socket type not supported */
+#define EADDRNOTAVAIL 125      /* Address not available */
+#define ENETRESET 126          /* Connection aborted by network */
+#define EISCONN 127                /* Socket is already connected */
+#define ENOTCONN 128           /* Socket is not connected */
+#define ETOOMANYREFS 129       /* Too many references: cannot splice */
+#define EPROCLIM 130           /* Too many processes */
+#define EUSERS 131                     /* Too many users */
+#define EDQUOT 132                     /* Disk quota exceeded */
+#define ESTALE 133          /* Unknown error */
 #ifndef  ENOTSUP
-#define ENOTSUP 134             /* Not supported */
-#endif                          /*  */
-#define ENOMEDIUM 135           /* No medium (in tape drive) */
-#define ENOSHARE 136            /* No such host or network path */
-#define ECASECLASH 137          /* Filename exists with different case */
-#define EWOULDBLOCK EAGAIN      /* Operation would block */
-#define EOVERFLOW 139           /* Value too large for defined data type */
+       #define ENOTSUP 134                 /* Not supported */
+#endif
+#define ENOMEDIUM 135       /* No medium (in tape drive) */
+#define ENOSHARE 136        /* No such host or network path */
+#define ECASECLASH 137      /* Filename exists with different case */
+#define EWOULDBLOCK EAGAIN     /* Operation would block */
+#define EOVERFLOW 139 /* Value too large for defined data type */
 
 #undef HOST_NOT_FOUND
 #define HOST_NOT_FOUND 1
@@ -206,46 +212,68 @@
 #define PROT_READ   0x1
 #define PROT_WRITE  0x2
 #define MAP_SHARED  0x1
-#define MAP_PRIVATE 0x2         /* unsupported */
+#define MAP_PRIVATE 0x2 /* unsupported */
 #define MAP_FIXED   0x10
 #define MAP_FAILED  ((void *)-1)
-  struct statfs
-  {
-    long f_type;                /* type of filesystem (see below) */
-    long f_bsize;               /* optimal transfer block size */
-    long f_blocks;              /* total data blocks in file system */
-    long f_bfree;               /* free blocks in fs */
-    long f_bavail;              /* free blocks avail to non-superuser */
-    long f_files;               /* total file nodes in file system */
-    long f_ffree;               /* free file nodes in fs */
-    long f_fsid;                /* file system id */
-    long f_namelen;             /* maximum length of filenames */
-    long f_spare[6];            /* spare for later */
-  };
-  extern const struct in6_addr in6addr_any;     /* :: */
-  extern const struct in6_addr in6addr_loopback;        /* ::1 */
 
+struct statfs
+{
+  long f_type;                  /* type of filesystem (see below) */
+  long f_bsize;                 /* optimal transfer block size */
+  long f_blocks;                /* total data blocks in file system */
+  long f_bfree;                 /* free blocks in fs */
+  long f_bavail;                /* free blocks avail to non-superuser */
+  long f_files;                 /* total file nodes in file system */
+  long f_ffree;                 /* free file nodes in fs */
+  long f_fsid;                  /* file system id */
+  long f_namelen;               /* maximum length of filenames */
+  long f_spare[6];              /* spare for later */
+};
+
+extern const struct in6_addr in6addr_any;        /* :: */
+extern const struct in6_addr in6addr_loopback;   /* ::1 */
+
 /* Taken from the Wine project <http://www.winehq.org>
     /wine/include/winternl.h */
-  enum SYSTEM_INFORMATION_CLASS
-  { SystemBasicInformation = 0, Unknown1, SystemPerformanceInformation = 2, 
SystemTimeOfDayInformation = 3,     /* was SystemTimeInformation */
-    Unknown4, SystemProcessInformation =
-      5, Unknown6, Unknown7, SystemProcessorPerformanceInformation =
-      8, Unknown9, Unknown10, SystemDriverInformation, Unknown12,
-    Unknown13, Unknown14, Unknown15, SystemHandleList, Unknown17,
-    Unknown18, Unknown19, Unknown20, SystemCacheInformation,
-    Unknown22, SystemInterruptInformation =
-      23, SystemExceptionInformation =
-      33, SystemRegistryQuotaInformation = 37, SystemLookasideInformation = 45
-  };
-  typedef struct
-  {
+enum SYSTEM_INFORMATION_CLASS
+{
+  SystemBasicInformation = 0,
+  Unknown1,
+  SystemPerformanceInformation = 2,
+  SystemTimeOfDayInformation = 3, /* was SystemTimeInformation */
+  Unknown4,
+  SystemProcessInformation = 5,
+  Unknown6,
+  Unknown7,
+  SystemProcessorPerformanceInformation = 8,
+  Unknown9,
+  Unknown10,
+  SystemDriverInformation,
+  Unknown12,
+  Unknown13,
+  Unknown14,
+  Unknown15,
+  SystemHandleList,
+  Unknown17,
+  Unknown18,
+  Unknown19,
+  Unknown20,
+  SystemCacheInformation,
+  Unknown22,
+  SystemInterruptInformation = 23,
+  SystemExceptionInformation = 33,
+  SystemRegistryQuotaInformation = 37,
+  SystemLookasideInformation = 45
+};
+
+typedef struct
+{
     LARGE_INTEGER IdleTime;
     LARGE_INTEGER KernelTime;
     LARGE_INTEGER UserTime;
     LARGE_INTEGER Reserved1[2];
     ULONG Reserved2;
-  } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
+} SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
 
 #define sleep(secs) (Sleep(secs * 1000))
 
@@ -262,11 +290,11 @@
 #define SHUT_RDWR SD_BOTH
 
 /* Operations for flock() */
-#define LOCK_SH  1              /* shared lock */
-#define LOCK_EX  2              /* exclusive lock */
-#define LOCK_NB  4              /* or'd with one of the above to prevent
-                                   blocking */
-#define LOCK_UN  8              /* remove lock */
+#define LOCK_SH  1       /* shared lock */
+#define LOCK_EX  2       /* exclusive lock */
+#define LOCK_NB  4       /* or'd with one of the above to prevent
+                            blocking */
+#define LOCK_UN  8       /* remove lock */
 
 /* Not supported under MinGW */
 #define S_IRGRP 0
@@ -289,294 +317,468 @@
 #define SIGTERM 15
 
 #define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__)
-  BOOL _plibc_CreateShortcut (const char *pszSrc, const char *pszDest);
-  BOOL _plibc_DereferenceShortcut (char *pszShortcut);
-  char *plibc_ChooseDir (char *pszTitle, unsigned long ulFlags);
-  char *plibc_ChooseFile (char *pszTitle, unsigned long ulFlags);
-  long QueryRegistry (HKEY hMainKey, char *pszKey, char *pszSubKey,
-                      char *pszBuffer, long *pdLength);
-  BOOL __win_IsHandleMarkedAsBlocking (SOCKET hHandle);
-  void __win_SetHandleBlockingMode (SOCKET s, BOOL bBlocking);
-  void __win_DiscardHandleBlockingMode (SOCKET s);
-  int _win_isSocketValid (int s);
-  int plibc_conv_to_win_path (const char *pszUnix, char *pszWindows);
-  unsigned plibc_get_handle_count ();
-  typedef void (*TPanicProc) (int, char *);
-  void plibc_set_panic_proc (TPanicProc proc);
-  int flock (int fd, int operation);
-  int fsync (int fildes);
-  int inet_pton (int af, const char *src, void *dst);
-  int inet_pton4 (const char *src, u_char * dst, int pton);
 
+BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest);
+BOOL _plibc_DereferenceShortcut(char *pszShortcut);
+char *plibc_ChooseDir(char *pszTitle, unsigned long ulFlags);
+char *plibc_ChooseFile(char *pszTitle, unsigned long ulFlags);
+long QueryRegistry(HKEY hMainKey, char *pszKey, char *pszSubKey,
+              char *pszBuffer, long *pdLength);
+
+BOOL __win_IsHandleMarkedAsBlocking(SOCKET hHandle);
+void __win_SetHandleBlockingMode(SOCKET s, BOOL bBlocking);
+void __win_DiscardHandleBlockingMode(SOCKET s);
+int _win_isSocketValid(int s);
+int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows);
+unsigned plibc_get_handle_count();
+
+typedef void (*TPanicProc) (int, char *);
+void plibc_set_panic_proc(TPanicProc proc);
+
+int flock(int fd, int operation);
+int fsync(int fildes);
+int inet_pton(int af, const char *src, void *dst);
+int inet_pton4(const char *src, u_char *dst, int pton);
 #if USE_IPV6
-  int inet_pton6 (const char *src, u_char * dst);
+int inet_pton6(const char *src, u_char *dst);
+#endif
+int truncate(const char *fname, int distance);
+int statfs(const char *path, struct statfs *buf);
+const char *hstrerror(int err);
+int mkstemp(char *tmplate);
+char *strptime (const char *buf, const char *format, struct tm *tm);
+const char *inet_ntop(int af, const void *src, char *dst, size_t size);
 
-#endif                          /*  */
-  int truncate (const char *fname, int distance);
-  int statfs (const char *path, struct statfs *buf);
-  const char *hstrerror (int err);
-  void gettimeofday (struct timeval *tp, void *tzp);
-  int mkstemp (char *tmplate);
-  char *strptime (const char *buf, const char *format, struct tm *tm);
-  char *ctime (const time_t * clock);
-  char *ctime_r (const time_t * clock, char *buf);
-  const char *inet_ntop (int af, const void *src, char *dst, size_t size);
-  int plibc_init (char *pszOrg, char *pszApp);
-  void plibc_shutdown ();
-  int plibc_initialized ();
-  int plibc_conv_to_win_path_ex (const char *pszUnix, char *pszWindows,
-                                 int derefLinks);
-  void _SetErrnoFromWinError (long lWinError, char *pszCaller, int iLine);
-  void SetErrnoFromWinsockError (long lWinError);
-  void SetHErrnoFromWinError (long lWinError);
-  void SetErrnoFromHRESULT (HRESULT hRes);
-  FILE *_win_fopen (const char *filename, const char *mode);
-  DIR *_win_opendir (const char *dirname);
-  int _win_open (const char *filename, int oflag, ...);
-
+int plibc_init(char *pszOrg, char *pszApp);
+void plibc_shutdown();
+int plibc_initialized();
+int plibc_conv_to_win_path_ex(const char *pszUnix, char *pszWindows, int 
derefLinks);
+void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine);
+void SetErrnoFromWinsockError(long lWinError);
+void SetHErrnoFromWinError(long lWinError);
+void SetErrnoFromHRESULT(HRESULT hRes);
+int GetErrnoFromWinsockError(long lWinError);
+FILE *_win_fopen(const char *filename, const char *mode);
+DIR *_win_opendir(const char *dirname);
+int _win_open(const char *filename, int oflag, ...);
 #ifdef ENABLE_NLS
-  char *_win_bindtextdomain (const char *domainname, const char *dirname);
+char *_win_bindtextdomain(const char *domainname, const char *dirname);
+#endif
+int _win_chdir(const char *path);
+int _win_close(int fd);
+int _win_creat(const char *path, mode_t mode);
+char *_win_ctime(const time_t *clock);
+char *_win_ctime_r(const time_t *clock, char *buf);
+int _win_fstat(int handle, struct stat *buffer);
+int _win_ftruncate(int fildes, off_t length);
+void _win_gettimeofday(struct timeval *tp, void *tzp);
+int _win_kill(pid_t pid, int sig);
+int _win_pipe(int *phandles);
+int _win_rmdir(const char *path);
+int _win_access( const char *path, int mode );
+int _win_chmod(const char *filename, int pmode);
+char *realpath(const char *file_name, char *resolved_name);
+long _win_random(void);
+int _win_remove(const char *path);
+int _win_rename(const char *oldname, const char *newname);
+int _win_stat(const char *path, struct stat *buffer);
+int _win_stat64(const char *path, struct stat64 *buffer);
+int _win_unlink(const char *filename);
+int _win_write(int fildes, const void *buf, size_t nbyte);
+int _win_read(int fildes, void *buf, size_t nbyte);
+size_t _win_fwrite(const void *buffer, size_t size, size_t count, FILE 
*stream);
+size_t _win_fread( void *buffer, size_t size, size_t count, FILE *stream );
+int _win_symlink(const char *path1, const char *path2);
+void *_win_mmap(void *start, size_t len, int access, int flags, int fd,
+                unsigned long long offset);
+int _win_munmap(void *start, size_t length);
+int _win_lstat(const char *path, struct stat *buf);
+int _win_lstat64(const char *path, struct stat64 *buf);
+int _win_readlink(const char *path, char *buf, size_t bufsize);
+int _win_accept(SOCKET s, struct sockaddr *addr, int *addrlen);
+int _win_printf(const char *format,...);
+int _win_fprintf(FILE *f,const char *format,...);
+int _win_vprintf(const char *format, va_list ap);
+int _win_vfprintf(FILE *stream, const char *format, va_list arg_ptr);
+int _win_vsprintf(char *dest,const char *format, va_list arg_ptr);
+int _win_vsnprintf(char* str, size_t size, const char *format, va_list 
arg_ptr);
+int _win_snprintf(char *str,size_t size,const char *format,...);
+int _win_sprintf(char *dest,const char *format,...);
+int _win_vsscanf(const char* str, const char* format, va_list arg_ptr);
+int _win_sscanf(const char *str, const char *format, ...);
+int _win_vfscanf(FILE *stream, const char *format, va_list arg_ptr);
+int _win_vscanf(const char *format, va_list arg_ptr);
+int _win_scanf(const char *format, ...);
+int _win_fscanf(FILE *stream, const char *format, ...);
+pid_t _win_waitpid(pid_t pid, int *stat_loc, int options);
+int _win_bind(SOCKET s, const struct sockaddr *name, int namelen);
+int _win_connect(SOCKET s,const struct sockaddr *name, int namelen);
+int _win_getpeername(SOCKET s, struct sockaddr *name,
+                int *namelen);
+int _win_getsockname(SOCKET s, struct sockaddr *name,
+                int *namelen);
+int _win_getsockopt(SOCKET s, int level, int optname, char *optval,
+                               int *optlen);
+int _win_listen(SOCKET s, int backlog);
+int _win_recv(SOCKET s, char *buf, int len, int flags);
+int _win_recvfrom(SOCKET s, void *buf, int len, int flags,
+             struct sockaddr *from, int *fromlen);
+int _win_select(int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds,
+                const struct timeval *tv);
+int _win_send(SOCKET s, const char *buf, int len, int flags);
+int _win_sendto(SOCKET s, const char *buf, int len, int flags,
+                const struct sockaddr *to, int tolen);
+int _win_setsockopt(SOCKET s, int level, int optname, const void *optval,
+                    int optlen);
+int _win_shutdown(SOCKET s, int how);
+SOCKET _win_socket(int af, int type, int protocol);
+struct hostent *_win_gethostbyaddr(const char *addr, int len, int type);
+struct hostent *_win_gethostbyname(const char *name);
+struct hostent *gethostbyname2(const char *name, int af);
+char *_win_strerror(int errnum);
+int IsWinNT();
+char *index(const char *s, int c);
 
-#endif                          /*  */
-  int _win_chdir (const char *path);
-  int _win_close (int fd);
-  int _win_creat (const char *path, mode_t mode);
-  int _win_fstat (int handle, struct stat *buffer);
-  int _win_ftruncate (int fildes, off_t length);
-  int _win_kill (pid_t pid, int sig);
-  int _win_pipe (int *phandles);
-  int _win_rmdir (const char *path);
-  int _win_access (const char *path, int mode);
-  int _win_chmod (const char *filename, int pmode);
-  char *realpath (const char *file_name, char *resolved_name);
-  long _win_random (void);
-  int _win_remove (const char *path);
-  int _win_rename (const char *oldname, const char *newname);
-  int _win_stat (const char *path, struct stat *buffer);
-  int _win_stat64 (const char *path, struct stat64 *buffer);
-  int _win_unlink (const char *filename);
-  int _win_write (int fildes, const void *buf, size_t nbyte);
-  int _win_read (int fildes, void *buf, size_t nbyte);
-  size_t _win_fwrite (const void *buffer, size_t size, size_t count,
-                      FILE * stream);
-  size_t _win_fread (void *buffer, size_t size, size_t count, FILE * stream);
-  int _win_symlink (const char *path1, const char *path2);
-  void *_win_mmap (void *start, size_t len, int access, int flags, int fd,
-                   unsigned long long offset);
-  int _win_munmap (void *start, size_t length);
-  int _win_lstat (const char *path, struct stat *buf);
-  int _win_lstat64 (const char *path, struct stat64 *buf);
-  int _win_readlink (const char *path, char *buf, size_t bufsize);
-  int _win_accept (SOCKET s, struct sockaddr *addr, int *addrlen);
-  int _win_printf (const char *format, ...);
-  int _win_fprintf (FILE * f, const char *format, ...);
-  int _win_vprintf (const char *format, va_list ap);
-  int _win_vfprintf (FILE * stream, const char *format, va_list arg_ptr);
-  int _win_vsprintf (char *dest, const char *format, va_list arg_ptr);
-  int _win_vsnprintf (char *str, size_t size, const char *format,
-                      va_list arg_ptr);
-  int _win_snprintf (char *str, size_t size, const char *format, ...);
-  int _win_sprintf (char *dest, const char *format, ...);
-  int _win_vsscanf (const char *str, const char *format, va_list arg_ptr);
-  int _win_sscanf (const char *str, const char *format, ...);
-  int _win_vfscanf (FILE * stream, const char *format, va_list arg_ptr);
-  int _win_vscanf (const char *format, va_list arg_ptr);
-  int _win_scanf (const char *format, ...);
-  int _win_fscanf (FILE * stream, const char *format, ...);
-  pid_t _win_waitpid (pid_t pid, int *stat_loc, int options);
-  int _win_bind (SOCKET s, const struct sockaddr *name, int namelen);
-  int _win_connect (SOCKET s, const struct sockaddr *name, int namelen);
-  int _win_getpeername (SOCKET s, struct sockaddr *name, int *namelen);
-  int _win_getsockname (SOCKET s, struct sockaddr *name, int *namelen);
-  int _win_getsockopt (SOCKET s, int level, int optname, char *optval,
-                       int *optlen);
-  int _win_listen (SOCKET s, int backlog);
-  int _win_recv (SOCKET s, char *buf, int len, int flags);
-  int _win_recvfrom (SOCKET s, void *buf, int len, int flags,
-                     struct sockaddr *from, int *fromlen);
-  int _win_select (int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds,
-                   const struct timeval *tv);
-  int _win_send (SOCKET s, const char *buf, int len, int flags);
-  int _win_sendto (SOCKET s, const char *buf, int len, int flags,
-                   const struct sockaddr *to, int tolen);
-  int _win_setsockopt (SOCKET s, int level, int optname, const void *optval,
-                       int optlen);
-  int _win_shutdown (SOCKET s, int how);
-  SOCKET _win_socket (int af, int type, int protocol);
-  struct hostent *_win_gethostbyaddr (const char *addr, int len, int type);
-  struct hostent *_win_gethostbyname (const char *name);
-  struct hostent *gethostbyname2 (const char *name, int af);
-  char *_win_strerror (int errnum);
-  int IsWinNT ();
-  char *index (const char *s, int c);
-
 #if !HAVE_STRNDUP
-  char *strndup (const char *s, size_t n);
-
-#endif                          /*  */
+char *strndup (const char *s, size_t n);
+#endif
 #if !HAVE_STRNLEN
-  size_t strnlen (const char *str, size_t maxlen);
+size_t strnlen (const char *str, size_t maxlen);
+#endif
 
-#endif                          /*  */
-
 #define strcasecmp(a, b) stricmp(a, b)
 #define strncasecmp(a, b, c) strnicmp(a, b, c)
 
-#endif                          /* WINDOWS */
+#endif /* WINDOWS */
 
 #ifndef WINDOWS
-#define DIR_SEPARATOR '/'
-#define DIR_SEPARATOR_STR "/"
-#define PATH_SEPARATOR ';'
-#define PATH_SEPARATOR_STR ";"
-#define NEWLINE "\n"
+ #define DIR_SEPARATOR '/'
+ #define DIR_SEPARATOR_STR "/"
+ #define PATH_SEPARATOR ';'
+ #define PATH_SEPARATOR_STR ";"
+ #define NEWLINE "\n"
 
 #ifdef ENABLE_NLS
-#define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n)
-#endif                          /*  */
-#define CREAT(p, m) creat(p, m)
-#undef FOPEN
-#define FOPEN(f, m) fopen(f, m)
-#define FTRUNCATE(f, l) ftruncate(f, l)
-#define OPENDIR(d) opendir(d)
-#define OPEN open
-#define CHDIR(d) chdir(d)
-#define CLOSE(f) close(f)
-#define LSEEK(f, o, w) lseek(f, o, w)
-#define RMDIR(f) rmdir(f)
-#define ACCESS(p, m) access(p, m)
-#define CHMOD(f, p) chmod(f, p)
-#define FSTAT(h, b) fstat(h, b)
-#define PLIBC_KILL(p, s) kill(p, s)
-#define PIPE(h) pipe(h)
-#define REMOVE(p) remove(p)
-#define RENAME(o, n) rename(o, n)
-#define STAT(p, b) stat(p, b)
-#define STAT64(p, b) stat64(p, b)
-#define UNLINK(f) unlink(f)
-#define WRITE(f, b, n) write(f, b, n)
-#define READ(f, b, n) read(f, b, n)
-#define GN_FREAD(b, s, c, f) fread(b, s, c, f)
-#define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f)
-#define SYMLINK(a, b) symlink(a, b)
-#define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o)
-#define MUNMAP(s, l) munmap(s, l)
-#define STRERROR(i) strerror(i)
-#define RANDOM() random()
-#define READLINK(p, b, s) readlink(p, b, s)
-#define LSTAT(p, b) lstat(p, b)
-#define LSTAT64(p, b) lstat64(p, b)
-#define PRINTF printf
-#define FPRINTF fprintf
-#define VPRINTF(f, a) vprintf(f, a)
-#define VFPRINTF(s, f, a) vfprintf(s, f, a)
-#define VSPRINTF(d, f, a) vsprintf(d, f, a)
-#define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
-#define _REAL_SNPRINTF snprintf
-#define SPRINTF sprintf
-#define VSSCANF(s, f, a) vsscanf(s, f, a)
-#define SSCANF sscanf
-#define VFSCANF(s, f, a) vfscanf(s, f, a)
-#define VSCANF(f, a) vscanf(f, a)
-#define SCANF scanf
-#define FSCANF fscanf
-#define WAITPID(p, s, o) waitpid(p, s, o)
-#define ACCEPT(s, a, l) accept(s, a, l)
-#define BIND(s, n, l) bind(s, n, l)
-#define CONNECT(s, n, l) connect(s, n, l)
-#define GETPEERNAME(s, n, l) getpeername(s, n, l)
-#define GETSOCKNAME(s, n, l) getsockname(s, n, l)
-#define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p)
-#define LISTEN(s, b) listen(s, b)
-#define RECV(s, b, l, f) recv(s, b, l, f)
-#define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o)
-#define SELECT(n, r, w, e, t) select(n, r, w, e, t)
-#define SEND(s, b, l, f) send(s, b, l, f)
-#define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n)
-#define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n)
-#define SHUTDOWN(s, h) shutdown(s, h)
-#define SOCKET(a, t, p) socket(a, t, p)
-#define GETHOSTBYADDR(a, l, t) gethostbyname(a, l, t)
-#define GETHOSTBYNAME(n) gethostbyname(n)
-#else                           /*  */
-#define DIR_SEPARATOR '\\'
-#define DIR_SEPARATOR_STR "\\"
-#define PATH_SEPARATOR ':'
-#define PATH_SEPARATOR_STR ":"
-#define NEWLINE "\r\n"
+ #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n)
+#endif
+ #define CREAT(p, m) creat(p, m)
+ #define PLIBC_CTIME(c) ctime(c)
+ #define CTIME_R(c, b) ctime_r(c, b)
+ #undef FOPEN
+ #define FOPEN(f, m) fopen(f, m)
+ #define FTRUNCATE(f, l) ftruncate(f, l)
+ #define OPENDIR(d) opendir(d)
+ #define OPEN open
+ #define CHDIR(d) chdir(d)
+ #define CLOSE(f) close(f)
+ #define LSEEK(f, o, w) lseek(f, o, w)
+ #define RMDIR(f) rmdir(f)
+ #define ACCESS(p, m) access(p, m)
+ #define CHMOD(f, p) chmod(f, p)
+ #define FSTAT(h, b) fstat(h, b)
+ #define PLIBC_KILL(p, s) kill(p, s)
+ #define PIPE(h) pipe(h)
+ #define REMOVE(p) remove(p)
+ #define RENAME(o, n) rename(o, n)
+ #define STAT(p, b) stat(p, b)
+ #define STAT64(p, b) stat64(p, b)
+ #define UNLINK(f) unlink(f)
+ #define WRITE(f, b, n) write(f, b, n)
+ #define READ(f, b, n) read(f, b, n)
+ #define GN_FREAD(b, s, c, f) fread(b, s, c, f)
+ #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f)
+ #define SYMLINK(a, b) symlink(a, b)
+ #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o)
+ #define MUNMAP(s, l) munmap(s, l)
+ #define STRERROR(i) strerror(i)
+ #define RANDOM() random()
+ #define READLINK(p, b, s) readlink(p, b, s)
+ #define LSTAT(p, b) lstat(p, b)
+ #define LSTAT64(p, b) lstat64(p, b)
+ #define PRINTF printf
+ #define FPRINTF fprintf
+ #define VPRINTF(f, a) vprintf(f, a)
+ #define VFPRINTF(s, f, a) vfprintf(s, f, a)
+ #define VSPRINTF(d, f, a) vsprintf(d, f, a)
+ #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
+ #define _REAL_SNPRINTF snprintf
+ #define SPRINTF sprintf
+ #define VSSCANF(s, f, a) vsscanf(s, f, a)
+ #define SSCANF sscanf
+ #define VFSCANF(s, f, a) vfscanf(s, f, a)
+ #define VSCANF(f, a) vscanf(f, a)
+ #define SCANF scanf
+ #define FSCANF fscanf
+ #define WAITPID(p, s, o) waitpid(p, s, o)
+ #define ACCEPT(s, a, l) accept(s, a, l)
+ #define BIND(s, n, l) bind(s, n, l)
+ #define CONNECT(s, n, l) connect(s, n, l)
+ #define GETPEERNAME(s, n, l) getpeername(s, n, l)
+ #define GETSOCKNAME(s, n, l) getsockname(s, n, l)
+ #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p)
+ #define LISTEN(s, b) listen(s, b)
+ #define RECV(s, b, l, f) recv(s, b, l, f)
+ #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o)
+ #define SELECT(n, r, w, e, t) select(n, r, w, e, t)
+ #define SEND(s, b, l, f) send(s, b, l, f)
+ #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n)
+ #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n)
+ #define SHUTDOWN(s, h) shutdown(s, h)
+ #define SOCKET(a, t, p) socket(a, t, p)
+ #define GETHOSTBYADDR(a, l, t) gethostbyname(a, l, t)
+ #define GETHOSTBYNAME(n) gethostbyname(n)
+ #define GETTIMEOFDAY(t, n) gettimeofday(t, n)
+ #define INSQUE(e, p) insque(e, p)
+ #define REMQUE(e) remque(e)
+ #define HSEARCH(i, a) hsearch(i, a)
+ #define HCREATE(n) hcreate(n)
+ #define HDESTROY() hdestroy()
+ #define HSEARCH_R(i, a, r, h) hsearch_r(i, a, r, h)
+ #define HCREATE_R(n, h) hcreate_r(n, h)
+ #define HDESTROY_R(h) hdestroy_r(h)
+ #define TSEARCH(k, r, c) tsearch(k, r, c)
+ #define TFIND(k, r, c) tfind(k, r, c)
+ #define TDELETE(k, r, c) tdelete(k, r, c)
+ #define TWALK(r, a) twalk(r, a)
+ #define TDESTROY(r, f) tdestroy(r, f)
+ #define LFIND(k, b, n, s, c) lfind(k, b, n, s, c)
+ #define LSEARCH(k, b, n, s, c) lsearch(k, b, n, s, c)
+#else
+ #define DIR_SEPARATOR '\\'
+ #define DIR_SEPARATOR_STR "\\"
+ #define PATH_SEPARATOR ':'
+ #define PATH_SEPARATOR_STR ":"
+ #define NEWLINE "\r\n"
 
 #ifdef ENABLE_NLS
-#define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n)
-#endif                          /*  */
-#define CREAT(p, m) _win_creat(p, m)
-#define FOPEN(f, m) _win_fopen(f, m)
-#define FTRUNCATE(f, l) _win_ftruncate(f, l)
-#define OPENDIR(d) _win_opendir(d)
-#define OPEN _win_open
-#define CHDIR(d) _win_chdir(d)
-#define CLOSE(f) _win_close(f)
-#define PLIBC_KILL(p, s) _win_kill(p, s)
-#define LSEEK(f, o, w) _win_lseek(f, o, w)
-#define FSTAT(h, b) _win_fstat(h, b)
-#define RMDIR(f) _win_rmdir(f)
-#define ACCESS(p, m) _win_access(p, m)
-#define CHMOD(f, p) _win_chmod(f, p)
-#define PIPE(h) _win_pipe(h)
-#define RANDOM() _win_random()
-#define REMOVE(p) _win_remove(p)
-#define RENAME(o, n) _win_rename(o, n)
-#define STAT(p, b) _win_stat(p, b)
-#define STAT64(p, b) _win_stat64(p, b)
-#define UNLINK(f) _win_unlink(f)
-#define WRITE(f, b, n) _win_write(f, b, n)
-#define READ(f, b, n) _win_read(f, b, n)
-#define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f)
-#define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f)
-#define SYMLINK(a, b) _win_symlink(a, b)
-#define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o)
-#define MUNMAP(s, l) _win_munmap(s, l)
-#define STRERROR(i) _win_strerror(i)
-#define READLINK(p, b, s) _win_readlink(p, b, s)
-#define LSTAT(p, b) _win_lstat(p, b)
-#define LSTAT64(p, b) _win_lstat64(p, b)
-#define PRINTF(f, ...) _win_printf(f , __VA_ARGS__)
-#define FPRINTF(fil, fmt, ...) _win_fprintf(fil, fmt, __VA_ARGS__)
-#define VPRINTF(f, a) _win_vprintf(f, a)
-#define VFPRINTF(s, f, a) _win_vfprintf(s, f, a)
-#define VSPRINTF(d, f, a) _win_vsprintf(d, f, a)
-#define VSNPRINTF(str, size, fmt, a) _win_vsnprintf(str, size, fmt, a)
-#define _REAL_SNPRINTF(str, size, fmt, ...) _win_snprintf(str, size, fmt, 
__VA_ARGS__)
-#define SPRINTF(d, f, ...) _win_sprintf(d, f, __VA_ARGS__)
-#define VSSCANF(s, f, a) _win_vsscanf(s, f, a)
-#define SSCANF(s, f, ...) _win_sscanf(s, f, __VA_ARGS__)
-#define VFSCANF(s, f, a) _win_vfscanf(s, f, a)
-#define VSCANF(f, a) _win_vscanf(f, a)
-#define SCANF(f, ...) _win_scanf(f, __VA_ARGS__)
-#define FSCANF(s, f, ...) _win_fscanf(s, f, __VA_ARGS__)
-#define WAITPID(p, s, o) _win_waitpid(p, s, o)
-#define ACCEPT(s, a, l) _win_accept(s, a, l)
-#define BIND(s, n, l) _win_bind(s, n, l)
-#define CONNECT(s, n, l) _win_connect(s, n, l)
-#define GETPEERNAME(s, n, l) _win_getpeername(s, n, l)
-#define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l)
-#define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p)
-#define LISTEN(s, b) _win_listen(s, b)
-#define RECV(s, b, l, f) _win_recv(s, b, l, f)
-#define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o)
-#define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t)
-#define SEND(s, b, l, f) _win_send(s, b, l, f)
-#define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n)
-#define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n)
-#define SHUTDOWN(s, h) _win_shutdown(s, h)
-#define SOCKET(a, t, p) _win_socket(a, t, p)
-#define GETHOSTBYADDR(a, l, t) _win_gethostbyname(a, l, t)
-#define GETHOSTBYNAME(n) _win_gethostbyname(n)
-#endif                          /*  */
+ #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n)
+#endif
+ #define CREAT(p, m) _win_creat(p, m)
+ #define PLIBC_CTIME(c) _win_ctime(c)
+ #define CTIME_R(c, b) _win_ctime_r(c, b)
+ #define FOPEN(f, m) _win_fopen(f, m)
+ #define FTRUNCATE(f, l) _win_ftruncate(f, l)
+ #define OPENDIR(d) _win_opendir(d)
+ #define OPEN _win_open
+ #define CHDIR(d) _win_chdir(d)
+ #define CLOSE(f) _win_close(f)
+ #define PLIBC_KILL(p, s) _win_kill(p, s)
+ #define LSEEK(f, o, w) _win_lseek(f, o, w)
+ #define FSTAT(h, b) _win_fstat(h, b)
+ #define RMDIR(f) _win_rmdir(f)
+ #define ACCESS(p, m) _win_access(p, m)
+ #define CHMOD(f, p) _win_chmod(f, p)
+ #define PIPE(h) _win_pipe(h)
+ #define RANDOM() _win_random()
+ #define REMOVE(p) _win_remove(p)
+ #define RENAME(o, n) _win_rename(o, n)
+ #define STAT(p, b) _win_stat(p, b)
+ #define STAT64(p, b) _win_stat64(p, b)
+ #define UNLINK(f) _win_unlink(f)
+ #define WRITE(f, b, n) _win_write(f, b, n)
+ #define READ(f, b, n) _win_read(f, b, n)
+ #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f)
+ #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f)
+ #define SYMLINK(a, b) _win_symlink(a, b)
+ #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o)
+ #define MUNMAP(s, l) _win_munmap(s, l)
+ #define STRERROR(i) _win_strerror(i)
+ #define READLINK(p, b, s) _win_readlink(p, b, s)
+ #define LSTAT(p, b) _win_lstat(p, b)
+ #define LSTAT64(p, b) _win_lstat64(p, b)
+ #define PRINTF(f, ...) _win_printf(f , __VA_ARGS__)
+ #define FPRINTF(fil, fmt, ...) _win_fprintf(fil, fmt, __VA_ARGS__)
+ #define VPRINTF(f, a) _win_vprintf(f, a)
+ #define VFPRINTF(s, f, a) _win_vfprintf(s, f, a)
+ #define VSPRINTF(d, f, a) _win_vsprintf(d, f, a)
+ #define VSNPRINTF(str, size, fmt, a) _win_vsnprintf(str, size, fmt, a)
+ #define _REAL_SNPRINTF(str, size, fmt, ...) _win_snprintf(str, size, fmt, 
__VA_ARGS__)
+ #define SPRINTF(d, f, ...) _win_sprintf(d, f, __VA_ARGS__)
+ #define VSSCANF(s, f, a) _win_vsscanf(s, f, a)
+ #define SSCANF(s, f, ...) _win_sscanf(s, f, __VA_ARGS__)
+ #define VFSCANF(s, f, a) _win_vfscanf(s, f, a)
+ #define VSCANF(f, a) _win_vscanf(f, a)
+ #define SCANF(f, ...) _win_scanf(f, __VA_ARGS__)
+ #define FSCANF(s, f, ...) _win_fscanf(s, f, __VA_ARGS__)
+ #define WAITPID(p, s, o) _win_waitpid(p, s, o)
+ #define ACCEPT(s, a, l) _win_accept(s, a, l)
+ #define BIND(s, n, l) _win_bind(s, n, l)
+ #define CONNECT(s, n, l) _win_connect(s, n, l)
+ #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l)
+ #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l)
+ #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p)
+ #define LISTEN(s, b) _win_listen(s, b)
+ #define RECV(s, b, l, f) _win_recv(s, b, l, f)
+ #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o)
+ #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t)
+ #define SEND(s, b, l, f) _win_send(s, b, l, f)
+ #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n)
+ #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n)
+ #define SHUTDOWN(s, h) _win_shutdown(s, h)
+ #define SOCKET(a, t, p) _win_socket(a, t, p)
+ #define GETHOSTBYADDR(a, l, t) _win_gethostbyname(a, l, t)
+ #define GETHOSTBYNAME(n) _win_gethostbyname(n)
+ #define GETTIMEOFDAY(t, n) _win_gettimeofday(t, n)
+ #define INSQUE(e, p) _win_insque(e, p)
+ #define REMQUE(e) _win_remque(e)
+ #define HSEARCH(i, a) _win_hsearch(i, a)
+ #define HCREATE(n) _win_hcreate(n)
+ #define HDESTROY() _win_hdestroy()
+ #define HSEARCH_R(i, a, r, h) _win_hsearch_r(i, a, r, h)
+ #define HCREATE_R(n, h) _win_hcreate_r(n, h)
+ #define HDESTROY_R(h) _win_hdestroy_r(h)
+ #define TSEARCH(k, r, c) _win_tsearch(k, r, c)
+ #define TFIND(k, r, c) _win_tfind(k, r, c)
+ #define TDELETE(k, r, c) _win_tdelete(k, r, c)
+ #define TWALK(r, a) _win_twalk(r, a)
+ #define TDESTROY(r, f) _win_tdestroy(r, f)
+ #define LFIND(k, b, n, s, c) _win_lfind(k, b, n, s, c)
+ #define LSEARCH(k, b, n, s, c) _win_lsearch(k, b, n, s, c)
+#endif
 
+/* search.h */
+
+/* Prototype structure for a linked-list data structure.
+   This is the type used by the `insque' and `remque' functions.  */
+
+struct PLIBC_SEARCH_QELEM
+  {
+    struct qelem *q_forw;
+    struct qelem *q_back;
+    char q_data[1];
+  };
+
+
+/* Insert ELEM into a doubly-linked list, after PREV.  */
+void _win_insque (void *__elem, void *__prev);
+
+/* Unlink ELEM from the doubly-linked list that it is in.  */
+void _win_remque (void *__elem);
+
+
+/* For use with hsearch(3).  */
+typedef int (*PLIBC_SEARCH__compar_fn_t) (__const void *, __const void *);
+
+typedef PLIBC_SEARCH__compar_fn_t _win_comparison_fn_t;
+
+/* Action which shall be performed in the call the hsearch.  */
+typedef enum
+  {
+    PLIBC_SEARCH_FIND,
+    PLIBC_SEARCH_ENTER
+  }
+PLIBC_SEARCH_ACTION;
+
+typedef struct PLIBC_SEARCH_entry
+  {
+    char *key;
+    void *data;
+  }
+PLIBC_SEARCH_ENTRY;
+
+/* The reentrant version has no static variables to maintain the state.
+   Instead the interface of all functions is extended to take an argument
+   which describes the current status.  */
+typedef struct _PLIBC_SEARCH_ENTRY
+{
+  unsigned int used;
+  PLIBC_SEARCH_ENTRY entry;
+}
+_PLIBC_SEARCH_ENTRY;
+
+
+/* Family of hash table handling functions.  The functions also
+   have reentrant counterparts ending with _r.  The non-reentrant
+   functions all work on a signle internal hashing table.  */
+
+/* Search for entry matching ITEM.key in internal hash table.  If
+   ACTION is `FIND' return found entry or signal error by returning
+   NULL.  If ACTION is `ENTER' replace existing data (if any) with
+   ITEM.data.  */
+PLIBC_SEARCH_ENTRY *_win_hsearch (PLIBC_SEARCH_ENTRY __item, 
PLIBC_SEARCH_ACTION __action);
+
+/* Create a new hashing table which will at most contain NEL elements.  */
+int _win_hcreate (size_t __nel);
+
+/* Destroy current internal hashing table.  */
+void _win_hdestroy (void);
+
+/* Data type for reentrant functions.  */
+struct PLIBC_SEARCH_hsearch_data
+  {
+    struct _PLIBC_SEARCH_ENTRY *table;
+    unsigned int size;
+    unsigned int filled;
+  };
+
+/* Reentrant versions which can handle multiple hashing tables at the
+   same time.  */
+int _win_hsearch_r (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action, 
PLIBC_SEARCH_ENTRY **__retval,
+          struct PLIBC_SEARCH_hsearch_data *__htab);
+int _win_hcreate_r (size_t __nel, struct PLIBC_SEARCH_hsearch_data *__htab);
+void _win_hdestroy_r (struct PLIBC_SEARCH_hsearch_data *__htab);
+
+
+/* The tsearch routines are very interesting. They make many
+   assumptions about the compiler.  It assumes that the first field
+   in node must be the "key" field, which points to the datum.
+   Everything depends on that.  */
+/* For tsearch */
+typedef enum
+{
+  PLIBC_SEARCH_preorder,
+  PLIBC_SEARCH_postorder,
+  PLIBC_SEARCH_endorder,
+  PLIBC_SEARCH_leaf
+}
+PLIBC_SEARCH_VISIT;
+
+/* Search for an entry matching the given KEY in the tree pointed to
+   by *ROOTP and insert a new element if not found.  */
+void *_win_tsearch (__const void *__key, void **__rootp,
+          PLIBC_SEARCH__compar_fn_t __compar);
+
+/* Search for an entry matching the given KEY in the tree pointed to
+   by *ROOTP.  If no matching entry is available return NULL.  */
+void *_win_tfind (__const void *__key, void *__const *__rootp,
+        PLIBC_SEARCH__compar_fn_t __compar);
+
+/* Remove the element matching KEY from the tree pointed to by *ROOTP.  */
+void *_win_tdelete (__const void *__restrict __key,
+          void **__restrict __rootp,
+          PLIBC_SEARCH__compar_fn_t __compar);
+
+typedef void (*PLIBC_SEARCH__action_fn_t) (__const void *__nodep, 
PLIBC_SEARCH_VISIT __value,
+             int __level);
+
+/* Walk through the whole tree and call the ACTION callback for every node
+   or leaf.  */
+void _win_twalk (__const void *__root, PLIBC_SEARCH__action_fn_t __action);
+
+/* Callback type for function to free a tree node.  If the keys are atomic
+   data this function should do nothing.  */
+typedef void (*PLIBC_SEARCH__free_fn_t) (void *__nodep);
+
+/* Destroy the whole tree, call FREEFCT for each node or leaf.  */
+void _win_tdestroy (void *__root, PLIBC_SEARCH__free_fn_t __freefct);
+
+
+/* Perform linear search for KEY by comparing by COMPAR in an array
+   [BASE,BASE+NMEMB*SIZE).  */
+void *_win_lfind (__const void *__key, __const void *__base,
+        size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar);
+
+/* Perform linear search for KEY by comparing by COMPAR function in
+   array [BASE,BASE+NMEMB*SIZE) and insert entry if not found.  */
+void *_win_lsearch (__const void *__key, void *__base,
+          size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar);
+
+
 #ifdef __cplusplus
 }
-#endif                          /*  */
+#endif
 
-#endif                          //_PLIBC_H_
 
+#endif //_PLIBC_H_
+
 /* end of plibc.h */

Modified: gnunet/src/util/Makefile.am
===================================================================
--- gnunet/src/util/Makefile.am 2009-06-10 18:48:17 UTC (rev 8540)
+++ gnunet/src/util/Makefile.am 2009-06-10 22:24:54 UTC (rev 8541)
@@ -4,6 +4,7 @@
 
 if MINGW
  WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols -lole32 -lshell32 
-luuid -liconv -lstdc++ -lcomdlg32 -lgdi32
+ WINSRC = win.cc winproc.c
 endif
 
 if USE_COVERAGE
@@ -45,7 +46,8 @@
   service.c \
   signal.c \
   strings.c \
-  time.c
+  time.c \
+  $(WINSRC)
 
 
 libgnunetutil_la_LIBADD = \

Modified: gnunet/src/util/crypto_rsa.c
===================================================================
--- gnunet/src/util/crypto_rsa.c        2009-06-10 18:48:17 UTC (rev 8540)
+++ gnunet/src/util/crypto_rsa.c        2009-06-10 22:24:54 UTC (rev 8541)
@@ -559,7 +559,10 @@
 struct GNUNET_CRYPTO_RsaPrivateKey *
 GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
 {
+#ifndef MINGW
+  // FIXME NILS
   struct flock fl;
+#endif
   struct GNUNET_CRYPTO_RsaPrivateKey *ret;
   struct RsaPrivateKeyBinaryEncoded *enc;
   struct stat sbuf;
@@ -581,11 +584,13 @@
                                     "open", filename);
           return NULL;
         }
+#ifndef MINGW
       memset (&fl, 0, sizeof (struct flock));
       fl.l_type = F_WRLCK;
       fl.l_whence = SEEK_SET;
       fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded);
       cnt = 0;
+
       while (0 != fcntl (fd, F_SETLK, &fl))
         {
           sleep (1);
@@ -604,6 +609,7 @@
           fl.l_whence = SEEK_SET;
           fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded);
         }
+#endif
       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                   _("Creating a new private key.  This may take a while.\n"));
       ret = GNUNET_CRYPTO_rsa_key_create ();
@@ -612,6 +618,7 @@
       GNUNET_assert (enc != NULL);
       GNUNET_assert (ntohs (enc->len) == WRITE (fd, enc, ntohs (enc->len)));
       GNUNET_free (enc);
+#ifndef MINGW
       fdatasync (fd);
       memset (&fl, 0, sizeof (struct flock));
       fl.l_type = F_UNLCK;
@@ -621,6 +628,7 @@
       if (0 != fcntl (fd, F_SETLK, &fl))
         GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
                                   "fcntl", filename);
+#endif
       GNUNET_assert (0 == CLOSE (fd));
       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                   _("Stored new private key in `%s'.\n"), filename);
@@ -636,6 +644,7 @@
   cnt = 0;
   while (1)
     {
+#ifndef MINGW
       memset (&fl, 0, sizeof (struct flock));
       fl.l_type = F_RDLCK;
       fl.l_whence = SEEK_SET;
@@ -658,11 +667,13 @@
           sleep (1);
           continue;
         }
+#endif
       if (0 != STAT (filename, &sbuf))
         {
           /* eh, what!? File we opened is now gone!? */
           GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
                                     "stat", filename);
+#ifndef MINGW
           memset (&fl, 0, sizeof (struct flock));
           fl.l_type = F_UNLCK;
           fl.l_whence = SEEK_SET;
@@ -671,10 +682,12 @@
             GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
                                       "fcntl", filename);
           GNUNET_assert (0 == CLOSE (fd));
+#endif
           return NULL;
         }
       if (sbuf.st_size < sizeof (struct RsaPrivateKeyBinaryEncoded))
         {
+#ifndef MINGW
           /* maybe we got the read lock before the hostkey generating
              process had a chance to get the write lock; give it up! */
           memset (&fl, 0, sizeof (struct flock));
@@ -698,6 +711,7 @@
             }
           sleep (2);            /* wait a bit longer! */
           continue;
+#endif
         }
       break;
     }
@@ -713,12 +727,14 @@
                   filename);
       GNUNET_free (enc);
     }
+#ifndef MINGW
   memset (&fl, 0, sizeof (struct flock));
   fl.l_type = F_UNLCK;
   fl.l_whence = SEEK_SET;
   fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded);
   if (0 != fcntl (fd, F_SETLK, &fl))
     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
+#endif
   GNUNET_assert (0 == CLOSE (fd));
   return ret;
 }

Modified: gnunet/src/util/disk.c
===================================================================
--- gnunet/src/util/disk.c      2009-06-10 18:48:17 UTC (rev 8540)
+++ gnunet/src/util/disk.c      2009-06-10 22:24:54 UTC (rev 8541)
@@ -157,7 +157,7 @@
   szDrive[3] = 0;
   if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy))
     {
-      GNUNET_GE_LOG (GNUNET_ERROR_TYPE_WARNING,
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                      _("`%s' failed for drive `%s': %u\n"),
                      "GetDiskFreeSpace", szDrive, GetLastError ());
 

Modified: gnunet/src/util/network.c
===================================================================
--- gnunet/src/util/network.c   2009-06-10 18:48:17 UTC (rev 8540)
+++ gnunet/src/util/network.c   2009-06-10 22:24:54 UTC (rev 8541)
@@ -249,9 +249,12 @@
       GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "accept");
       return NULL;
     }
+#ifndef MINGW
+  // FIXME NILS
   if (0 != fcntl (fd, F_SETFD, fcntl (fd, F_GETFD) | FD_CLOEXEC))
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
                          "fcntl");
+#endif
   if (addrlen > sizeof (addr))
     {
       GNUNET_break (0);
@@ -287,7 +290,7 @@
       if (aret == GNUNET_NO)
        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                    _("Access denied to `%s'\n"),
-                   GNUNET_a2s(uaddr, addrlen));        
+                   GNUNET_a2s(uaddr, addrlen));
       GNUNET_break (0 == SHUTDOWN (fd, SHUT_RDWR));
       GNUNET_break (0 == CLOSE (fd));
       GNUNET_free (uaddr);
@@ -432,9 +435,12 @@
           sock->ai_pos = sock->ai_pos->ai_next;
           continue;
         }
+#ifndef MINGW
+      // FIXME NILS
       if (0 != fcntl (s, F_SETFD, fcntl (s, F_GETFD) | FD_CLOEXEC))
         GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
                              "fcntl");
+#endif
       if (GNUNET_SYSERR == socket_set_blocking (s, GNUNET_NO))
         {
           /* we'll treat this one as fatal */
@@ -524,7 +530,7 @@
     }
   /* connect succeeded! clean up "ai" */
 #if DEBUG_NETWORK
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Connection to `%s' succeeded!\n",
              GNUNET_a2s(sock->addr, sock->addrlen));
 #endif
@@ -619,9 +625,11 @@
                            GNUNET_ERROR_TYPE_BULK, "socket");
       return NULL;
     }
+#ifndef MINGW
   if (0 != fcntl (s, F_SETFD, fcntl (s, F_GETFD) | FD_CLOEXEC))
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
                          "fcntl");
+#endif
   if (GNUNET_SYSERR == socket_set_blocking (s, GNUNET_NO))
     {
       /* we'll treat this one as fatal */
@@ -712,7 +720,7 @@
         }
     }
   if (sock->sock != -1)
-    GNUNET_break (0 == CLOSE (sock->sock));    
+    GNUNET_break (0 == CLOSE (sock->sock));
   GNUNET_free_non_null (sock->addr);
   if (sock->ai != NULL)
     freeaddrinfo (sock->ai);
@@ -810,7 +818,14 @@
     }
   GNUNET_assert (FD_ISSET (sh->sock, tc->read_ready));
 RETRY:
-  ret = RECV (sh->sock, buffer, sh->max, MSG_DONTWAIT);
+  ret = RECV (sh->sock, buffer, sh->max,
+#ifndef MINGW
+      // FIXME MINGW
+      MSG_DONTWAIT
+#else
+      0
+#endif
+      );
   if (ret == -1)
     {
       if (errno == EINTR)
@@ -825,7 +840,7 @@
 #if DEBUG_NETWORK
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "receive_ready read %u/%u bytes from `%s'!\n",
-             (unsigned int) ret, 
+             (unsigned int) ret,
              sh->max,
              GNUNET_a2s(sh->addr, sh->addrlen));
 #endif
@@ -889,7 +904,7 @@
                                             GNUNET_TIME_absolute_get_remaining
                                             (sh->receive_timeout),
                                             sh->sock, &receive_ready,
-                                            sh);   
+                                            sh);
 }
 
 
@@ -1086,7 +1101,14 @@
 RETRY:
   ret = SEND (sock->sock,
               &sock->write_buffer[sock->write_buffer_pos],
-              have, MSG_DONTWAIT | MSG_NOSIGNAL);
+              have,
+#ifndef MINGW
+              // FIXME NILS
+              MSG_DONTWAIT | MSG_NOSIGNAL
+#else
+              0
+#endif
+  );
   if (ret == -1)
     {
       if (errno == EINTR)

Modified: gnunet/src/util/os_priority.c
===================================================================
--- gnunet/src/util/os_priority.c       2009-06-10 18:48:17 UTC (rev 8540)
+++ gnunet/src/util/os_priority.c       2009-06-10 22:24:54 UTC (rev 8541)
@@ -123,9 +123,11 @@
 pid_t
 GNUNET_OS_start_process (const char *filename, ...)
 {
+  va_list ap;
+
+#ifndef MINGW
   pid_t ret;
   char **argv;
-  va_list ap;
   int argc;
 
   ret = fork ();
@@ -149,6 +151,42 @@
   execvp (filename, argv);
   GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
   exit (1);
+#else
+  char *arg;
+  unsigned int cmdlen;
+  char *cmd, *idx;
+  STARTUPINFO start;
+  PROCESS_INFORMATION proc;
+
+  cmdlen = 0;
+  va_start (ap, filename);
+  while (NULL != (arg = va_arg (ap, char *)))
+    cmdlen = cmdlen + strlen (arg) + 3;
+  va_end (ap);
+
+  cmd = idx = GNUNET_malloc (sizeof(char) * cmdlen);
+  va_start (ap, filename);
+  while (NULL != (arg = va_arg (ap, char *)))
+    idx += sprintf (idx, "\"%s\" ", arg);
+  va_end (ap);
+
+  memset (&start, 0, sizeof(start));
+  start.cb = sizeof(start);
+
+  if (!CreateProcess (filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL,
+      NULL, &start, &proc))
+  {
+    SetErrnoFromWinError (GetLastError ());
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
+    return -1;
+  }
+  CloseHandle (proc.hProcess);
+  CloseHandle (proc.hThread);
+
+  GNUNET_free(cmd);
+
+  return proc.dwProcessId;
+#endif
 }
 
 
@@ -164,6 +202,7 @@
 pid_t
 GNUNET_OS_start_process_v (const char *filename, char *const argv[])
 {
+#ifndef MINGW
   pid_t ret;
 
   ret = fork ();
@@ -176,6 +215,46 @@
   execvp (filename, argv);
   GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
   exit (1);
+#else
+  char **arg;
+  unsigned int cmdlen;
+  char *cmd, *idx;
+  STARTUPINFO start;
+  PROCESS_INFORMATION proc;
+
+  cmdlen = 0;
+  arg = argv;
+  while (*arg)
+  {
+    cmdlen = cmdlen + strlen (*arg) + 3;
+    arg++;
+  }
+
+  cmd = idx = GNUNET_malloc (sizeof(char) * cmdlen);
+  arg = argv;
+  while (*arg)
+  {
+    idx += sprintf (idx, "\"%s\" ", *arg);
+    arg++;
+  }
+
+  memset (&start, 0, sizeof(start));
+  start.cb = sizeof(start);
+
+  if (!CreateProcess (filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL,
+      NULL, &start, &proc))
+  {
+    SetErrnoFromWinError (GetLastError ());
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
+    return -1;
+  }
+  CloseHandle (proc.hProcess);
+  CloseHandle (proc.hThread);
+
+  GNUNET_free(cmd);
+
+  return proc.dwProcessId;
+#endif
 }
 
 

Modified: gnunet/src/util/scheduler.c
===================================================================
--- gnunet/src/util/scheduler.c 2009-06-10 18:48:17 UTC (rev 8540)
+++ gnunet/src/util/scheduler.c 2009-06-10 22:24:54 UTC (rev 8541)
@@ -470,10 +470,12 @@
   struct Task *tpos;
 
   sig_shutdown = 0;
+#ifndef MINGW
   shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown);
   shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown);
   shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT, &sighandler_shutdown);
   shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP, &sighandler_shutdown);
+#endif
   memset (&sched, 0, sizeof (sched));
   sched.current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
   GNUNET_SCHEDULER_add_continuation (&sched,

Modified: gnunet/src/util/server.c
===================================================================
--- gnunet/src/util/server.c    2009-06-10 18:48:17 UTC (rev 8540)
+++ gnunet/src/util/server.c    2009-06-10 22:24:54 UTC (rev 8541)
@@ -379,9 +379,12 @@
       GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
       return -1;
     }
+#ifndef MINGW
+  // FIXME NILS
   if (0 != fcntl (fd, F_SETFD, fcntl (fd, F_GETFD) | FD_CLOEXEC))
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
                          "fcntl");
+#endif
   if (SETSOCKOPT (fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0)
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
                          "setsockopt");

Modified: gnunet/src/util/time.c
===================================================================
--- gnunet/src/util/time.c      2009-06-10 18:48:17 UTC (rev 8540)
+++ gnunet/src/util/time.c      2009-06-10 22:24:54 UTC (rev 8541)
@@ -39,7 +39,7 @@
   struct GNUNET_TIME_Absolute ret;
   struct timeval tv;
 
-  gettimeofday (&tv, NULL);
+  GETTIMEOFDAY (&tv, NULL);
   ret.value = tv.tv_sec * 1000 + tv.tv_usec / 1000;
   return ret;
 }

Copied: gnunet/src/util/win.cc (from rev 8477, GNUnet/src/util/win/win.cc)
===================================================================
--- gnunet/src/util/win.cc                              (rev 0)
+++ gnunet/src/util/win.cc      2009-06-10 22:24:54 UTC (rev 8541)
@@ -0,0 +1,828 @@
+/*
+     This file is part of GNUnet.
+     (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other 
contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file util/win/win.cc
+ * @brief Helper functions for MS Windows in C++
+ * @author Nils Durner
+ **/
+
+#ifndef _WIN_CC
+#define _WIN_CC
+
+#include "winproc.h"
+#include "platform.h"
+#include "gnunet_common.h"
+#include "gnunet_network_lib.h"
+
+#include <list>
+using namespace std;
+#include <ntdef.h>
+
+#ifndef INHERITED_ACE
+#define INHERITED_ACE 0x10
+#endif
+
+extern "C" {
+
+typedef list<WSAOVERLAPPED *> TOLList;
+
+static HANDLE hOLLock;
+static TOLList lstOL;
+
+int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows);
+
+void __attribute__ ((constructor)) gnunet_win_init() {
+  hOLLock = CreateMutex(NULL, FALSE, NULL);
+}
+
+void __attribute__ ((destructor)) gnunet_win_fini() {
+  CloseHandle(hOLLock);
+}
+
+/**
+ * Enumerate all network adapters
+ */
+void EnumNICs(PMIB_IFTABLE *pIfTable, PMIB_IPADDRTABLE *pAddrTable)
+{
+  DWORD dwSize, dwRet;
+
+  *pIfTable = NULL;
+
+  if (pAddrTable)
+    *pAddrTable = NULL;
+
+  if (GNGetIfTable)
+  {
+    dwSize = dwRet = 0;
+
+    *pIfTable = (MIB_IFTABLE *) GlobalAlloc(GPTR, sizeof(MIB_IFTABLE));
+
+    /* Get size of table */
+    if (GNGetIfTable(*pIfTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER)
+    {
+      GlobalFree(*pIfTable);
+      *pIfTable = (MIB_IFTABLE *) GlobalAlloc(GPTR, dwSize);
+    }
+
+    if ((dwRet = GNGetIfTable(*pIfTable, &dwSize, 0)) == NO_ERROR &&
+      pAddrTable)
+    {
+      DWORD dwIfIdx, dwSize = sizeof(MIB_IPADDRTABLE);
+      *pAddrTable = (MIB_IPADDRTABLE *) GlobalAlloc(GPTR, dwSize);
+
+      /* Make an initial call to GetIpAddrTable to get the
+         necessary size */
+      if (GNGetIpAddrTable(*pAddrTable, &dwSize, 0) == 
ERROR_INSUFFICIENT_BUFFER)
+      {
+        GlobalFree(*pAddrTable);
+        *pAddrTable = (MIB_IPADDRTABLE *) GlobalAlloc(GPTR, dwSize);
+      }
+      GNGetIpAddrTable(*pAddrTable, &dwSize, 0);
+    }
+  }
+}
+
+/**
+ * Lists all network interfaces in a combo box
+ * Used by the basic GTK configurator
+ * @param callback
+ */
+  int ListNICs(void (*callback) (const char *, int, void *), void * cls)
+{
+  PMIB_IFTABLE pTable;
+  PMIB_IPADDRTABLE pAddrTable;
+  DWORD dwIfIdx, dwExternalNIC;
+  IPAddr theIP;
+
+  /* Determine our external NIC  */
+  theIP = inet_addr("192.0.34.166"); /* www.example.com */
+  if ((! GNGetBestInterface) ||
+      (GNGetBestInterface(theIP, &dwExternalNIC) != NO_ERROR))
+  {
+    dwExternalNIC = 0;
+  }
+
+  /* Enumerate NICs */
+  EnumNICs(&pTable, &pAddrTable);
+
+  if (pTable)
+  {
+    for(dwIfIdx=0; dwIfIdx <= pTable->dwNumEntries; dwIfIdx++)
+    {
+      char szEntry[1001];
+      DWORD dwIP = 0;
+      int iItm;
+               PIP_ADAPTER_INFO pAdapterInfo;
+               PIP_ADAPTER_INFO pAdapter = NULL;
+               DWORD dwRetVal = 0;
+
+      /* Get IP-Address */
+      int i;
+      for(i = 0; i < pAddrTable->dwNumEntries; i++)
+      {
+        if (pAddrTable->table[i].dwIndex == pTable->table[dwIfIdx].dwIndex)
+        {
+          dwIP = pAddrTable->table[i].dwAddr;
+          break;
+        }
+      }
+
+      if (dwIP)
+      {
+        BYTE bPhysAddr[MAXLEN_PHYSADDR];
+                 char *pszIfName = NULL;
+        char dst[INET_ADDRSTRLEN];
+
+        /* Get friendly interface name */
+                       pAdapterInfo = (IP_ADAPTER_INFO *) 
malloc(sizeof(IP_ADAPTER_INFO));
+                       ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);
+
+                       /* Make an initial call to GetAdaptersInfo to get
+                          the necessary size into the ulOutBufLen variable */
+                       if (GGetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == 
ERROR_BUFFER_OVERFLOW) {
+                         free(pAdapterInfo);
+                         pAdapterInfo = (IP_ADAPTER_INFO *) malloc 
(ulOutBufLen);
+                       }
+
+                       if ((dwRetVal = GGetAdaptersInfo( pAdapterInfo, 
&ulOutBufLen)) == NO_ERROR) {
+                         pAdapter = pAdapterInfo;
+                         while (pAdapter) {
+                               if (pTable->table[dwIfIdx].dwIndex == 
pAdapter->Index)
+                               {
+                                       char szKey[251];
+                                       long lLen = 250;
+
+                                       sprintf(szKey, 
"SYSTEM\\CurrentControlSet\\Control\\Network\\"
+                                               
"{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection",
+                                               pAdapter->AdapterName);
+                                       pszIfName = (char *) malloc(251);
+                                       if (QueryRegistry(HKEY_LOCAL_MACHINE, 
szKey, "Name", pszIfName,
+                                               &lLen) != ERROR_SUCCESS)
+                                       {
+                                               free(pszIfName);
+                                               pszIfName = NULL;
+                                       }
+                               }
+                           pAdapter = pAdapter->Next;
+                         }
+                       }
+                       free(pAdapterInfo);
+
+                       /* Set entry */
+        memset(bPhysAddr, 0, MAXLEN_PHYSADDR);
+        memcpy(bPhysAddr,
+          pTable->table[dwIfIdx].bPhysAddr,
+          pTable->table[dwIfIdx].dwPhysAddrLen);
+
+        snprintf(szEntry, 1000, "%s (%s - %I64u)",
+          pszIfName ? pszIfName : (char *) pTable->table[dwIfIdx].bDescr,
+          inet_ntop (AF_INET, &dwIP, dst, INET_ADDRSTRLEN),
+          *((unsigned long long *) bPhysAddr));
+        szEntry[1000] = 0;
+
+        if (pszIfName)
+               free(pszIfName);
+
+        callback(szEntry, pAddrTable->table[dwIfIdx].dwIndex == dwExternalNIC, 
cls);
+      }
+    }
+    GlobalFree(pAddrTable);
+    GlobalFree(pTable);
+  }
+
+  return GNUNET_YES;
+}
+
+/**
+ * @brief Installs the Windows service
+ * @param servicename name of the service as diplayed by the SCM
+ * @param application path to the application binary
+ * @param username the name of the service's user account
+ * @returns 0 on success
+ *          1 if the Windows version doesn't support services
+ *          2 if the SCM could not be opened
+ *          3 if the service could not be created
+ */
+int InstallAsService(char *servicename, char *application, char *username)
+{
+  SC_HANDLE hManager, hService;
+  char szEXE[_MAX_PATH + 17] = "\"";
+  char *user = NULL;
+
+  if (! GNOpenSCManager)
+    return 1;
+
+  plibc_conv_to_win_path(application, szEXE + 1);
+  strcat(szEXE, "\" --win-service");
+  hManager = GNOpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
+  if (! hManager)
+    return 2;
+
+  if (username)
+  {
+       user = (char *) malloc(strlen(username) + 3);
+       sprintf(user, ".\\%s", username);
+  }
+
+  hService = GNCreateService(hManager, (LPCTSTR) servicename, (LPCTSTR) 
servicename, 0,
+    SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, 
(LPCTSTR) szEXE,
+    NULL, NULL, NULL, (LPCTSTR) user, (LPCTSTR) username);
+
+  if (user)
+    free(user);
+
+  if (! hService)
+    return 3;
+
+  GNCloseServiceHandle(hService);
+
+  return 0;
+}
+
+/**
+ * @brief Uninstall Windows service
+ * @param servicename name of the service to delete
+ * @returns 0 on success
+ *          1 if the Windows version doesn't support services
+ *          2 if the SCM could not be openend
+ *          3 if the service cannot be accessed
+ *          4 if the service cannot be deleted
+ */
+int UninstallService(char *servicename)
+{
+  SC_HANDLE hManager, hService;
+
+  if (! GNOpenSCManager)
+    return 1;
+
+  hManager = GNOpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
+  if (! hManager)
+    return 2;
+
+  if (! (hService = GNOpenService(hManager, (LPCTSTR) servicename, DELETE)))
+    if (GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST)
+      return 3;
+     else
+       goto closeSCM;
+
+  if (! GNDeleteService(hService))
+    if (GetLastError() != ERROR_SERVICE_MARKED_FOR_DELETE)
+      return 4;
+
+closeSCM:
+  GNCloseServiceHandle(hService);
+
+  return 0;
+}
+
+/**
+ * @author Scott Field, Microsoft
+ * @see http://support.microsoft.com/?scid=kb;en-us;132958
+ * @date 12-Jul-95
+ */
+void _InitLsaString(PLSA_UNICODE_STRING LsaString, LPWSTR String)
+{
+  DWORD StringLength;
+
+  if(String == NULL)
+  {
+    LsaString->Buffer = NULL;
+    LsaString->Length = 0;
+    LsaString->MaximumLength = 0;
+    return;
+  }
+
+  StringLength = wcslen(String);
+  LsaString->Buffer = String;
+  LsaString->Length = (USHORT) StringLength *sizeof(WCHAR);
+  LsaString->MaximumLength = (USHORT) (StringLength + 1) * sizeof(WCHAR);
+}
+
+
+/**
+ * @author Scott Field, Microsoft
+ * @see http://support.microsoft.com/?scid=kb;en-us;132958
+ * @date 12-Jul-95
+ */
+NTSTATUS _OpenPolicy(LPWSTR ServerName, DWORD DesiredAccess, PLSA_HANDLE 
PolicyHandle)
+{
+  LSA_OBJECT_ATTRIBUTES ObjectAttributes;
+  LSA_UNICODE_STRING ServerString;
+  PLSA_UNICODE_STRING Server = NULL;
+
+  /* Always initialize the object attributes to all zeroes. */
+  ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes));
+
+  if(ServerName != NULL)
+  {
+    /* Make a LSA_UNICODE_STRING out of the LPWSTR passed in */
+    _InitLsaString(&ServerString, ServerName);
+    Server = &ServerString;
+  }
+
+  /* Attempt to open the policy. */
+  return GNLsaOpenPolicy(Server,
+                       &ObjectAttributes, DesiredAccess, PolicyHandle);
+}
+
+/**
+ * @brief Obtain a SID representing the supplied account on the supplied system
+ * @return TRUE on success, FALSE on failure
+ * @author Scott Field, Microsoft
+ * @date 12-Jul-95
+ * @remarks A buffer is allocated which contains the SID representing the
+ *          supplied account. This buffer should be freed when it is no longer
+ *          needed by calling\n
+ *            HeapFree(GetProcessHeap(), 0, buffer)
+ * @remarks Call GetLastError() to obtain extended error information.
+ * @see http://support.microsoft.com/?scid=kb;en-us;132958
+ */
+BOOL _GetAccountSid(LPTSTR SystemName, LPTSTR AccountName, PSID * Sid)
+{
+  LPTSTR ReferencedDomain = NULL;
+  DWORD cbSid = 128;                                                   /* 
initial allocation attempt */
+  DWORD cchReferencedDomain = 16;      /* initial allocation size */
+  SID_NAME_USE peUse;
+  BOOL bSuccess = FALSE;                                       /* assume this 
function will fail */
+
+  /* initial memory allocations */
+  if ((*Sid = HeapAlloc (GetProcessHeap (), 0, cbSid)) == NULL)
+       return FALSE;
+
+  if ((ReferencedDomain = (LPTSTR) HeapAlloc (GetProcessHeap (),
+                                   0,
+                                   cchReferencedDomain *
+                                   sizeof (TCHAR))) == NULL)
+       return FALSE;
+
+    /* Obtain the SID of the specified account on the specified system. */
+       while (!GNLookupAccountName(SystemName, /* machine to lookup account on 
*/
+                  AccountName,                                                 
                                        /* account to lookup */
+                  *Sid,                                                        
                                                                /* SID of 
interest */
+                  &cbSid,                                                      
                                                        /* size of SID */
+                  ReferencedDomain,                                            
                        /* domain account was found on */
+                  &cchReferencedDomain, &peUse))
+       {
+               if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
+               {
+                       /* reallocate memory */
+                       if ((*Sid = HeapReAlloc (GetProcessHeap (), 0, *Sid, 
cbSid)) == NULL)
+                               return FALSE;
+
+                       if ((ReferencedDomain = (LPTSTR) HeapReAlloc 
(GetProcessHeap (),
+                                             0,
+                                             ReferencedDomain,
+                                             cchReferencedDomain
+                                             * sizeof (TCHAR))) == NULL)
+                               return FALSE;
+      }
+      else
+        goto end;
+  }
+
+  /* Indicate success. */
+  bSuccess = TRUE;
+
+end:
+  /* Cleanup and indicate failure, if appropriate. */
+  HeapFree (GetProcessHeap (), 0, ReferencedDomain);
+
+  if (!bSuccess)
+  {
+    if (*Sid != NULL)
+    {
+               HeapFree (GetProcessHeap (), 0, *Sid);
+               *Sid = NULL;
+    }
+  }
+
+  return bSuccess;
+}
+
+/**
+ * @author Scott Field, Microsoft
+ * @see http://support.microsoft.com/?scid=kb;en-us;132958
+ * @date 12-Jul-95
+ */
+NTSTATUS _SetPrivilegeOnAccount(LSA_HANDLE PolicyHandle,/* open policy handle 
*/
+                               PSID AccountSid,                        /* SID 
to grant privilege to */
+                               LPWSTR PrivilegeName,   /* privilege to grant 
(Unicode) */
+                               BOOL bEnable                                    
        /* enable or disable */
+  )
+{
+  LSA_UNICODE_STRING PrivilegeString;
+
+  /* Create a LSA_UNICODE_STRING for the privilege name. */
+  _InitLsaString(&PrivilegeString, PrivilegeName);
+
+  /* grant or revoke the privilege, accordingly */
+  if(bEnable)
+  {
+    NTSTATUS i;
+
+    i = GNLsaAddAccountRights(PolicyHandle,                            /* open 
policy handle */
+                               AccountSid,                             /* 
target SID */
+                               &PrivilegeString,        /* privileges */
+                               1                                               
                                        /* privilege count */
+      );
+  }
+  else
+  {
+    return GNLsaRemoveAccountRights(PolicyHandle,                      /* open 
policy handle */
+                                  AccountSid,                          /* 
target SID */
+                                  FALSE,                                       
                /* do not disable all rights */
+                                  &PrivilegeString,            /* privileges */
+                                  1                                            
                                /* privilege count */
+      );
+  }
+}
+
+/**
+ * @brief Create a Windows service account
+ * @return 0 on success, > 0 otherwise
+ * @param pszName the name of the account
+ * @param pszDesc description of the account
+ */
+int CreateServiceAccount(char *pszName, char *pszDesc)
+{
+  USER_INFO_1 ui;
+  USER_INFO_1008 ui2;
+  NET_API_STATUS nStatus;
+  wchar_t wszName[MAX_NAME_LENGTH], wszDesc[MAX_NAME_LENGTH];
+  DWORD dwErr;
+  LSA_HANDLE hPolicy;
+  PSID pSID;
+
+  if (! GNNetUserAdd)
+       return 1;
+  mbstowcs(wszName, pszName, strlen(pszName) + 1);
+  mbstowcs(wszDesc, pszDesc, strlen(pszDesc) + 1);
+
+  memset(&ui, 0, sizeof(ui));
+  ui.usri1_name = wszName;
+  ui.usri1_password = wszName; /* account is locked anyway */
+  ui.usri1_priv = USER_PRIV_USER;
+  ui.usri1_comment = wszDesc;
+  ui.usri1_flags = UF_SCRIPT;
+
+  nStatus = GNNetUserAdd(NULL, 1, (LPBYTE)&ui, NULL);
+
+  if (nStatus != NERR_Success && nStatus != NERR_UserExists)
+       return 2;
+
+  ui2.usri1008_flags = UF_PASSWD_CANT_CHANGE | UF_DONT_EXPIRE_PASSWD;
+  GNNetUserSetInfo(NULL, wszName, 1008, (LPBYTE)&ui2, NULL);
+
+  if (_OpenPolicy(NULL, POLICY_ALL_ACCESS, &hPolicy) !=
+                                                                               
STATUS_SUCCESS)
+       return 3;
+
+  _GetAccountSid(NULL, (LPTSTR) pszName, &pSID);
+
+  if (_SetPrivilegeOnAccount(hPolicy, pSID, L"SeServiceLogonRight", TRUE) != 
STATUS_SUCCESS)
+       return 4;
+
+  _SetPrivilegeOnAccount(hPolicy, pSID, L"SeDenyInteractiveLogonRight", TRUE);
+  _SetPrivilegeOnAccount(hPolicy, pSID, L"SeDenyBatchLogonRight", TRUE);
+  _SetPrivilegeOnAccount(hPolicy, pSID, L"SeDenyNetworkLogonRight", TRUE);
+
+  GNLsaClose(hPolicy);
+
+  return 0;
+}
+
+/**
+ * @brief Grant permission to a file
+ * @param lpszFileName the name of the file or directory
+ * @param lpszAccountName the user account
+ * @param the desired access (e.g. GENERIC_ALL)
+ * @return TRUE on success
+ * @remark based on 
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q102102&;
+ */
+BOOL AddPathAccessRights(char *lpszFileName, char *lpszAccountName,
+      DWORD dwAccessMask)
+{
+  /* SID variables. */
+  SID_NAME_USE   snuType;
+  TCHAR *        szDomain       = NULL;
+  DWORD          cbDomain       = 0;
+  LPVOID         pUserSID       = NULL;
+  DWORD          cbUserSID      = 0;
+
+  /* File SD variables. */
+  PSECURITY_DESCRIPTOR pFileSD  = NULL;
+  DWORD          cbFileSD       = 0;
+
+  /* New SD variables. */
+  SECURITY_DESCRIPTOR  newSD;
+
+  /* ACL variables. */
+  PACL           pACL           = NULL;
+  BOOL           fDaclPresent;
+  BOOL           fDaclDefaulted;
+  ACL_SIZE_INFORMATION AclInfo;
+
+  /* New ACL variables. */
+  PACL           pNewACL        = NULL;
+  DWORD          cbNewACL       = 0;
+
+  /* Temporary ACE. */
+  LPVOID         pTempAce       = NULL;
+  UINT           CurrentAceIndex = 0;
+
+  UINT           newAceIndex = 0;
+
+  /* Assume function will fail. */
+  BOOL           fResult        = FALSE;
+  BOOL           fAPISuccess;
+
+  SECURITY_INFORMATION secInfo = DACL_SECURITY_INFORMATION;
+
+  /**
+   * STEP 1: Get SID of the account name specified.
+   */
+  fAPISuccess = GNLookupAccountName(NULL, (LPCTSTR) lpszAccountName,
+        pUserSID, &cbUserSID, (LPTSTR) szDomain, &cbDomain, &snuType);
+
+  /* API should have failed with insufficient buffer. */
+  if (fAPISuccess)
+     goto end;
+  else if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
+     goto end;
+  }
+
+  pUserSID = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbUserSID);
+  if (!pUserSID) {
+     goto end;
+  }
+
+  szDomain = (TCHAR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbDomain 
* sizeof(TCHAR));
+  if (!szDomain) {
+     goto end;
+  }
+
+  fAPISuccess = GNLookupAccountName(NULL, (LPCTSTR) lpszAccountName,
+        pUserSID, &cbUserSID, (LPTSTR) szDomain, &cbDomain, &snuType);
+  if (!fAPISuccess) {
+     goto end;
+  }
+
+  /**
+   *  STEP 2: Get security descriptor (SD) of the file specified.
+   */
+  fAPISuccess = GNGetFileSecurity((LPCTSTR) lpszFileName,
+        secInfo, pFileSD, 0, &cbFileSD);
+
+  /* API should have failed with insufficient buffer. */
+  if (fAPISuccess)
+     goto end;
+  else if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
+     goto end;
+  }
+
+  pFileSD = (PSECURITY_DESCRIPTOR) HeapAlloc(GetProcessHeap(), 
HEAP_ZERO_MEMORY,
+       cbFileSD);
+  if (!pFileSD) {
+     goto end;
+  }
+
+  fAPISuccess = GNGetFileSecurity((LPCTSTR) lpszFileName,
+        secInfo, pFileSD, cbFileSD, &cbFileSD);
+  if (!fAPISuccess) {
+     goto end;
+  }
+
+  /**
+   * STEP 3: Initialize new SD.
+   */
+  if (!GNInitializeSecurityDescriptor(&newSD,
+        SECURITY_DESCRIPTOR_REVISION)) {
+     goto end;
+  }
+
+  /**
+   * STEP 4: Get DACL from the old SD.
+   */
+  if (!GNGetSecurityDescriptorDacl(pFileSD, &fDaclPresent, &pACL,
+        &fDaclDefaulted)) {
+     goto end;
+  }
+
+  /**
+   * STEP 5: Get size information for DACL.
+   */
+  AclInfo.AceCount = 0; // Assume NULL DACL.
+  AclInfo.AclBytesFree = 0;
+  AclInfo.AclBytesInUse = sizeof(ACL);
+
+  if (pACL == NULL)
+     fDaclPresent = FALSE;
+
+  /* If not NULL DACL, gather size information from DACL. */
+  if (fDaclPresent) {
+
+     if (!GNGetAclInformation(pACL, &AclInfo,
+           sizeof(ACL_SIZE_INFORMATION), AclSizeInformation)) {
+        goto end;
+     }
+  }
+
+  /**
+   * STEP 6: Compute size needed for the new ACL.
+   */
+  cbNewACL = AclInfo.AclBytesInUse + sizeof(ACCESS_ALLOWED_ACE)
+        + GetLengthSid(pUserSID) - sizeof(DWORD);
+
+  /**
+   * STEP 7: Allocate memory for new ACL.
+   */
+  pNewACL = (PACL) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbNewACL);
+  if (!pNewACL) {
+     goto end;
+  }
+
+  /**
+   * STEP 8: Initialize the new ACL.
+   */
+  if (!GNInitializeAcl(pNewACL, cbNewACL, ACL_REVISION2)) {
+     goto end;
+  }
+
+  /**
+   * STEP 9 If DACL is present, copy all the ACEs from the old DACL
+   * to the new DACL.
+   *
+   * The following code assumes that the old DACL is
+   * already in Windows 2000 preferred order.  To conform
+   * to the new Windows 2000 preferred order, first we will
+   * copy all non-inherited ACEs from the old DACL to the
+   * new DACL, irrespective of the ACE type.
+   */
+
+  newAceIndex = 0;
+
+  if (fDaclPresent && AclInfo.AceCount) {
+
+     for (CurrentAceIndex = 0;
+           CurrentAceIndex < AclInfo.AceCount;
+           CurrentAceIndex++) {
+
+        /**
+         * TEP 10: Get an ACE.
+         */
+        if (!GNGetAce(pACL, CurrentAceIndex, &pTempAce)) {
+           goto end;
+        }
+
+        /**
+         * STEP 11: Check if it is a non-inherited ACE.
+         * If it is an inherited ACE, break from the loop so
+         * that the new access allowed non-inherited ACE can
+         * be added in the correct position, immediately after
+         * all non-inherited ACEs.
+         */
+        if (((ACCESS_ALLOWED_ACE *)pTempAce)->Header.AceFlags
+           & INHERITED_ACE)
+           break;
+
+        /**
+         * STEP 12: Skip adding the ACE, if the SID matches
+         * with the account specified, as we are going to
+         * add an access allowed ACE with a different access
+         * mask.
+         */
+        if (GNEqualSid(pUserSID,
+           &(((ACCESS_ALLOWED_ACE *)pTempAce)->SidStart)))
+           continue;
+
+        /**
+         * STEP 13: Add the ACE to the new ACL.
+         */
+        if (!GNAddAce(pNewACL, ACL_REVISION, MAXDWORD, pTempAce,
+              ((PACE_HEADER) pTempAce)->AceSize)) {
+           goto end;
+        }
+
+        newAceIndex++;
+     }
+  }
+
+  /**
+   * STEP 14: Add the access-allowed ACE to the new DACL.
+   * The new ACE added here will be in the correct position,
+   * immediately after all existing non-inherited ACEs.
+   */
+  if (!GNAddAccessAllowedAce(pNewACL, ACL_REVISION2, dwAccessMask,
+        pUserSID)) {
+     goto end;
+  }
+
+  /**
+   * STEP 14.5: Make new ACE inheritable
+   */
+  if (!GetAce(pNewACL, newAceIndex, &pTempAce))
+    goto end;
+  ((ACCESS_ALLOWED_ACE *)pTempAce)->Header.AceFlags |=
+    (CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE);
+
+  /**
+   * STEP 15: To conform to the new Windows 2000 preferred order,
+   * we will now copy the rest of inherited ACEs from the
+   * old DACL to the new DACL.
+   */
+  if (fDaclPresent && AclInfo.AceCount) {
+
+     for (;
+          CurrentAceIndex < AclInfo.AceCount;
+          CurrentAceIndex++) {
+
+        /**
+         * STEP 16: Get an ACE.
+         */
+        if (!GNGetAce(pACL, CurrentAceIndex, &pTempAce)) {
+           goto end;
+        }
+
+        /**
+         * STEP 17: Add the ACE to the new ACL.
+         */
+        if (!GNAddAce(pNewACL, ACL_REVISION, MAXDWORD, pTempAce,
+              ((PACE_HEADER) pTempAce)->AceSize)) {
+           goto end;
+        }
+     }
+  }
+
+  /**
+   * STEP 18: Set permissions
+   */
+  if (GNSetNamedSecurityInfo((LPTSTR) lpszFileName, SE_FILE_OBJECT,
+    DACL_SECURITY_INFORMATION, NULL, NULL, pNewACL, NULL) != ERROR_SUCCESS) {
+       goto end;
+  }
+
+  fResult = TRUE;
+
+end:
+
+  /**
+   * STEP 19: Free allocated memory
+   */
+  if (pUserSID)
+     HeapFree(GetProcessHeap(), 0, pUserSID);
+
+  if (szDomain)
+     HeapFree(GetProcessHeap(), 0, szDomain);
+
+  if (pFileSD)
+     HeapFree(GetProcessHeap(), 0, pFileSD);
+
+  if (pNewACL)
+     HeapFree(GetProcessHeap(), 0, pNewACL);
+
+  return fResult;
+}
+
+char *winErrorStr(const char *prefix, int dwErr)
+{
+  char *err, *ret;
+  int mem;
+
+  if (! FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
FORMAT_MESSAGE_FROM_SYSTEM,
+    NULL, (DWORD) dwErr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) 
&err,
+    0, NULL ))
+  {
+    err = "";
+  }
+
+  mem = strlen(err) + strlen(prefix) + 20;
+  ret = (char *) malloc(mem);
+
+  snprintf(ret, mem, "%s: %s (#%u)", prefix, err, dwErr);
+
+  LocalFree(err);
+
+  return ret;
+}
+
+} /* extern "C" */
+
+#endif

Copied: gnunet/src/util/winproc.c (from rev 8477, GNUnet/src/util/win/winproc.c)
===================================================================
--- gnunet/src/util/winproc.c                           (rev 0)
+++ gnunet/src/util/winproc.c   2009-06-10 22:24:54 UTC (rev 8541)
@@ -0,0 +1,254 @@
+/*
+     This file is part of GNUnet.
+     (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other 
contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file util/win/winproc.c
+ * @brief Functions for MS Windows
+ * @author Nils Durner
+ */
+
+#include "platform.h"
+#include "gnunet_common.h"
+
+#define DEBUG_WINPROC 0
+
+#ifdef MINGW
+
+static HINSTANCE hNTDLL, hIphlpapi, hAdvapi, hNetapi;
+
+TNtQuerySystemInformation GNNtQuerySystemInformation;
+TGetIfEntry GNGetIfEntry;
+TGetIpAddrTable GNGetIpAddrTable;
+TGetIfTable GNGetIfTable;
+TOpenSCManager GNOpenSCManager;
+TCreateService GNCreateService;
+TCloseServiceHandle GNCloseServiceHandle;
+TDeleteService GNDeleteService;
+TRegisterServiceCtrlHandler GNRegisterServiceCtrlHandler;
+TSetServiceStatus GNSetServiceStatus;
+TStartServiceCtrlDispatcher GNStartServiceCtrlDispatcher;
+TControlService GNControlService;
+TOpenService GNOpenService;
+TGetBestInterface GNGetBestInterface;
+TGetAdaptersInfo GGetAdaptersInfo;
+TNetUserAdd GNNetUserAdd;
+TNetUserSetInfo GNNetUserSetInfo;
+TLsaOpenPolicy GNLsaOpenPolicy;
+TLsaAddAccountRights GNLsaAddAccountRights;
+TLsaRemoveAccountRights GNLsaRemoveAccountRights;
+TLsaClose GNLsaClose;
+TLookupAccountName GNLookupAccountName;
+TGetFileSecurity GNGetFileSecurity;
+TInitializeSecurityDescriptor GNInitializeSecurityDescriptor;
+TGetSecurityDescriptorDacl GNGetSecurityDescriptorDacl;
+TGetAclInformation GNGetAclInformation;
+TInitializeAcl GNInitializeAcl;
+TGetAce GNGetAce;
+TEqualSid GNEqualSid;
+TAddAce GNAddAce;
+TAddAccessAllowedAce GNAddAccessAllowedAce;
+TSetNamedSecurityInfo GNSetNamedSecurityInfo;
+
+/**
+ * Log (panic) messages from PlibC
+ */
+void
+plibc_panic (int err, char *msg)
+{
+  GNUNET_log (((err ==
+                   INT_MAX) ? GNUNET_ERROR_TYPE_DEBUG : 
GNUNET_ERROR_TYPE_ERROR),
+                 "%s", msg);
+}
+
+/**
+ * @brief Initialize PlibC and set up Windows environment
+ * @param logging context, NULL means stderr
+ * @return Error code from winerror.h, ERROR_SUCCESS on success
+*/
+int
+InitWinEnv ()
+{
+  int ret;
+
+  plibc_initialized ();
+  plibc_set_panic_proc (plibc_panic);
+  ret = plibc_init ("GNU", PACKAGE);
+
+  /* don't load other DLLs twice */
+  if (hNTDLL)
+    return ret;
+
+  hNTDLL = LoadLibrary ("ntdll.dll");
+
+  /* Function to get CPU usage under Win NT */
+  if (hNTDLL)
+    {
+      GNNtQuerySystemInformation = (TNtQuerySystemInformation)
+        GetProcAddress (hNTDLL, "NtQuerySystemInformation");
+    }
+  else
+    {
+      GNNtQuerySystemInformation = NULL;
+    }
+
+  /* Functions to get information about a network adapter */
+  hIphlpapi = LoadLibrary ("iphlpapi.dll");
+  if (hIphlpapi)
+    {
+      GNGetIfEntry = (TGetIfEntry) GetProcAddress (hIphlpapi, "GetIfEntry");
+      GNGetIpAddrTable = (TGetIpAddrTable) GetProcAddress (hIphlpapi,
+                                                           "GetIpAddrTable");
+      GNGetIfTable = (TGetIfTable) GetProcAddress (hIphlpapi, "GetIfTable");
+      GNGetBestInterface = (TGetBestInterface) GetProcAddress (hIphlpapi,
+                                                               
"GetBestInterface");
+      GGetAdaptersInfo = (TGetAdaptersInfo) GetProcAddress (hIphlpapi,
+                                                            "GetAdaptersInfo");
+    }
+  else
+    {
+      GNGetIfEntry = NULL;
+      GNGetIpAddrTable = NULL;
+      GNGetIfTable = NULL;
+      GNGetBestInterface = NULL;
+      GGetAdaptersInfo = NULL;
+    }
+
+  /* Service & Account functions */
+  hAdvapi = LoadLibrary ("advapi32.dll");
+  if (hAdvapi)
+    {
+      GNOpenSCManager = (TOpenSCManager)
+        GetProcAddress (hAdvapi, "OpenSCManagerA");
+      GNCreateService = (TCreateService)
+        GetProcAddress (hAdvapi, "CreateServiceA");
+      GNCloseServiceHandle = (TCloseServiceHandle)
+        GetProcAddress (hAdvapi, "CloseServiceHandle");
+      GNDeleteService = (TDeleteService)
+        GetProcAddress (hAdvapi, "DeleteService");
+      GNRegisterServiceCtrlHandler = (TRegisterServiceCtrlHandler)
+        GetProcAddress (hAdvapi, "RegisterServiceCtrlHandlerA");
+      GNSetServiceStatus = (TSetServiceStatus)
+        GetProcAddress (hAdvapi, "SetServiceStatus");
+      GNStartServiceCtrlDispatcher = (TStartServiceCtrlDispatcher)
+        GetProcAddress (hAdvapi, "StartServiceCtrlDispatcherA");
+      GNControlService = (TControlService)
+        GetProcAddress (hAdvapi, "ControlService");
+      GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA");
+
+      GNLsaOpenPolicy = (TLsaOpenPolicy)
+        GetProcAddress (hAdvapi, "LsaOpenPolicy");
+      GNLsaAddAccountRights = (TLsaAddAccountRights)
+        GetProcAddress (hAdvapi, "LsaAddAccountRights");
+      GNLsaRemoveAccountRights = (TLsaRemoveAccountRights)
+        GetProcAddress (hAdvapi, "LsaRemoveAccountRights");
+      GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose");
+      GNLookupAccountName = (TLookupAccountName)
+        GetProcAddress (hAdvapi, "LookupAccountNameA");
+
+      GNGetFileSecurity = (TGetFileSecurity)
+        GetProcAddress (hAdvapi, "GetFileSecurityA");
+      GNInitializeSecurityDescriptor = (TInitializeSecurityDescriptor)
+        GetProcAddress (hAdvapi, "InitializeSecurityDescriptor");
+      GNGetSecurityDescriptorDacl = (TGetSecurityDescriptorDacl)
+        GetProcAddress (hAdvapi, "GetSecurityDescriptorDacl");
+      GNGetAclInformation = (TGetAclInformation)
+        GetProcAddress (hAdvapi, "GetAclInformation");
+      GNInitializeAcl = (TInitializeAcl)
+        GetProcAddress (hAdvapi, "InitializeAcl");
+      GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce");
+      GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid");
+      GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce");
+      GNAddAccessAllowedAce = (TAddAccessAllowedAce)
+        GetProcAddress (hAdvapi, "AddAccessAllowedAce");
+      GNSetNamedSecurityInfo = (TSetNamedSecurityInfo)
+        GetProcAddress (hAdvapi, "SetNamedSecurityInfoA");
+    }
+  else
+    {
+      GNOpenSCManager = NULL;
+      GNCreateService = NULL;
+      GNCloseServiceHandle = NULL;
+      GNDeleteService = NULL;
+      GNRegisterServiceCtrlHandler = NULL;
+      GNSetServiceStatus = NULL;
+      GNStartServiceCtrlDispatcher = NULL;
+      GNControlService = NULL;
+      GNOpenService = NULL;
+
+      GNLsaOpenPolicy = NULL;
+      GNLsaAddAccountRights = NULL;
+      GNLsaRemoveAccountRights = NULL;
+      GNLsaClose = NULL;
+      GNLookupAccountName = NULL;
+
+      GNGetFileSecurity = NULL;
+      GNInitializeSecurityDescriptor = NULL;
+      GNGetSecurityDescriptorDacl = NULL;
+      GNGetAclInformation = NULL;
+      GNInitializeAcl = NULL;
+      GNGetAce = NULL;
+      GNEqualSid = NULL;
+      GNAddAce = NULL;
+      GNAddAccessAllowedAce = NULL;
+      GNSetNamedSecurityInfo = NULL;
+    }
+
+  /* Account function */
+  hNetapi = LoadLibrary ("netapi32.dll");
+  if (hNetapi)
+    {
+      GNNetUserAdd = (TNetUserAdd) GetProcAddress (hNetapi, "NetUserAdd");
+      GNNetUserSetInfo = (TNetUserSetInfo)
+        GetProcAddress (hNetapi, "NetUserSetInfo");
+    }
+  else
+    {
+      GNNetUserAdd = NULL;
+      GNNetUserSetInfo = NULL;
+    }
+
+  return ret;
+}
+
+/**
+ * Clean up Windows environment
+ */
+void
+ShutdownWinEnv ()
+{
+  plibc_shutdown ();
+
+  FreeLibrary (hNTDLL);
+  FreeLibrary (hIphlpapi);
+  FreeLibrary (hAdvapi);
+  FreeLibrary (hNetapi);
+
+  CoUninitialize ();
+}
+
+#endif /* MINGW */
+
+#if !HAVE_ATOLL
+long long
+atoll (const char *nptr)
+{
+  return atol (nptr);
+}
+#endif





reply via email to

[Prev in Thread] Current Thread [Next in Thread]