gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r710 - in GNUnet: . src/applications/bootstrap_http src/app


From: durner
Subject: [GNUnet-SVN] r710 - in GNUnet: . src/applications/bootstrap_http src/applications/fs/ecrs src/applications/fs/fsui src/applications/fs/lib src/applications/fs/module src/applications/gap src/applications/sqstore_mysql src/applications/testbed src/conf src/include src/server src/transports src/util src/util/win
Date: Fri, 29 Apr 2005 15:31:57 -0700 (PDT)

Author: durner
Date: 2005-04-29 15:30:41 -0700 (Fri, 29 Apr 2005)
New Revision: 710

Added:
   GNUnet/src/include/plibc.h
Removed:
   GNUnet/src/util/win/inet_pton.c
   GNUnet/src/util/win/win_printf.c
   GNUnet/src/util/win/winselect.c
   GNUnet/src/util/win/winstrptime.c
Modified:
   GNUnet/configure.ac
   GNUnet/src/applications/bootstrap_http/http.c
   GNUnet/src/applications/fs/ecrs/download.c
   GNUnet/src/applications/fs/ecrs/ecrstest.c
   GNUnet/src/applications/fs/ecrs/unindex.c
   GNUnet/src/applications/fs/ecrs/upload.c
   GNUnet/src/applications/fs/fsui/collection.c
   GNUnet/src/applications/fs/fsui/download.c
   GNUnet/src/applications/fs/fsui/upload.c
   GNUnet/src/applications/fs/lib/fslibtest.c
   GNUnet/src/applications/fs/module/ondemand.c
   GNUnet/src/applications/gap/gaptest.c
   GNUnet/src/applications/sqstore_mysql/mysql.c
   GNUnet/src/applications/testbed/commands.c
   GNUnet/src/applications/testbed/gnunet-testbed.c
   GNUnet/src/applications/testbed/testbed.c
   GNUnet/src/conf/mconf_textbox.c
   GNUnet/src/conf/wizard_callbacks.c
   GNUnet/src/include/Makefile.am
   GNUnet/src/include/gnunet_util.h
   GNUnet/src/include/platform.h
   GNUnet/src/include/winproc.h
   GNUnet/src/server/startup.c
   GNUnet/src/server/tcpserver.c
   GNUnet/src/transports/http.c
   GNUnet/src/transports/smtp.c
   GNUnet/src/transports/tcp.c
   GNUnet/src/transports/tcp6.c
   GNUnet/src/transports/udp.c
   GNUnet/src/transports/udp6.c
   GNUnet/src/util/bloomfilter.c
   GNUnet/src/util/hashing.c
   GNUnet/src/util/identity.c
   GNUnet/src/util/initialize.c
   GNUnet/src/util/io.c
   GNUnet/src/util/semaphore.c
   GNUnet/src/util/state.c
   GNUnet/src/util/storage.c
   GNUnet/src/util/tcpio.c
   GNUnet/src/util/win/Makefile.am
   GNUnet/src/util/win/win.cc
   GNUnet/src/util/win/winproc.c
Log:
Migrating POSIX emulation for Windows to PlibC <http://plibc.sf.net/>

Modified: GNUnet/configure.ac
===================================================================
--- GNUnet/configure.ac 2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/configure.ac 2005-04-29 22:30:41 UTC (rev 710)
@@ -113,7 +113,7 @@
      AC_DEFINE_UNQUOTED(WINDOWS,1,[This is a Windows system])
      AC_DEFINE_UNQUOTED(_WIN32,1,[This is a Windows system])
      AC_CHECK_LIB(intl, gettext)
-     LDFLAGS="$LDFLAGS -no-undefined -Wl,--export-all-symbols -lws2_32"
+     LDFLAGS="$LDFLAGS -no-undefined -Wl,--export-all-symbols -lws2_32 -lplibc"
      CFLAGS="-mms-bitfields $CFLAGS"
      build_target="mingw"
      AC_PROG_CXX

Modified: GNUnet/src/applications/bootstrap_http/http.c
===================================================================
--- GNUnet/src/applications/bootstrap_http/http.c       2005-04-28 20:50:54 UTC 
(rev 709)
+++ GNUnet/src/applications/bootstrap_http/http.c       2005-04-29 22:30:41 UTC 
(rev 710)
@@ -146,7 +146,7 @@
        __FILE__, __LINE__,
        STRERROR(errno));
     FREE(filename);
-    CLOSE(sock);
+    closefile(sock);
     return;
   }
 
@@ -172,7 +172,7 @@
        __FILE__, __LINE__,
        STRERROR(errno));
     FREE(command);
-    CLOSE(sock);
+    closefile(sock);
     return;
   }
   FREE(command);
@@ -204,7 +204,7 @@
     LOG(LOG_WARNING,
        _("Parsing HTTP response for URL '%s' failed.\n"),
        url);
-    CLOSE(sock);
+    closefile(sock);
     return;
   }
 
@@ -247,7 +247,7 @@
   }
 
   FREE(buffer);
-  CLOSE(sock);
+  closefile(sock);
 }
 
 

Modified: GNUnet/src/applications/fs/ecrs/download.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/download.c  2005-04-28 20:50:54 UTC (rev 
709)
+++ GNUnet/src/applications/fs/ecrs/download.c  2005-04-29 22:30:41 UTC (rev 
710)
@@ -103,7 +103,7 @@
 
   for (i=0;i<=this->treedepth;i++) {
     if (this->handles[i] != -1) {
-      CLOSE(this->handles[i]);
+      closefile(this->handles[i]);
       this->handles[i] = -1;
     }
   }
@@ -163,7 +163,7 @@
       strcat(fn, ".A");
       fn[strlen(fn)-1] += i;
     }
-    this->handles[i] = OPEN(fn,
+    this->handles[i] = fileopen(fn,
                            O_CREAT|O_RDWR,
                            S_IRUSR|S_IWUSR );
     if (this->handles[i] < 0) {

Modified: GNUnet/src/applications/fs/ecrs/ecrstest.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/ecrstest.c  2005-04-28 20:50:54 UTC (rev 
709)
+++ GNUnet/src/applications/fs/ecrs/ecrstest.c  2005-04-29 22:30:41 UTC (rev 
710)
@@ -78,7 +78,7 @@
   int i;
 
   name = makeName(size);
-  fd = OPEN(name, O_WRONLY|O_CREAT, S_IWUSR|S_IRUSR);
+  fd = fileopen(name, O_WRONLY|O_CREAT, S_IWUSR|S_IRUSR);
   buf = MALLOC(size);
   memset(buf, size + size / 253, size);
   for (i=0;i<(int) (size - 42 - sizeof(HashCode512));i+=sizeof(HashCode512))
@@ -87,7 +87,7 @@
         (HashCode512*) &buf[i]);
   write(fd, buf, size);
   FREE(buf);
-  CLOSE(fd);
+  closefile(fd);
   ret = ECRS_uploadFile(name,
                        YES, /* index */
                        0, /* anon */
@@ -195,7 +195,7 @@
                              &testTerminate,
                              NULL)) {
 
-    fd = OPEN(tmpName, O_RDONLY);
+    fd = fileopen(tmpName, O_RDONLY);
     buf = MALLOC(size);
     in = MALLOC(size);
     memset(buf, size + size / 253, size);
@@ -211,7 +211,7 @@
       ret = OK;
     FREE(buf);
     FREE(in);
-    CLOSE(fd);
+    closefile(fd);
   }
   UNLINK(tmpName);
   FREE(tmpName);

Modified: GNUnet/src/applications/fs/ecrs/unindex.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/unindex.c   2005-04-28 20:50:54 UTC (rev 
709)
+++ GNUnet/src/applications/fs/ecrs/unindex.c   2005-04-29 22:30:41 UTC (rev 
710)
@@ -236,9 +236,9 @@
                     &fileId);
 
 #ifdef O_LARGEFILE
-  fd = OPEN(filename, O_RDONLY | O_LARGEFILE);
+  fd = fileopen(filename, O_RDONLY | O_LARGEFILE);
 #else
-  fd = OPEN(filename, O_RDONLY);
+  fd = fileopen(filename, O_RDONLY);
 #endif
   if (fd == -1) {
     LOG_FILE_STRERROR(LOG_WARNING, "OPEN", filename);
@@ -385,7 +385,7 @@
   /* free resources */
   FREE(iblocks);
   FREE(dblock);
-  CLOSE(fd);
+  closefile(fd);
   releaseClientSocket(sock);
   return OK;
  FAILURE:
@@ -393,7 +393,7 @@
     FREENONNULL(iblocks[i]);
   FREE(iblocks);
   FREE(dblock);
-  CLOSE(fd);
+  closefile(fd);
   releaseClientSocket(sock);
   return SYSERR;
 }

Modified: GNUnet/src/applications/fs/ecrs/upload.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/upload.c    2005-04-28 20:50:54 UTC (rev 
709)
+++ GNUnet/src/applications/fs/ecrs/upload.c    2005-04-29 22:30:41 UTC (rev 
710)
@@ -190,9 +190,9 @@
   treedepth = computeDepth(filesize);
 
 #ifdef O_LARGEFILE
-  fd = OPEN(filename, O_RDONLY | O_LARGEFILE);
+  fd = fileopen(filename, O_RDONLY | O_LARGEFILE);
 #else
-  fd = OPEN(filename, O_RDONLY);
+  fd = fileopen(filename, O_RDONLY);
 #endif
   if (fd == -1) {
     LOG_FILE_STRERROR(LOG_WARNING, "OPEN", filename);
@@ -366,7 +366,7 @@
   FREENONNULL(iblocks[treedepth]);
   FREE(iblocks);
   FREE(dblock);
-  CLOSE(fd);
+  closefile(fd);
   releaseClientSocket(sock);
   return OK;
  FAILURE:
@@ -374,7 +374,7 @@
     FREENONNULL(iblocks[i]);
   FREE(iblocks);
   FREE(dblock);
-  CLOSE(fd);
+  closefile(fd);
   releaseClientSocket(sock);
   return SYSERR;
 }

Modified: GNUnet/src/applications/fs/fsui/collection.c
===================================================================
--- GNUnet/src/applications/fs/fsui/collection.c        2005-04-28 20:50:54 UTC 
(rev 709)
+++ GNUnet/src/applications/fs/fsui/collection.c        2005-04-29 22:30:41 UTC 
(rev 710)
@@ -257,7 +257,7 @@
     FREE(tmpName);
     return;
   }
-  CLOSE(fd);
+  closefile(fd);
   if (OK != ECRS_uploadFile(tmpName,
                            NO, /* indexing */
                            ntohl(cd->anonymityLevel),

Modified: GNUnet/src/applications/fs/fsui/download.c
===================================================================
--- GNUnet/src/applications/fs/fsui/download.c  2005-04-28 20:50:54 UTC (rev 
709)
+++ GNUnet/src/applications/fs/fsui/download.c  2005-04-29 22:30:41 UTC (rev 
710)
@@ -214,10 +214,10 @@
     int fd;
 
 #ifdef O_LARGEFILE
-    fd = OPEN(dl->filename,
+    fd = fileopen(dl->filename,
              O_LARGEFILE | O_RDONLY);
 #else
-    fd = OPEN(dl->filename,
+    fd = fileopen(dl->filename,
              O_RDONLY);
 #endif
     if (fd == -1) {
@@ -242,7 +242,7 @@
       MUTEX_UNLOCK(&dl->ctx->lock);
       ECRS_freeMetaData(md);
       MUNMAP(dirBlock, totalBytes);
-      CLOSE(fd);
+      closefile(fd);
     }
 
     /* wait for recursive downloads (if any) */

Modified: GNUnet/src/applications/fs/fsui/upload.c
===================================================================
--- GNUnet/src/applications/fs/fsui/upload.c    2005-04-28 20:50:54 UTC (rev 
709)
+++ GNUnet/src/applications/fs/fsui/upload.c    2005-04-29 22:30:41 UTC (rev 
710)
@@ -149,7 +149,7 @@
                            len)) {
       LOG_FILE_STRERROR(LOG_ERROR, tempName, "write");
     } else {
-      CLOSE(handle);
+      closefile(handle);
       ret = ECRS_uploadFile(tempName,
                            NO,
                            utc->anonymityLevel,

Modified: GNUnet/src/applications/fs/lib/fslibtest.c
===================================================================
--- GNUnet/src/applications/fs/lib/fslibtest.c  2005-04-28 20:50:54 UTC (rev 
709)
+++ GNUnet/src/applications/fs/lib/fslibtest.c  2005-04-29 22:30:41 UTC (rev 
710)
@@ -286,7 +286,7 @@
     CHECK(-1 != WRITE(fd, 
                      &((DBlock*)&block[1])[1],
                      ntohl(block->size) - sizeof(Datastore_Value) - 
sizeof(DBlock)));
-    CLOSE(fd);
+    closefile(fd);
     CHECK(FS_initIndex(sock,
                       &hc, 
                       tmpName) == YES);

Modified: GNUnet/src/applications/fs/module/ondemand.c
===================================================================
--- GNUnet/src/applications/fs/module/ondemand.c        2005-04-28 20:50:54 UTC 
(rev 709)
+++ GNUnet/src/applications/fs/module/ondemand.c        2005-04-29 22:30:41 UTC 
(rev 710)
@@ -208,7 +208,7 @@
     LOG(LOG_DEBUG,
        "Storing on-demand encoded data in '%s'.\n",
        fn);
-    fd = OPEN(fn,
+    fd = fileopen(fn,
 #ifdef O_LARGEFILE
              O_CREAT|O_WRONLY|O_LARGEFILE,
 #else
@@ -232,7 +232,7 @@
       LOG_FILE_STRERROR(LOG_ERROR, "write", fn);
       ret = SYSERR;
     }
-    CLOSE(fd);
+    closefile(fd);
     if (ret == SYSERR) {
       FREE(fn);    
       return ret;
@@ -358,9 +358,9 @@
   fn = getOnDemandFile(&odb->fileId);
 
 #ifdef O_LARGEFILE
-  fileHandle = OPEN(fn, O_RDONLY|O_LARGEFILE, 0);
+  fileHandle = fileopen(fn, O_RDONLY|O_LARGEFILE, 0);
 #else
-  fileHandle = OPEN(fn, O_RDONLY, 0);
+  fileHandle = fileopen(fn, O_RDONLY, 0);
 #endif
   if (fileHandle == -1) {
     char unavail_key[256];
@@ -450,7 +450,7 @@
                                       SEEK_SET)) {
     LOG_FILE_STRERROR(LOG_WARNING, "lseek", fn);
     FREE(fn);
-    CLOSE(fileHandle);
+    closefile(fileHandle);
     return SYSERR;
   }
   db = MALLOC(sizeof(DBlock) + ntohl(odb->blockSize));
@@ -463,10 +463,10 @@
     LOG_FILE_STRERROR(LOG_ERROR, "read", fn);
     FREE(fn);
     FREE(db);
-    CLOSE(fileHandle);
+    closefile(fileHandle);
     return SYSERR;
   }
-  CLOSE(fileHandle);
+  closefile(fileHandle);
   ret = fileBlockEncode(db,
                        ntohl(odb->blockSize) + sizeof(DBlock),
                        query,
@@ -495,12 +495,12 @@
   int fd;
 
   fn = getOnDemandFile(fileId);
-  fd = OPEN(fn,
+  fd = fileopen(fn,
            O_RDONLY);
   FREE(fn);
   if(fd == -1)
     return NO;
-  CLOSE(fd);
+  closefile(fd);
   return YES;
 }
 
@@ -563,7 +563,7 @@
   LOG(LOG_DEBUG,
       "Removing on-demand encoded data stored in '%s'.\n",
       fn);
-  fd = OPEN(fn,
+  fd = fileopen(fn,
 #ifdef O_LARGEFILE
            O_RDONLY | O_LARGEFILE,
 #else
@@ -587,7 +587,7 @@
                      &block[1],
                      delta)) {
       LOG_FILE_STRERROR(LOG_ERROR, "read", fn);
-      CLOSE(fd);
+      closefile(fd);
       FREE(fn);
       FREE(block);
       return SYSERR;
@@ -625,7 +625,7 @@
     pos += delta;
   }
   FREE(block);
-  CLOSE(fd);
+  closefile(fd);
   UNLINK(fn);
 
   /* Remove information about unavailability */

Modified: GNUnet/src/applications/gap/gaptest.c
===================================================================
--- GNUnet/src/applications/gap/gaptest.c       2005-04-28 20:50:54 UTC (rev 
709)
+++ GNUnet/src/applications/gap/gaptest.c       2005-04-29 22:30:41 UTC (rev 
710)
@@ -86,7 +86,7 @@
   int i;
 
   name = makeName(size);
-  fd = OPEN(name, O_WRONLY|O_CREAT, S_IWUSR|S_IRUSR);
+  fd = fileopen(name, O_WRONLY|O_CREAT, S_IWUSR|S_IRUSR);
   buf = MALLOC(size);
   memset(buf, size + size / 253, size);
   for (i=0;i<(int) (size - 42 - sizeof(HashCode512));i+=sizeof(HashCode512))
@@ -95,7 +95,7 @@
         (HashCode512*) &buf[i]);
   write(fd, buf, size);
   FREE(buf);
-  CLOSE(fd);
+  closefile(fd);
   ret = ECRS_uploadFile(name,
                        YES, /* index */
                        0, /* anon */
@@ -203,7 +203,7 @@
                              &testTerminate,
                              NULL)) {
 
-    fd = OPEN(tmpName, O_RDONLY);
+    fd = fileopen(tmpName, O_RDONLY);
     buf = MALLOC(size);
     in = MALLOC(size);
     memset(buf, size + size / 253, size);
@@ -219,7 +219,7 @@
       ret = OK;
     FREE(buf);
     FREE(in);
-    CLOSE(fd);
+    closefile(fd);
   }
   UNLINK(tmpName);
   FREE(tmpName);

Modified: GNUnet/src/applications/sqstore_mysql/mysql.c
===================================================================
--- GNUnet/src/applications/sqstore_mysql/mysql.c       2005-04-28 20:50:54 UTC 
(rev 709)
+++ GNUnet/src/applications/sqstore_mysql/mysql.c       2005-04-29 22:30:41 UTC 
(rev 710)
@@ -1183,7 +1183,7 @@
   home_dir = pw->pw_dir;
 #else
   home_dir = (char *) MALLOC(_MAX_PATH + 1);
-  conv_to_win_path("~/", home_dir);
+  plibc_conv_to_win_path("~/", home_dir);
 #endif
   nX = strlen(home_dir)+1024;
   cnffile = getConfigurationString("MYSQL",

Modified: GNUnet/src/applications/testbed/commands.c
===================================================================
--- GNUnet/src/applications/testbed/commands.c  2005-04-28 20:50:54 UTC (rev 
709)
+++ GNUnet/src/applications/testbed/commands.c  2005-04-29 22:30:41 UTC (rev 
710)
@@ -316,10 +316,10 @@
     if (0 == BIND(s,
                  &addr,
                  sizeof(addr))) {
-      CLOSE(s);
+      closefile(s);
       break; /* found port! */
     } else {
-      CLOSE(s); /* not available, try another one... */
+      closefile(s); /* not available, try another one... */
     }
   }
   if (lport == 65535) {
@@ -1606,7 +1606,7 @@
           STRERROR(errno));
     FREE(reg);
     FREE(hostname);
-    CLOSE(sock);
+    closefile(sock);
     return -1;
   }
 
@@ -1630,7 +1630,7 @@
           STRERROR(errno));
     FREE(command);
     FREE(hostname);
-    CLOSE(sock);
+    closefile(sock);
     return -1;
   }
   FREE(command);
@@ -1662,7 +1662,7 @@
   }
   if (curpos < 4) { /* invalid response */
     XPRINTF(" exit register (error: no http response read)\n");
-    CLOSE(sock);
+    closefile(sock);
     return -1;
   }
 
@@ -1693,18 +1693,18 @@
 
       if (0 != processCommands(buffer, &curpos)) {
        FREE(buffer);
-       CLOSE(sock);
+       closefile(sock);
        return -1;
       }
     }
   }
   if (0 != processCommands(buffer, &curpos)) {
     FREE(buffer);
-    CLOSE(sock);
+    closefile(sock);
     return -1;
   }
   FREE(buffer);
-  CLOSE(sock);
+  closefile(sock);
   return 0;
 }
 

Modified: GNUnet/src/applications/testbed/gnunet-testbed.c
===================================================================
--- GNUnet/src/applications/testbed/gnunet-testbed.c    2005-04-28 20:50:54 UTC 
(rev 709)
+++ GNUnet/src/applications/testbed/gnunet-testbed.c    2005-04-29 22:30:41 UTC 
(rev 710)
@@ -180,7 +180,7 @@
        _("Cannot connect to LOOPBACK port %d: %s\n"),
        PORT,
        STRERROR(errno));
-    CLOSE(sock);
+    closefile(sock);
     sock = -1;
     return SYSERR;
   }
@@ -217,7 +217,7 @@
   }
   retVal = *(int*)buf;
   FREE(buf);
-  CLOSE(sock);
+  closefile(sock);
   return retVal;
 }
 
@@ -349,7 +349,7 @@
        secs);
     sleep(secs);
     secs += 5; /* slow progression... */
-    CLOSE(ssock);
+    closefile(ssock);
     goto CREATE_SOCKET;
   }
 
@@ -410,7 +410,7 @@
       LOG(LOG_WARNING,
          _("Rejected unauthorized connection from %u.%u.%u.%u.\n"),
          PRIP(ntohl(*(int*)&clientAddr.sin_addr)));
-      CLOSE(sock);
+      closefile(sock);
       continue;
     }
 
@@ -467,7 +467,7 @@
                 &i);
     }
     FREE(command);
-    CLOSE(sock);
+    closefile(sock);
     sock = -1;
   }
   /* just to be certain, we could have

Modified: GNUnet/src/applications/testbed/testbed.c
===================================================================
--- GNUnet/src/applications/testbed/testbed.c   2005-04-28 20:50:54 UTC (rev 
709)
+++ GNUnet/src/applications/testbed/testbed.c   2005-04-29 22:30:41 UTC (rev 
710)
@@ -522,14 +522,14 @@
   if (pi->pid == 0) {
     /* make pipe stdout/stderr */
 
-    CLOSE(fd[0]);
-    CLOSE(1);
-    CLOSE(2);
+    closefile(fd[0]);
+    closefile(1);
+    closefile(2);
     if (-1 == dup2(fd[1], 1))
       LOG_STRERROR(LOG_ERROR, "dup2");
     if (-1 == dup2(fd[1], 2))
       LOG_STRERROR(LOG_ERROR, "dup2");
-    CLOSE(fd[1]);
+    closefile(fd[1]);
     CHDIR(dir);
     FREE(dir);
     execvp(pi->argv[0],
@@ -543,12 +543,12 @@
     exit(errno);
   } /* end pi->pid == 0 */
   FREE(dir);
-  CLOSE(fd[1]);
+  closefile(fd[1]);
   for (pos=0;pos<pi->argc;pos++)
     FREE(pi->argv[pos]);
   FREE(pi->argv);
   if (pi->pid == -1) {
-    CLOSE(fd[0]);
+    closefile(fd[0]);
     SEMAPHORE_UP(pi->sem);
     MUTEX_UNLOCK(&lock);
     return -1;
@@ -588,7 +588,7 @@
           ret);
     MUTEX_UNLOCK(&lock);
   }
-  CLOSE(pi->outputPipe);
+  closefile(pi->outputPipe);
   MUTEX_LOCK(&lock);
 
   ret = waitpid(pi->pid,
@@ -1179,7 +1179,7 @@
        STRERROR(errno));
     FREE(reg);
     FREE(hostname);
-    CLOSE(sock);
+    closefile(sock);
     return;
   }
 
@@ -1233,7 +1233,7 @@
        STRERROR(errno));
     FREE(command);
     FREE(hostname);
-    CLOSE(sock);
+    closefile(sock);
     return;
   }
   FREE(command);
@@ -1263,7 +1263,7 @@
     else
       curpos=0;
   }
-  CLOSE(sock);
+  closefile(sock);
   if (curpos < 4) { /* invalid response */
     LOG(LOG_WARNING,
        _("Exit register (error: no http response read).\n"));

Modified: GNUnet/src/conf/mconf_textbox.c
===================================================================
--- GNUnet/src/conf/mconf_textbox.c     2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/conf/mconf_textbox.c     2005-04-29 22:30:41 UTC (rev 710)
@@ -52,7 +52,7 @@
     search_term[0] = '\0';     /* no search term entered yet */
 
     /* Open input file for reading */
-    if ((fd = OPEN (file, O_RDONLY)) == -1) {
+    if ((fd = fileopen(file, O_RDONLY)) == -1) {
        endwin ();
        fprintf (stderr,
                 "\nCan't open input file in dialog_textbox().\n");

Modified: GNUnet/src/conf/wizard_callbacks.c
===================================================================
--- GNUnet/src/conf/wizard_callbacks.c  2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/conf/wizard_callbacks.c  2005-04-29 22:30:41 UTC (rev 710)
@@ -182,7 +182,7 @@
                else
                {
                        char szPath[_MAX_PATH + 1];
-                       conv_to_win_path("/bin/gnunetd.exe", szPath);
+                       plibc_conv_to_win_path("/bin/gnunetd.exe", szPath);
                        
                        if (RegSetValue(HKEY_LOCAL_MACHINE,
                                
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", REG_SZ, szPath, 

Modified: GNUnet/src/include/Makefile.am
===================================================================
--- GNUnet/src/include/Makefile.am      2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/include/Makefile.am      2005-04-29 22:30:41 UTC (rev 710)
@@ -6,6 +6,7 @@
   fs.h \
   gettext.h \
   platform.h \
+  plibc.h \
   winproc.h 
 
 gnunetincludedir = $(includedir)/GNUnet

Modified: GNUnet/src/include/gnunet_util.h
===================================================================
--- GNUnet/src/include/gnunet_util.h    2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/include/gnunet_util.h    2005-04-29 22:30:41 UTC (rev 710)
@@ -1943,7 +1943,7 @@
 /* use the CLOSE macro... */
 void close_(int fd, const char * filename, int linenumber);
 
-#define CLOSE(fd) close_(fd, __FILE__, __LINE__)
+#define closefile(fd) close_(fd, __FILE__, __LINE__)
 
 /**
  * Stop the application.
@@ -2296,6 +2296,10 @@
  */
 void getLocaleDir(char *dir);
 
+/**
+ * open() a file
+ */
+int fileopen(const char *filename, int oflag, ...);
 
 /**
  * Helper functions

Modified: GNUnet/src/include/platform.h
===================================================================
--- GNUnet/src/include/platform.h       2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/include/platform.h       2005-04-29 22:30:41 UTC (rev 710)
@@ -154,136 +154,6 @@
 #include <sys/mman.h>
 #endif
 
-#ifndef SIGALRM
- #define SIGALRM 14
-#endif
-
-/**
- * Open a file
- */
-int OPEN(const char *filename, int oflag, ...);
-
-#ifndef MINGW
- #define DIR_SEPARATOR '/'
- #define DIR_SEPARATOR_STR "/"
- #define NEWLINE "\n"
-
- #define CREAT(p, m) creat(p, m)
- #undef FOPEN
- #define FOPEN(f, m) fopen(f, m)
- #define OPENDIR(d) opendir(d)
- #define CHDIR(d) chdir(d)
- #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 PIPE(h) pipe(h)
- #define REMOVE(p) remove(p)
- #define RENAME(o, n) rename(o, n)
- #define STAT(p, b) stat(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 READLINK(p, b, s) readlink(p, b, s)
- #define LSTAT(p, b) lstat(p, b)
- #define PRINTF(f, ...) printf(f , __VA_ARGS__)
- #define FPRINTF(fil, fmt, ...) fprintf(fil, fmt, __VA_ARGS__)
- #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(str, size, fmt, ...) snprintf(str, size, fmt, 
__VA_ARGS__)
- #define SPRINTF(d, f, ...) sprintf(d, f, __VA_ARGS__)
- #define VSSCANF(s, f, a) vsscanf(s, f, a)
- #define SSCANF(s, f, ...) sscanf(s, f, __VA_ARGS__)
- #define VFSCANF(s, f, a) vfscanf(s, f, a)
- #define VSCANF(f, a) vscanf(f, a)
- #define SCANF(f, ...) scanf(f, __VA_ARGS__)
- #define FSCANF(s, f, ...) fscanf(s, f, __VA_ARGS__)
- #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 NEWLINE "\r\n"
-
- #define CREAT(p, m) _win_creat(p, m)
- #define FOPEN(f, m) _win_fopen(f, m)
- #define OPENDIR(d) _win_opendir(d)
- #define CHDIR(d) _win_chdir(d)
- #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 REMOVE(p) _win_remove(p)
- #define RENAME(o, n) _win_rename(o, n)
- #define STAT(p, b) _win_stat(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 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 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
-
 #ifdef OSX
  #define socklen_t unsigned int
 #endif
@@ -292,141 +162,8 @@
 long long atoll(const char *nptr);
 #endif
 
-#ifndef HAVE_LANGINFO_H
-/* Modified version of glibc's langinfo.h */
+#if ENABLE_NLS
+       #include "langinfo.h"
+#endif
 
-/* Enumeration of locale items that can be queried with `nl_langinfo'. */
-enum
-{
-  /* LC_TIME category: date and time formatting.  */
-
-  /* Abbreviated days of the week. */
-  ABDAY_1, /* Sun */
-#define ABDAY_1     ABDAY_1
-  ABDAY_2,
-#define ABDAY_2     ABDAY_2
-  ABDAY_3,
-#define ABDAY_3     ABDAY_3
-  ABDAY_4,
-#define ABDAY_4     ABDAY_4
-  ABDAY_5,
-#define ABDAY_5     ABDAY_5
-  ABDAY_6,
-#define ABDAY_6     ABDAY_6
-  ABDAY_7,
-#define ABDAY_7     ABDAY_7
-
-  /* Long-named days of the week. */
-  DAY_1,      /* Sunday */
-#define DAY_1     DAY_1
-  DAY_2,      /* Monday */
-#define DAY_2     DAY_2
-  DAY_3,      /* Tuesday */
-#define DAY_3     DAY_3
-  DAY_4,      /* Wednesday */
-#define DAY_4     DAY_4
-  DAY_5,      /* Thursday */
-#define DAY_5     DAY_5
-  DAY_6,      /* Friday */
-#define DAY_6     DAY_6
-  DAY_7,      /* Saturday */
-#define DAY_7     DAY_7
-
-  /* Abbreviated month names.  */
-  ABMON_1,      /* Jan */
-#define ABMON_1     ABMON_1
-  ABMON_2,
-#define ABMON_2     ABMON_2
-  ABMON_3,
-#define ABMON_3     ABMON_3
-  ABMON_4,
-#define ABMON_4     ABMON_4
-  ABMON_5,
-#define ABMON_5     ABMON_5
-  ABMON_6,
-#define ABMON_6     ABMON_6
-  ABMON_7,
-#define ABMON_7     ABMON_7
-  ABMON_8,
-#define ABMON_8     ABMON_8
-  ABMON_9,
-#define ABMON_9     ABMON_9
-  ABMON_10,
-#define ABMON_10    ABMON_10
-  ABMON_11,
-#define ABMON_11    ABMON_11
-  ABMON_12,
-#define ABMON_12    ABMON_12
-
-  /* Long month names.  */
-  MON_1,      /* January */
-#define MON_1     MON_1
-  MON_2,
-#define MON_2     MON_2
-  MON_3,
-#define MON_3     MON_3
-  MON_4,
-#define MON_4     MON_4
-  MON_5,
-#define MON_5     MON_5
-  MON_6,
-#define MON_6     MON_6
-  MON_7,
-#define MON_7     MON_7
-  MON_8,
-#define MON_8     MON_8
-  MON_9,
-#define MON_9     MON_9
-  MON_10,
-#define MON_10      MON_10
-  MON_11,
-#define MON_11      MON_11
-  MON_12,
-#define MON_12      MON_12
-
-  AM_STR,     /* Ante meridian string.  */
-#define AM_STR      AM_STR
-  PM_STR,     /* Post meridian string.  */
-#define PM_STR      PM_STR
-
-  D_T_FMT,      /* Date and time format for strftime.  */
-#define D_T_FMT     D_T_FMT
-  D_FMT,      /* Date format for strftime.  */
-#define D_FMT     D_FMT
-  T_FMT,      /* Time format for strftime.  */
-#define T_FMT     T_FMT
-  T_FMT_AMPM,     /* 12-hour time format for strftime.  */
-#define T_FMT_AMPM    T_FMT_AMPM
-
-  ERA,        /* Alternate era.  */
-#define ERA     ERA
-  ERA_D_FMT,      /* Date in alternate era format.  */
-#define ERA_D_FMT   ERA_D_FMT
-  ALT_DIGITS,     /* Alternate symbols for digits.  */
-#define ALT_DIGITS    ALT_DIGITS
-  ERA_D_T_FMT,      /* Date and time in alternate era format.  */
-#define ERA_D_T_FMT   ERA_D_T_FMT
-  ERA_T_FMT,      /* Time in alternate era format.  */
-#define ERA_T_FMT   ERA_T_FMT
-  _DATE_FMT,    /* strftime format for date.  */
-#define _DATE_FMT _DATE_FMT
-  CODESET,
-#define CODESET     CODESET
-  CRNCYSTR,
-#define CRNCYSTR     CRNCYSTR
-  RADIXCHAR,
-#define RADIXCHAR   RADIXCHAR
-  THOUSEP,
-#define THOUSEP     THOUSEP
-  YESEXPR,
-#define YESEXPR     YESEXPR
-  NOEXPR,     /* Regex matching ``no'' input.  */
-#define NOEXPR      NOEXPR
-  /* This marks the highest value used.  */
-  _NL_NUM
-};
-#else
- #include <langinfo.h>
-#endif /* #ifndef HAVE_LANGINFO_H */
-
 #endif

Added: GNUnet/src/include/plibc.h
===================================================================
--- GNUnet/src/include/plibc.h  2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/include/plibc.h  2005-04-29 22:30:41 UTC (rev 710)
@@ -0,0 +1,537 @@
+/*
+     This file is part of PlibC.
+     (C) 2005 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
+*/
+
+/**
+ * @file include/plibc.h
+ * @brief PlibC header
+ * @attention This file is usually not installed under Unix,
+ *            so ship it with your application
+ */
+
+#ifndef _PLIBC_H_
+#define _PLIBC_H_
+
+#include <windows.h>
+#include <time.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+
+#ifndef SIGALRM
+ #define SIGALRM 14
+#endif
+
+#if ENABLE_NLS
+       #include "langinfo.h"
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef WINDOWS
+
+#define __BYTE_ORDER BYTE_ORDER
+#define __BIG_ENDIAN BIG_ENDIAN
+
+/* Conflicts with our definitions */
+#define __G_WIN32_H__
+
+/* Convert LARGE_INTEGER to double */
+#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \
+  (double)((x).LowPart))
+
+#define socklen_t int
+#define ssize_t int
+#define ftruncate chsize
+#define off_t int
+
+/* Thanks to the Cygwin project */
+#define EPERM 1                /* Not super-user */
+#define ENOENT 2       /* No such file or directory */
+#define ESRCH 3                /* No such process */
+#define EINTR 4                /* Interrupted system call */
+#define EIO 5          /* I/O error */
+#define ENXIO 6                /* No such device or address */
+#define E2BIG 7                /* Arg list too long */
+#define ENOEXEC 8      /* Exec format error */
+#define EBADF 9                /* Bad file number */
+#define ECHILD 10      /* No children */
+#define EAGAIN 11      /* Resource unavailable or operation would block, try 
again */
+#define ENOMEM 12      /* Not enough memory */
+#define EACCES 13      /* Permission denied */
+#define EFAULT 14      /* Bad address */
+#define ENOTBLK 15     /* Block device required */
+#define EBUSY 16       /* Mount device busy */
+#define EEXIST 17      /* File exists */
+#define EXDEV 18       /* Cross-device link */
+#define ENODEV 19      /* No such device */
+#define ENOTDIR 20     /* Not a directory */
+#define EISDIR 21      /* Is a directory */
+#define EINVAL 22      /* Invalid argument */
+#define ENFILE 23      /* Too many open files in system */
+#define EMFILE 24      /* Too many open files */
+#define ENOTTY 25      /* Not a typewriter */
+#define ETXTBSY 26     /* Text file busy */
+#define EFBIG 27       /* File too large */
+#define ENOSPC 28      /* No space left on device */
+#define ESPIPE 29      /* Illegal seek */
+#define EROFS 30       /* Read only file system */
+#define EMLINK 31      /* Too many links */
+#define EPIPE 32       /* Broken pipe */
+#define EDOM 33                /* Math arg out of domain of func */
+#define ERANGE 34      /* Math result not representable */
+#define ENOMSG 35      /* No message of desired type */
+#define EIDRM 36       /* Identifier removed */
+#define ECHRNG 37      /* Channel number out of range */
+#define EL2NSYNC 38    /* Level 2 not synchronized */
+#define L3HLT 39       /* Level 3 halted */
+#define EL3RST 40      /* Level 3 reset */
+#define ELNRNG 41      /* Link number out of range */
+#define EUNATCH 42     /* Protocol driver not attached */
+#define ENOCSI 43      /* No CSI structure available */
+#define EL2HLT 44      /* Level 2 halted */
+#undef  EDEADLK
+#define EDEADLK 45     /* Deadlock condition */
+#undef  ENOLCK
+#define ENOLCK 46      /* No record locks available */
+#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 */
+#undef  EDEADLOCK
+#define EDEADLOCK 56   /* File locking deadlock error */
+#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 */
+#undef  ENOSYS
+#define ENOSYS 88      /* Function not implemented */
+#define ENMFILE 89      /* No more files */
+#undef  ENOTEMPTY
+#define ENOTEMPTY 90   /* Directory not empty */
+#undef  ENAMETOOLONG
+#define ENAMETOOLONG 91        /* File or path name too long */
+#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 */
+#undef  ETIMEDOUT
+#define ETIMEDOUT 116          /* Connection timed out */
+#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 */
+#undef  ENOTSUP
+#define ENOTSUP 134                /* Not supported */
+#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 */
+
+#undef HOST_NOT_FOUND
+#define HOST_NOT_FOUND 1
+#undef TRY_AGAIN
+#define TRY_AGAIN 2
+#undef NO_RECOVERY
+#define NO_RECOVERY 3
+#undef NO_ADDRESS
+#define NO_ADDRESS 4
+
+#define PROT_READ   0x1
+#define PROT_WRITE  0x2
+#define MAP_SHARED  0x1
+#define MAP_FIXED   0x10
+
+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 */
+};
+
+/* 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
+{
+    LARGE_INTEGER IdleTime;
+    LARGE_INTEGER KernelTime;
+    LARGE_INTEGER UserTime;
+    LARGE_INTEGER Reserved1[2];
+    ULONG Reserved2;
+} SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
+
+#define sleep(secs) (Sleep(secs * 1000))
+
+/*********************** statfs *****************************/
+/* fake block size */
+#define FAKED_BLOCK_SIZE 512
+
+/* linux-compatible values for fs type */
+#define MSDOS_SUPER_MAGIC     0x4d44
+#define NTFS_SUPER_MAGIC      0x5346544E
+
+/*********************** End of statfs ***********************/
+
+#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 */
+
+/* Not supported under MinGW */
+#define S_IRGRP 0
+#define S_IWGRP 0
+#define S_IROTH 0
+#define S_IXGRP 0
+#define S_IWOTH 0
+#define S_IXOTH 0
+#define S_ISUID 0
+#define S_ISGID 0
+#define S_ISVTX 0
+#define S_IRWXG 0
+#define S_IRWXO 0
+
+#define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__)
+
+BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest);
+BOOL _plibc_DereferenceShortcut(char *pszShortcut);
+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);
+
+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);
+#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);
+int plibc_init(char *pszOrg, char *pszApp);
+void plibc_shutdown();
+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 _win_chdir(const char *path);
+int _win_close(int fd);
+int _win_fstat(int handle, struct stat *buffer);
+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);
+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_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_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, ...);
+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);
+char *_win_strerror(int errnum);
+int IsWinNT();
+
+#endif /* WINDOWS */
+
+#ifndef WINDOWS
+ #define DIR_SEPARATOR '/'
+ #define DIR_SEPARATOR_STR "/"
+ #define NEWLINE "\n"
+
+ #define CREAT(p, m) creat(p, m)
+ #undef FOPEN
+ #define FOPEN(f, m) fopen(f, m)
+ #define OPENDIR(d) opendir(d)
+ #define OPEN(f) open(f)
+ #define CHDIR(d) chdir(d)
+ #define CLOSE(f) close(f)
+ #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 PIPE(h) pipe(h)
+ #define REMOVE(p) remove(p)
+ #define RENAME(o, n) rename(o, n)
+ #define STAT(p, b) stat(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 READLINK(p, b, s) readlink(p, b, s)
+ #define LSTAT(p, b) lstat(p, b)
+ #define PRINTF(f, ...) printf(f , __VA_ARGS__)
+ #define FPRINTF(fil, fmt, ...) fprintf(fil, fmt, __VA_ARGS__)
+ #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(str, size, fmt, ...) snprintf(str, size, fmt, 
__VA_ARGS__)
+ #define SPRINTF(d, f, ...) sprintf(d, f, __VA_ARGS__)
+ #define VSSCANF(s, f, a) vsscanf(s, f, a)
+ #define SSCANF(s, f, ...) sscanf(s, f, __VA_ARGS__)
+ #define VFSCANF(s, f, a) vfscanf(s, f, a)
+ #define VSCANF(f, a) vscanf(f, a)
+ #define SCANF(f, ...) scanf(f, __VA_ARGS__)
+ #define FSCANF(s, f, ...) fscanf(s, f, __VA_ARGS__)
+ #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 NEWLINE "\r\n"
+
+ #define CREAT(p, m) _win_creat(p, m)
+ #define FOPEN(f, m) _win_fopen(f, m)
+ #define OPENDIR(d) _win_opendir(d)
+ #define OPEN(f) _win_open(f)
+ #define CHDIR(d) _win_chdir(d)
+ #define CLOSE(f) _win_close(f)
+ #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 REMOVE(p) _win_remove(p)
+ #define RENAME(o, n) _win_rename(o, n)
+ #define STAT(p, b) _win_stat(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 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 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
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif //_PLIBC_H_
+
+/* end of plibc.h */

Modified: GNUnet/src/include/winproc.h
===================================================================
--- GNUnet/src/include/winproc.h        2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/include/winproc.h        2005-04-29 22:30:41 UTC (rev 710)
@@ -44,277 +44,12 @@
 #include "gnunet_util.h"
 #include "platform.h"
 
+#include "plibc.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#define __BYTE_ORDER BYTE_ORDER
-#define __BIG_ENDIAN BIG_ENDIAN
-
-/* Conflicts with our definitions */
-#define __G_WIN32_H__
-
-/* Convert LARGE_INTEGER to double */
-#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \
-  (double)((x).LowPart))
-
-#define socklen_t int
-#define ssize_t int
-#define ftruncate chsize
-#define off_t int
-
-/* Thanks to the Cygwin project */
-#define EPERM 1                /* Not super-user */
-#define ENOENT 2       /* No such file or directory */
-#define ESRCH 3                /* No such process */
-#define EINTR 4                /* Interrupted system call */
-#define EIO 5          /* I/O error */
-#define ENXIO 6                /* No such device or address */
-#define E2BIG 7                /* Arg list too long */
-#define ENOEXEC 8      /* Exec format error */
-#define EBADF 9                /* Bad file number */
-#define ECHILD 10      /* No children */
-#define EAGAIN 11      /* Resource unavailable or operation would block, try 
again */
-#define ENOMEM 12      /* Not enough memory */
-#define EACCES 13      /* Permission denied */
-#define EFAULT 14      /* Bad address */
-#define ENOTBLK 15     /* Block device required */
-#define EBUSY 16       /* Mount device busy */
-#define EEXIST 17      /* File exists */
-#define EXDEV 18       /* Cross-device link */
-#define ENODEV 19      /* No such device */
-#define ENOTDIR 20     /* Not a directory */
-#define EISDIR 21      /* Is a directory */
-#define EINVAL 22      /* Invalid argument */
-#define ENFILE 23      /* Too many open files in system */
-#define EMFILE 24      /* Too many open files */
-#define ENOTTY 25      /* Not a typewriter */
-#define ETXTBSY 26     /* Text file busy */
-#define EFBIG 27       /* File too large */
-#define ENOSPC 28      /* No space left on device */
-#define ESPIPE 29      /* Illegal seek */
-#define EROFS 30       /* Read only file system */
-#define EMLINK 31      /* Too many links */
-#define EPIPE 32       /* Broken pipe */
-#define EDOM 33                /* Math arg out of domain of func */
-#define ERANGE 34      /* Math result not representable */
-#define ENOMSG 35      /* No message of desired type */
-#define EIDRM 36       /* Identifier removed */
-#define ECHRNG 37      /* Channel number out of range */
-#define EL2NSYNC 38    /* Level 2 not synchronized */
-#define L3HLT 39       /* Level 3 halted */
-#define EL3RST 40      /* Level 3 reset */
-#define ELNRNG 41      /* Link number out of range */
-#define EUNATCH 42     /* Protocol driver not attached */
-#define ENOCSI 43      /* No CSI structure available */
-#define EL2HLT 44      /* Level 2 halted */
-#undef  EDEADLK
-#define EDEADLK 45     /* Deadlock condition */
-#undef  ENOLCK
-#define ENOLCK 46      /* No record locks available */
-#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 */
-#undef  EDEADLOCK
-#define EDEADLOCK 56   /* File locking deadlock error */
-#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 */
-#undef  ENOSYS
-#define ENOSYS 88      /* Function not implemented */
-#define ENMFILE 89      /* No more files */
-#undef  ENOTEMPTY
-#define ENOTEMPTY 90   /* Directory not empty */
-#undef  ENAMETOOLONG
-#define ENAMETOOLONG 91        /* File or path name too long */
-#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 */
-#undef  ETIMEDOUT
-#define ETIMEDOUT 116          /* Connection timed out */
-#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 */
-#undef  ENOTSUP
-#define ENOTSUP 134                /* Not supported */
-#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 */
-
-#undef HOST_NOT_FOUND
-#define HOST_NOT_FOUND 1
-#undef TRY_AGAIN
-#define TRY_AGAIN 2
-#undef NO_RECOVERY
-#define NO_RECOVERY 3
-#undef NO_ADDRESS
-#define NO_ADDRESS 4
-
-#define PROT_READ   0x1
-#define PROT_WRITE  0x2
-#define MAP_SHARED  0x1
-#define MAP_FIXED   0x10
-
-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 */
-};
-
-/* 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
-{
-    LARGE_INTEGER IdleTime;
-    LARGE_INTEGER KernelTime;
-    LARGE_INTEGER UserTime;
-    LARGE_INTEGER Reserved1[2];
-    ULONG Reserved2;
-} SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
-
-#define sleep(secs) (Sleep(secs * 1000))
-
-/*********************** statfs *****************************/
-/* fake block size */
-#define FAKED_BLOCK_SIZE 512
-
-/* linux-compatible values for fs type */
-#define MSDOS_SUPER_MAGIC     0x4d44
-#define NTFS_SUPER_MAGIC      0x5346544E
-
-/*********************** End of statfs ***********************/
-
-typedef struct
-{
-  SOCKET s;
-  BOOL bBlocking;
-} Winsock;
-extern Winsock *pSocks;
-extern unsigned int uiSockCount;
-extern HANDLE hSocksLock;
-
-typedef struct
-{
-  int fildes;
-  void *buf;
-  size_t nbyte;
-} TReadWriteInfo;
-
-#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 */
-
-/* Not supported under MinGW */
-#define S_IRGRP 0
-#define S_IWGRP 0
-#define S_IROTH 0
-#define S_IXGRP 0
-#define S_IWOTH 0
-#define S_IXOTH 0
-#define S_ISUID 0
-#define S_ISGID 0
-#define S_ISVTX 0
-#define S_IRWXG 0
-#define S_IRWXO 0
-
-#define conv_to_win_path(u, w) conv_to_win_path_ex(u, w, 1)
-
 typedef DWORD WINAPI (*TNtQuerySystemInformation) (int, PVOID, ULONG, PULONG);
 typedef DWORD WINAPI (*TGetIfEntry) (PMIB_IFROW pIfRow);
 typedef DWORD WINAPI (*TGetIpAddrTable) (PMIB_IPADDRTABLE pIpAddrTable,
@@ -350,8 +85,6 @@
 typedef DWORD WINAPI (*TGetAdaptersInfo) (PIP_ADAPTER_INFO pAdapterInfo, 
PULONG pOutBufLen);
 
 
-#define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__)
-
 extern TNtQuerySystemInformation GNNtQuerySystemInformation;
 extern TGetIfEntry GNGetIfEntry;
 extern TGetIpAddrTable GNGetIpAddrTable;
@@ -375,97 +108,9 @@
               char *pszBuffer, long *pdLength);
 int ListNICs(void (*callback) (char *, int));
 
-BOOL __win_IsHandleMarkedAsBlocking(SOCKET hHandle);
-void __win_SetHandleBlockingMode(SOCKET s, BOOL bBlocking);
-void __win_DiscardHandleBlockingMode(SOCKET s);
+void GNInitWinEnv();
+void GNShutdownWinEnv();
 
-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);
-#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);
-void InitWinEnv();
-void ShutdownWinEnv();
-int 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_chdir(const char *path);
-int _win_fstat(int handle, struct stat *buffer);
-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);
-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_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_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, ...);
-#ifndef HAVE_LANGINFO_H
-char *nl_langinfo(int item);
-#endif
-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);
-char *_win_strerror(int errnum);
-int IsWinNT();
-
 #ifdef __cplusplus
 }
 #endif

Modified: GNUnet/src/server/startup.c
===================================================================
--- GNUnet/src/server/startup.c 2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/server/startup.c 2005-04-29 22:30:41 UTC (rev 710)
@@ -328,7 +328,7 @@
     int ok;
     char c;
 
-    CLOSE(filedes[1]); /* we only read */
+    closefile(filedes[1]); /* we only read */
     ok = SYSERR;
     while (0 < READ(filedes[0], &c, sizeof(char))) {
       if (c == '.')
@@ -340,8 +340,8 @@
     else
       exit(1); /* child reported error */
   }
-  CLOSE(filedes[0]); /* we only write */
-  nullfd = OPEN("/dev/null",
+  closefile(filedes[0]); /* we only write */
+  nullfd = fileopen("/dev/null",
                O_CREAT | O_RDWR | O_APPEND);
   if (nullfd < 0) {
     perror("/dev/null");
@@ -367,7 +367,7 @@
 #ifndef MINGW
   char c = '.';
   WRITE(filedes[1], &c, sizeof(char)); /* signal success */
-  CLOSE(filedes[1]);
+  closefile(filedes[1]);
 #endif
 }
 

Modified: GNUnet/src/server/tcpserver.c
===================================================================
--- GNUnet/src/server/tcpserver.c       2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/server/tcpserver.c       2005-04-29 22:30:41 UTC (rev 710)
@@ -188,7 +188,7 @@
     clientList = session->next;
   else
     prev->next = session->next;
-  CLOSE(session->sock);
+  closefile(session->sock);
   GROW(session->writeBuffer,
        session->writeBufferSize,
        0);
@@ -429,7 +429,7 @@
        secs);
     sleep(secs);
     secs += 5; /* slow progression... */
-    CLOSE(listenerFD);
+    closefile(listenerFD);
     goto CREATE_SOCKET;
   }
 
@@ -518,7 +518,7 @@
          LOG(LOG_WARNING,
              _("Rejected unauthorized connection from %u.%u.%u.%u.\n"),
              PRIP(ntohl(*(int*)&clientAddr.sin_addr)));
-         CLOSE(sock);
+         closefile(sock);
        } else {
          ClientHandle ch
            = MALLOC(sizeof(ClientThreadHandle));
@@ -660,7 +660,7 @@
   } /* while tcpserver_keep_running */
 
   /* shutdown... */
-  CLOSE(listenerFD);
+  closefile(listenerFD);
 
   /* close all sessions */
   while (clientList != NULL)
@@ -753,8 +753,8 @@
   LOG(LOG_DEBUG,
       "entering %s\n", __FUNCTION__);
 #endif
-  CLOSE(signalingPipe[0]);
-  CLOSE(signalingPipe[1]);
+  closefile(signalingPipe[0]);
+  closefile(signalingPipe[1]);
   /* free data structures */
   MUTEX_DESTROY(&handlerlock);
   MUTEX_DESTROY(&clientlock);

Modified: GNUnet/src/transports/http.c
===================================================================
--- GNUnet/src/transports/http.c        2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/transports/http.c        2005-04-29 22:30:41 UTC (rev 710)
@@ -352,7 +352,7 @@
   if (httpSession->sock != -1)
     if (0 != SHUTDOWN(httpSession->sock, SHUT_RDWR))
       LOG_STRERROR(LOG_EVERYTHING, "shutdown");
-  CLOSE(httpSession->sock);
+  closefile(httpSession->sock);
   httpSession->sock = -1;
   httpDisconnect(tsessions[i]);
   tsessions[i] = tsessions[--tsessionCount];
@@ -793,7 +793,7 @@
            LOG(LOG_INFO,
                _("Rejected blacklisted connection from %u.%u.%u.%u.\n"),
                PRIP(ntohl(*(int*)&clientAddr.sin_addr)));
-           CLOSE(sock);
+           closefile(sock);
          } else {
 #if DEBUG_HTTP
            LOG(LOG_INFO,
@@ -885,7 +885,7 @@
   }
   /* shutdown... */
   if (http_sock != -1) {
-    CLOSE(http_sock);
+    closefile(http_sock);
     http_sock = -1;
   }
   /* close all sessions */
@@ -1111,7 +1111,7 @@
     return SYSERR;
   }
   if (0 != setBlocking(sock, NO)) {
-    CLOSE(sock);
+    closefile(sock);
     LOG_STRERROR(LOG_FAILURE, "setBlocking");
     return SYSERR;
   }
@@ -1141,7 +1141,7 @@
        PRIP(ntohl(*(int*)&haddr->ip)),
        ntohs(haddr->port),
        STRERROR(errno));
-    CLOSE(sock);
+    closefile(sock);
     return SYSERR;
   }
   httpSession = MALLOC(sizeof(HTTPSession));
@@ -1255,8 +1255,8 @@
                       0);
     if (http_sock < 0) {
       LOG_STRERROR(LOG_FAILURE, "socket");
-      CLOSE(http_pipe[0]);
-      CLOSE(http_pipe[1]);
+      closefile(http_pipe[0]);
+      closefile(http_pipe[1]);
       SEMAPHORE_FREE(serverSignal);
       serverSignal = NULL;
       http_shutdown = YES;
@@ -1288,7 +1288,7 @@
          _("Could not bind the HTTP listener to port %d. "
            "No transport service started.\n"),
          getGNUnetHTTPPort());
-      CLOSE(http_sock);
+      closefile(http_sock);
       SEMAPHORE_FREE(serverSignal);
       serverSignal = NULL;
       return SYSERR;
@@ -1303,7 +1303,7 @@
   } else {
     LOG_STRERROR(LOG_ERROR,
                 "pthread_create");
-    CLOSE(http_sock);
+    closefile(http_sock);
     SEMAPHORE_FREE(serverSignal);
     serverSignal = NULL;
     return SYSERR;
@@ -1330,10 +1330,10 @@
   } else
     haveThread = NO;
   serverSignal = NULL;
-  CLOSE(http_pipe[1]);
-  CLOSE(http_pipe[0]);
+  closefile(http_pipe[1]);
+  closefile(http_pipe[0]);
   if (http_sock != -1) {
-    CLOSE(http_sock);
+    closefile(http_sock);
     http_sock = -1;
   }
   if (haveThread == YES)

Modified: GNUnet/src/transports/smtp.c
===================================================================
--- GNUnet/src/transports/smtp.c        2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/transports/smtp.c        2005-04-29 22:30:41 UTC (rev 710)
@@ -313,7 +313,7 @@
                  (struct sockaddr*)&soaddr,
                  sizeof(soaddr))) {
     LOG_STRERROR(LOG_FAILURE, "connect");
-    CLOSE(res);
+    closefile(res);
     return -1;
   }
   return res;
@@ -439,7 +439,7 @@
     unsigned int size;
     MessagePack * coreMP;
 
-    smtp_pipe = OPEN(pipename, O_RDONLY);
+    smtp_pipe = fileopen(pipename, O_RDONLY);
     fdes = fdopen(smtp_pipe, "r");
     while ( smtp_shutdown == NO ) {
       do {
@@ -783,7 +783,7 @@
   smtp_sock = connectToSMTPServer();
   if ( smtp_sock == -1) {
     LOG_STRERROR(LOG_ERROR, "connectToSMTPServer");
-    CLOSE(smtp_sock);
+    closefile(smtp_sock);
     return SYSERR;
   }
   LOG(LOG_DEBUG,
@@ -794,7 +794,7 @@
     LOG(LOG_ERROR,
        _("SMTP server send unexpected response at %s:%d.\n"),
        __FILE__, __LINE__);
-    CLOSE(smtp_sock);
+    closefile(smtp_sock);
     return SYSERR;
   }
   email = NULL; /* abusing email as a flag... */
@@ -832,10 +832,10 @@
   void * unused;
 
   smtp_shutdown = YES;
-  CLOSE(smtp_pipe); /* close pipe. Waiting fgets should return NULL*/
+  closefile(smtp_pipe); /* close pipe. Waiting fgets should return NULL*/
   SEMAPHORE_DOWN(serverSignal);
   SEMAPHORE_FREE(serverSignal);
-  CLOSE(smtp_sock);
+  closefile(smtp_sock);
   PTHREAD_JOIN(&dispatchThread, &unused);
   return OK;
 }

Modified: GNUnet/src/transports/tcp.c
===================================================================
--- GNUnet/src/transports/tcp.c 2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/transports/tcp.c 2005-04-29 22:30:41 UTC (rev 710)
@@ -303,7 +303,7 @@
   if (tcpSession->sock != -1)
     if (0 != SHUTDOWN(tcpSession->sock, SHUT_RDWR))
       LOG_STRERROR(LOG_EVERYTHING, "shutdown");
-  CLOSE(tcpSession->sock);
+  closefile(tcpSession->sock);
   tcpSession->sock = -1;
   tcpDisconnect(tsessions[i]);
   tsessions[i] = tsessions[--tsessionCount];
@@ -669,7 +669,7 @@
                _("Rejected blacklisted connection from %u.%u.%u.%u.\n"),
                PRIP(ntohl(*(int*)&clientAddr.sin_addr)));
            SHUTDOWN(sock, 2);
-           CLOSE(sock);
+           closefile(sock);
          } else {
 #if DEBUG_TCP
            LOG(LOG_INFO,
@@ -770,7 +770,7 @@
   }
   /* shutdown... */
   if (tcp_sock != -1) {
-    CLOSE(tcp_sock);
+    closefile(tcp_sock);
     tcp_sock = -1;
   }
   /* close all sessions */
@@ -1069,7 +1069,7 @@
     return SYSERR;
   }
   if (0 != setBlocking(sock, NO)) {
-    CLOSE(sock);
+    closefile(sock);
     LOG_STRERROR(LOG_FAILURE, "setBlocking");
     return SYSERR;
   }
@@ -1093,12 +1093,12 @@
        PRIP(ntohl(*(int*)&haddr->ip)),
        ntohs(haddr->port),
        STRERROR(errno));
-    CLOSE(sock);
+    closefile(sock);
     return SYSERR;
   }
   if (0 != setBlocking(sock, NO)) {
     LOG_STRERROR(LOG_FAILURE, "setBlocking");
-    CLOSE(sock);
+    closefile(sock);
     return SYSERR;
   }
   tcpSession = MALLOC(sizeof(TCPSession));
@@ -1233,8 +1233,8 @@
                      0);
     if (tcp_sock < 0) {
       LOG_STRERROR(LOG_FAILURE, "socket");
-      CLOSE(tcp_pipe[0]);
-      CLOSE(tcp_pipe[1]);
+      closefile(tcp_pipe[0]);
+      closefile(tcp_pipe[1]);
       SEMAPHORE_FREE(serverSignal);
       serverSignal = NULL;
       tcp_shutdown = YES;
@@ -1265,7 +1265,7 @@
       LOG(LOG_ERROR,
          _("Failed to start transport service on port %d.\n"),
          getGNUnetTCPPort());
-      CLOSE(tcp_sock);
+      closefile(tcp_sock);
       tcp_sock = -1;
       SEMAPHORE_FREE(serverSignal);
       serverSignal = NULL;
@@ -1281,7 +1281,7 @@
   } else {
     LOG_STRERROR(LOG_ERROR,
                 "pthread_create");
-    CLOSE(tcp_sock);
+    closefile(tcp_sock);
     SEMAPHORE_FREE(serverSignal);
     serverSignal = NULL;
     return SYSERR;
@@ -1308,10 +1308,10 @@
   } else
     haveThread = NO;
   serverSignal = NULL;
-  CLOSE(tcp_pipe[1]);
-  CLOSE(tcp_pipe[0]);
+  closefile(tcp_pipe[1]);
+  closefile(tcp_pipe[0]);
   if (tcp_sock != -1) {
-    CLOSE(tcp_sock);
+    closefile(tcp_sock);
     tcp_sock = -1;
   }
   if (haveThread == YES)

Modified: GNUnet/src/transports/tcp6.c
===================================================================
--- GNUnet/src/transports/tcp6.c        2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/transports/tcp6.c        2005-04-29 22:30:41 UTC (rev 710)
@@ -295,7 +295,7 @@
   if (-1 != tcp6Session->sock)
     if (0 != SHUTDOWN(tcp6Session->sock, SHUT_RDWR))
       LOG_STRERROR(LOG_EVERYTHING, "shutdown");
-  CLOSE(tcp6Session->sock);
+  closefile(tcp6Session->sock);
   tcp6Session->sock = -1;
   tcp6Disconnect(tsessions[i]);
   tsessions[i] = tsessions[--tsessionCount];
@@ -659,7 +659,7 @@
                          INET6_ADDRSTRLEN));
            FREE(tmp);
            SHUTDOWN(sock, 2);
-           CLOSE(sock);
+           closefile(sock);
          } else
            createNewSession(sock);
        } else {
@@ -744,7 +744,7 @@
   }
   /* shutdown... */
   if (tcp6_sock != -1) {
-    CLOSE(tcp6_sock);
+    closefile(tcp6_sock);
     tcp6_sock = -1;
   }
   /* close all sessions */
@@ -1033,7 +1033,7 @@
     if (sock < 0)
       continue;
     if (0 != setBlocking(sock, NO)) {
-      CLOSE(sock);
+      closefile(sock);
       LOG_STRERROR(LOG_FAILURE, "setBlocking");
       return SYSERR;
     }
@@ -1045,7 +1045,7 @@
     if ( (i < 0) &&
         (errno != EINPROGRESS) ) {
       LOG_STRERROR(LOG_WARNING, "connect");
-      CLOSE(sock);
+      closefile(sock);
       sock = -1;
       continue;
     }
@@ -1058,7 +1058,7 @@
   }
   if (0 != setBlocking(sock, NO)) {
     LOG_STRERROR(LOG_FAILURE, "setBlocking");
-    CLOSE(sock);
+    closefile(sock);
     return SYSERR;
   }
   tcp6Session = MALLOC(sizeof(TCP6Session));
@@ -1176,8 +1176,8 @@
                       0);
     if (tcp6_sock < 0) {
       LOG_STRERROR(LOG_FAILURE, "socket");
-      CLOSE(tcp6_pipe[0]);
-      CLOSE(tcp6_pipe[1]);
+      closefile(tcp6_pipe[0]);
+      closefile(tcp6_pipe[1]);
       SEMAPHORE_FREE(serverSignal);
       serverSignal = NULL;
       tcp6_shutdown = YES;
@@ -1208,7 +1208,7 @@
       LOG(LOG_ERROR,
          _("Failed to start transport service on port %d.\n"),
          getGNUnetTCP6Port());
-      CLOSE(tcp6_sock);
+      closefile(tcp6_sock);
       tcp6_sock = -1;
       SEMAPHORE_FREE(serverSignal);
       serverSignal = NULL;
@@ -1224,7 +1224,7 @@
   } else {
     LOG_STRERROR(LOG_ERROR,
                 "pthread_create");
-    CLOSE(tcp6_sock);
+    closefile(tcp6_sock);
     SEMAPHORE_FREE(serverSignal);
     serverSignal = NULL;
     return SYSERR;
@@ -1251,10 +1251,10 @@
   } else
     haveThread = NO;
   serverSignal = NULL;
-  CLOSE(tcp6_pipe[1]);
-  CLOSE(tcp6_pipe[0]);
+  closefile(tcp6_pipe[1]);
+  closefile(tcp6_pipe[0]);
   if (tcp6_sock != -1) {
-    CLOSE(tcp6_sock);
+    closefile(tcp6_sock);
     tcp6_sock = -1;
   }
   if (haveThread == YES)

Modified: GNUnet/src/transports/udp.c
===================================================================
--- GNUnet/src/transports/udp.c 2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/transports/udp.c 2005-04-29 22:30:41 UTC (rev 710)
@@ -553,7 +553,7 @@
       PTHREAD_JOIN(&dispatchThread, &unused);
     }
   }
-  CLOSE(udp_sock);
+  closefile(udp_sock);
   udp_sock = -1;
   return OK;
 }

Modified: GNUnet/src/transports/udp6.c
===================================================================
--- GNUnet/src/transports/udp6.c        2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/transports/udp6.c        2005-04-29 22:30:41 UTC (rev 710)
@@ -568,7 +568,7 @@
       PTHREAD_JOIN(&dispatchThread, &unused);
     }
   }
-  CLOSE(udp6_sock);
+  closefile(udp6_sock);
   udp6_sock = -1;
   return OK;
 }

Modified: GNUnet/src/util/bloomfilter.c
===================================================================
--- GNUnet/src/util/bloomfilter.c       2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/util/bloomfilter.c       2005-04-29 22:30:41 UTC (rev 710)
@@ -385,9 +385,9 @@
 
   /* Try to open a bloomfilter file */
 #ifndef _MSC_VER
-  bf->fd = OPEN(filename, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
+  bf->fd = fileopen(filename, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
 #else
-  bf->fd = OPEN(filename, O_WRONLY|O_CREAT, S_IREAD|S_IWRITE);
+  bf->fd = fileopen(filename, O_WRONLY|O_CREAT, S_IREAD|S_IWRITE);
 #endif
   if (-1 == bf->fd) {
     LOG_FILE_STRERROR(LOG_FAILURE, "open", filename);
@@ -449,7 +449,7 @@
   if (NULL == bf)
     return;
   MUTEX_DESTROY(&bf->lock);
-  CLOSE(bf->fd);
+  closefile(bf->fd);
   FREE(bf->bitArray);
   FREE(bf);
 }

Modified: GNUnet/src/util/hashing.c
===================================================================
--- GNUnet/src/util/hashing.c   2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/util/hashing.c   2005-04-29 22:30:41 UTC (rev 710)
@@ -328,7 +328,7 @@
   int fh;
   struct sha512_ctx ctx;
 
-  fh = OPEN(filename,
+  fh = fileopen(filename,
 #ifdef O_LARGEFILE
            O_RDONLY | O_LARGEFILE
 #else
@@ -348,7 +348,7 @@
     if (delta != READ(fh,
                      buf,
                      delta)) {
-      CLOSE(fh);
+      closefile(fh);
       FREE(buf);
       return SYSERR;
     }
@@ -360,7 +360,7 @@
     else
       break;
   }
-  CLOSE(fh);
+  closefile(fh);
   sha512_final(&ctx,
               (unsigned char*) ret);
   FREE(buf);

Modified: GNUnet/src/util/identity.c
===================================================================
--- GNUnet/src/util/identity.c  2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/util/identity.c  2005-04-29 22:30:41 UTC (rev 710)
@@ -171,7 +171,7 @@
   
   if (ioctl(sockfd, SIOCGIFCONF, &ifc) == -1) {
     LOG_STRERROR(LOG_WARNING, "ioctl");
-    CLOSE(sockfd);
+    closefile(sockfd);
     FREE(interfaces);
     return SYSERR;
   }
@@ -191,7 +191,7 @@
     memcpy(identity,
           &(((struct sockaddr_in *)&ifr[i].ifr_addr)->sin_addr),
           sizeof(struct in_addr));
-    CLOSE(sockfd);
+    closefile(sockfd);
     FREE(interfaces);
     return OK;
   }
@@ -213,12 +213,12 @@
     memcpy(identity,
           &(((struct sockaddr_in *)&ifr[i].ifr_addr)->sin_addr),
           sizeof(struct in_addr));
-    CLOSE(sockfd);
+    closefile(sockfd);
     FREE(interfaces);
     return OK;
   }
 
-  CLOSE(sockfd);
+  closefile(sockfd);
   LOG(LOG_WARNING,
       _("Could not obtain IP for interface '%s' using '%s'.\n"),
       "ioctl",

Modified: GNUnet/src/util/initialize.c
===================================================================
--- GNUnet/src/util/initialize.c        2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/util/initialize.c        2005-04-29 22:30:41 UTC (rev 710)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002 Christian Grothoff (and other contributing authors)
+     (C) 2001, 2002, 2005 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
@@ -110,7 +110,7 @@
 void getLocaleDir(char *dir)
 {
 #ifdef WINDOWS
-       conv_to_win_path("/share/locale/", dir);
+       plibc_conv_to_win_path("/share/locale/", dir);
 #else
        strcpy(dir, LOCALEDIR);
 #endif

Modified: GNUnet/src/util/io.c
===================================================================
--- GNUnet/src/util/io.c        2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/util/io.c        2005-04-29 22:30:41 UTC (rev 710)
@@ -315,7 +315,7 @@
 /**
  * Open a file
  */
-int OPEN(const char *filename, int oflag, ...)
+int fileopen(const char *filename, int oflag, ...)
 {
   int mode;
   char *fn;
@@ -324,7 +324,7 @@
   char szFile[_MAX_PATH + 1];
   long lRet;
 
-  if ((lRet = conv_to_win_path(filename, szFile)) != ERROR_SUCCESS)
+  if ((lRet = plibc_conv_to_win_path(filename, szFile)) != ERROR_SUCCESS)
   {
     errno = ENOENT;
     SetLastError(lRet);

Modified: GNUnet/src/util/semaphore.c
===================================================================
--- GNUnet/src/util/semaphore.c 2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/util/semaphore.c 2005-04-29 22:30:41 UTC (rev 710)
@@ -651,13 +651,13 @@
   ret->filename = STRDUP(basename);
   fd = -1;
   while (fd == -1) {
-    fd = OPEN(basename,
+    fd = fileopen(basename,
              O_CREAT|O_RDWR|O_EXCL,
              S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP /* 660 */);
     if ( (fd == -1) &&
         (errno == EEXIST) ) {
       /* try without creation */
-      fd = OPEN(basename,
+      fd = fileopen(basename,
                O_RDWR,
                S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP /* 660 */);
       /* possibly the file was deleted in the meantime,
@@ -970,7 +970,7 @@
          __LINE__);
     FREE(sem->filename);
     FLOCK(sem->fd, LOCK_UN);
-    CLOSE(sem->fd);
+    closefile(sem->fd);
   }
 #else
 #endif

Modified: GNUnet/src/util/state.c
===================================================================
--- GNUnet/src/util/state.c     2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/util/state.c     2005-04-29 22:30:41 UTC (rev 710)
@@ -125,7 +125,7 @@
           "%s/%s",
           dbh,
           name);
-  fd = OPEN(fil,
+  fd = fileopen(fil,
            O_RDONLY,
            S_IRUSR);
   if (fd == -1) {
@@ -135,7 +135,7 @@
   fsize = getFileSize(fil);
   FREE(fil);
   if (fsize == 0) { /* also invalid! */
-    CLOSE(fd);
+    closefile(fd);
     return -1;
   }
 
@@ -143,7 +143,7 @@
   size = READ(fd,
              *result,
              fsize);
-  CLOSE(fd);
+  closefile(fd);
   if (size == -1) {
     FREE(*result);
     *result = NULL;
@@ -176,7 +176,7 @@
           "%s/%s",
           dbh,
           name);
-  fd = OPEN(fil,
+  fd = fileopen(fil,
            O_RDWR|O_CREAT,
            S_IRUSR|S_IWUSR);
   if (fd == -1) {
@@ -191,7 +191,7 @@
   WRITE(fd,
        block,
        len);
-  CLOSE(fd);
+  closefile(fd);
   return OK;
 }
 
@@ -219,7 +219,7 @@
           "%s/%s",
           dbh,
           name);
-  fd = OPEN(fil,
+  fd = fileopen(fil,
            O_RDWR|O_CREAT,
            S_IRUSR|S_IWUSR);
   if (fd == -1) {
@@ -232,7 +232,7 @@
        len);
   if (0 != ftruncate(fd, len))
     LOG_FILE_STRERROR(LOG_WARNING, "ftruncate", fil);
-  CLOSE(fd);
+  closefile(fd);
   FREE(fil);
   return OK;
 }

Modified: GNUnet/src/util/storage.c
===================================================================
--- GNUnet/src/util/storage.c   2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/util/storage.c   2005-04-29 22:30:41 UTC (rev 710)
@@ -342,7 +342,7 @@
 #else
   fn = MALLOC(MAX_PATH + 1);
 
-  if ((lRet = conv_to_win_path(fil, buffer)) != ERROR_SUCCESS)
+  if ((lRet = plibc_conv_to_win_path(fil, buffer)) != ERROR_SUCCESS)
   {
        SetErrnoFromWinError(lRet);
 
@@ -453,11 +453,11 @@
 
   if ((fileName == NULL) || (result == NULL))
     return -1;
-  handle = OPEN(fileName,O_RDONLY,S_IRUSR);
+  handle = fileopen(fileName,O_RDONLY,S_IRUSR);
   if (handle < 0)
     return -1;
   size = READ(handle, result, len);
-  CLOSE(handle);
+  closefile(handle);
   return size;
 }
 
@@ -477,7 +477,7 @@
      present, otherwise overwrite */
   if ((fileName == NULL) || (buffer == NULL))
     return;
-  handle = OPEN(fileName,
+  handle = fileopen(fileName,
                O_CREAT|O_WRONLY,S_IRUSR|S_IWUSR);
   if (handle == -1) {
     LOG_FILE_STRERROR(LOG_WARNING, "open", fileName);
@@ -487,7 +487,7 @@
   if (n != WRITE(handle, buffer, n))
     LOG_FILE_STRERROR(LOG_WARNING, "write", fileName);
   CHMOD(fileName, atoo(mode));
-  CLOSE(handle);
+  closefile(handle);
 }
 
 /**
@@ -608,37 +608,13 @@
 void close_(int fd,
            const char * filename,
            int linenumber) {
-#ifdef MINGW
-  /* Windows sockets have to be closed using closesocket() */
-  if (closesocket(fd) != 0) {
-#endif
-    if (0 != close(fd)) {
-#ifdef MINGW
-      /* Close Windows handle */
-      if (! CloseHandle((HANDLE) fd)) {
-#endif
+    if (0 != CLOSE(fd)) {
        LOG(LOG_INFO,
            _("'%s' failed at %s:%d with error: %s\n"),
-#ifdef MINGW
-           "CloseHandle",
-#else
            "close",
-#endif
            filename,
            linenumber, STRERROR(errno));
       }
-#ifdef MINGW
-    } else {
-      /* discard blocking mode */
-      unsigned int uiIndex;
-      WaitForSingleObject(hSocksLock, INFINITE);
-      for(uiIndex = 0; uiIndex < uiSockCount; uiIndex++)
-        if (pSocks[uiIndex].s == fd)
-          pSocks[uiIndex].s = -1;
-      ReleaseMutex(hSocksLock);
-    }
-  }
-#endif
 }
 
 #define COPY_BLK_SIZE 65536
@@ -658,20 +634,20 @@
 
   buf = MALLOC(COPY_BLK_SIZE);
   pos = 0;
-  in = OPEN(src, O_RDONLY
+  in = fileopen(src, O_RDONLY
 #ifdef O_LARGEFILE
             | O_LARGEFILE
 #endif
            );
   if (in == -1)
     return SYSERR;
-  out = OPEN(dst, O_WRONLY | O_CREAT | O_EXCL
+  out = fileopen(dst, O_WRONLY | O_CREAT | O_EXCL
 #ifdef O_LARGEFILE
             | O_LARGEFILE
 #endif
             , S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
   if (out == -1) {
-    CLOSE(in);
+    closefile(in);
     return SYSERR;
   }
   size = getFileSize(src);
@@ -685,12 +661,12 @@
       goto FAIL;
     pos += len;
   }
-  CLOSE(in);
-  CLOSE(out);
+  closefile(in);
+  closefile(out);
   return OK;
  FAIL:
-  CLOSE(in);
-  CLOSE(out);
+  closefile(in);
+  closefile(out);
   return SYSERR;
 }
 

Modified: GNUnet/src/util/tcpio.c
===================================================================
--- GNUnet/src/util/tcpio.c     2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/util/tcpio.c     2005-04-29 22:30:41 UTC (rev 710)
@@ -166,7 +166,7 @@
        PRIP(ntohl(*(int*)&sock->ip.addr)),
        sock->port,
        STRERROR(errno));
-    CLOSE(sock->socket);
+    closefile(sock->socket);
     sock->socket = -1;
     return SYSERR;
   }
@@ -442,7 +442,7 @@
     sock->socket = -1;
     if (0 != SHUTDOWN(i, SHUT_RDWR))
       LOG_STRERROR(LOG_DEBUG, "shutdown");
-    CLOSE(i);
+    closefile(i);
   }
   sock->outBufLen = 0;
   FREENONNULL(sock->outBufPending);

Modified: GNUnet/src/util/win/Makefile.am
===================================================================
--- GNUnet/src/util/win/Makefile.am     2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/util/win/Makefile.am     2005-04-29 22:30:41 UTC (rev 710)
@@ -5,11 +5,7 @@
 if MINGW
   libwin_la_SOURCES = \
      winproc.c \
-     win_printf.c \
-     winselect.c \
-     winstrptime.c \
-     win.cc \
-     inet_pton.c
+     win.cc
 endif
 
 if CYGWIN

Deleted: GNUnet/src/util/win/inet_pton.c
===================================================================
--- GNUnet/src/util/win/inet_pton.c     2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/util/win/inet_pton.c     2005-04-29 22:30:41 UTC (rev 710)
@@ -1,348 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2001, 2002, 2003, 2004 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/inet_pton.c
- * @brief inet_pton for Windows
- * @author http://net-snmp.sourceforge.net
- */
-
-/*     Id: inet_pton.c,v 1.5 2001/04/13 15:24:35 lukem Exp     */
-/*     $NetBSD: inet_pton.c,v 1.16 2000/02/07 18:51:02 itojun Exp $    */
-
-/* Copyright (c) 1996 by Internet Software Consortium.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#include "platform.h"
-
-#ifndef HAVE_INET_PTON
-
-#if HAVE_ARPA_NAMESER_H
-#include <arpa/nameser.h>
-#endif
-
-  /*
-   * Net-SNMP Win32 additions
-   */
-#if HAVE_WINSOCK_H
-#include <winsock2.h>
-#include <errno.h>
-#include <stdio.h>
-#endif
-
-#ifndef EAFNOSUPPORT
-#define EAFNOSUPPORT            WSAEAFNOSUPPORT
-#endif
-
-#ifndef IN6ADDRSZ
-#define        IN6ADDRSZ       16
-#endif
-
-#ifndef INT16SZ
-#define        INT16SZ         2
-#endif
-  /*
-   * End of Net-SNMP Win32 additions
-   */
-
-#ifndef INADDRSZ
-#define        INADDRSZ        4
-#endif
-
-/*
- *  Don't even consider trying to compile this on a system where
- * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
- */
-
-static int     inet_pton4(const char *src, u_char *dst, int pton);
-#if USE_IPV6
-static int     inet_pton6(const char *src, u_char *dst);
-#endif
-
-/* int
- * inet_pton(af, src, dst)
- *     convert from presentation format (which usually means ASCII printable)
- *     to network format (which is usually some kind of binary format).
- * return:
- *     1 if the address was valid for the specified address family
- *     0 if the address wasn't valid (`dst' is untouched in this case)
- *     -1 if some other error occurred (`dst' is untouched in this case, too)
- * author:
- *     Paul Vixie, 1996.
- */
-int
-inet_pton(af, src, dst)
-       int af;
-       const char *src;
-       void *dst;
-{
-
-       switch (af) {
-       case AF_INET:
-               return (inet_pton4(src, dst, 1));
-#if USE_IPV6
-       case AF_INET6:
-               return (inet_pton6(src, dst));
-#endif
-       default:
-               errno = EAFNOSUPPORT;
-               return (-1);
-       }
-       /* NOTREACHED */
-}
-
-/* int
- * inet_pton4(src, dst, pton)
- *     when last arg is 0: inet_aton(). with hexadecimal, octal and shorthand.
- *     when last arg is 1: inet_pton(). decimal dotted-quad only.
- * return:
- *     1 if `src' is a valid input, else 0.
- * notice:
- *     does not touch `dst' unless it's returning 1.
- * author:
- *     Paul Vixie, 1996.
- */
-static int
-inet_pton4(src, dst, pton)
-       const char *src;
-       u_char *dst;
-       int pton;
-{
-       u_int val;
-       u_int digit;
-       int base, n;
-       unsigned char c;
-       u_int parts[4];
-       register u_int *pp = parts;
-
-       c = *src;
-       for (;;) {
-               /*
-                * Collect number up to ``.''.
-                * Values are specified as for C:
-                * 0x=hex, 0=octal, isdigit=decimal.
-                */
-               if (!isdigit(c))
-                       return (0);
-               val = 0; base = 10;
-               if (c == '0') {
-                       c = *++src;
-                       if (c == 'x' || c == 'X')
-                               base = 16, c = *++src;
-                       else if (isdigit(c) && c != '9')
-                               base = 8;
-               }
-               /* inet_pton() takes decimal only */
-               if (pton && base != 10)
-                       return (0);
-               for (;;) {
-                       if (isdigit(c)) {
-                               digit = c - '0';
-                               if (digit >= base)
-                                       break;
-                               val = (val * base) + digit;
-                               c = *++src;
-                       } else if (base == 16 && isxdigit(c)) {
-                               digit = c + 10 - (islower(c) ? 'a' : 'A');
-                               if (digit >= 16)
-                                       break;
-                               val = (val << 4) | digit;
-                               c = *++src;
-                       } else
-                               break;
-               }
-               if (c == '.') {
-                       /*
-                        * Internet format:
-                        *      a.b.c.d
-                        *      a.b.c   (with c treated as 16 bits)
-                        *      a.b     (with b treated as 24 bits)
-                        *      a       (with a treated as 32 bits)
-                        */
-                       if (pp >= parts + 3)
-                               return (0);
-                       *pp++ = val;
-                       c = *++src;
-               } else
-                       break;
-       }
-       /*
-        * Check for trailing characters.
-        */
-       if (c != '\0' && !isspace(c))
-               return (0);
-       /*
-        * Concoct the address according to
-        * the number of parts specified.
-        */
-       n = pp - parts + 1;
-       /* inet_pton() takes dotted-quad only.  it does not take shorthand. */
-       if (pton && n != 4)
-               return (0);
-       switch (n) {
-
-       case 0:
-               return (0);             /* initial nondigit */
-
-       case 1:                         /* a -- 32 bits */
-               break;
-
-       case 2:                         /* a.b -- 8.24 bits */
-               if (parts[0] > 0xff || val > 0xffffff)
-                       return (0);
-               val |= parts[0] << 24;
-               break;
-
-       case 3:                         /* a.b.c -- 8.8.16 bits */
-               if ((parts[0] | parts[1]) > 0xff || val > 0xffff)
-                       return (0);
-               val |= (parts[0] << 24) | (parts[1] << 16);
-               break;
-
-       case 4:                         /* a.b.c.d -- 8.8.8.8 bits */
-               if ((parts[0] | parts[1] | parts[2] | val) > 0xff)
-                       return (0);
-               val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
-               break;
-       }
-       if (dst) {
-               val = htonl(val);
-               memcpy(dst, &val, INADDRSZ);
-       }
-       return (1);
-}
-
-#if USE_IPV6
-/* int
- * inet_pton6(src, dst)
- *     convert presentation level address to network order binary form.
- * return:
- *     1 if `src' is a valid [RFC1884 2.2] address, else 0.
- * notice:
- *     (1) does not touch `dst' unless it's returning 1.
- *     (2) :: in a full address is silently ignored.
- * credit:
- *     inspired by Mark Andrews.
- * author:
- *     Paul Vixie, 1996.
- */
-static int
-inet_pton6(src, dst)
-       const char *src;
-       u_char *dst;
-{
-       static const char xdigits_l[] = "0123456789abcdef",
-                         xdigits_u[] = "0123456789ABCDEF";
-       u_char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
-       const char *xdigits, *curtok;
-       int ch, saw_xdigit;
-       u_int val;
-
-       memset((tp = tmp), '\0', IN6ADDRSZ);
-       endp = tp + IN6ADDRSZ;
-       colonp = NULL;
-       /* Leading :: requires some special handling. */
-       if (*src == ':')
-               if (*++src != ':')
-                       return (0);
-       curtok = src;
-       saw_xdigit = 0;
-       val = 0;
-       while ((ch = *src++) != '\0') {
-               const char *pch;
-
-               if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
-                       pch = strchr((xdigits = xdigits_u), ch);
-               if (pch != NULL) {
-                       val <<= 4;
-                       val |= (pch - xdigits);
-                       if (val > 0xffff)
-                               return (0);
-                       saw_xdigit = 1;
-                       continue;
-               }
-               if (ch == ':') {
-                       curtok = src;
-                       if (!saw_xdigit) {
-                               if (colonp)
-                                       return (0);
-                               colonp = tp;
-                               continue;
-                       } else if (*src == '\0')
-                               return (0);
-                       if (tp + INT16SZ > endp)
-                               return (0);
-                       *tp++ = (u_char) (val >> 8) & 0xff;
-                       *tp++ = (u_char) val & 0xff;
-                       saw_xdigit = 0;
-                       val = 0;
-                       continue;
-               }
-               if (ch == '.' && ((tp + INADDRSZ) <= endp) &&
-                   inet_pton4(curtok, tp, 1) > 0) {
-                       tp += INADDRSZ;
-                       saw_xdigit = 0;
-                       break;  /* '\0' was seen by inet_pton4(). */
-               }
-               return (0);
-       }
-       if (saw_xdigit) {
-               if (tp + INT16SZ > endp)
-                       return (0);
-               *tp++ = (u_char) (val >> 8) & 0xff;
-               *tp++ = (u_char) val & 0xff;
-       }
-       if (colonp != NULL) {
-               /*
-                * Since some memmove()'s erroneously fail to handle
-                * overlapping regions, we'll do the shift by hand.
-                */
-               const int n = tp - colonp;
-               int i;
-
-               if (tp == endp)
-                       return (0);
-               for (i = 1; i <= n; i++) {
-                       endp[- i] = colonp[n - i];
-                       colonp[n - i] = 0;
-               }
-               tp = endp;
-       }
-       if (tp != endp)
-               return (0);
-       memcpy(dst, tmp, IN6ADDRSZ);
-       return (1);
-}
-#endif
-
-#endif /* HAVE_INET_PTON */

Modified: GNUnet/src/util/win/win.cc
===================================================================
--- GNUnet/src/util/win/win.cc  2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/util/win/win.cc  2005-04-29 22:30:41 UTC (rev 710)
@@ -32,236 +32,6 @@
 
 extern "C" {
 
-BOOL CreateShortcut(const char *pszSrc, const char *pszDest)
-{
-    /* Create shortcut */
-    IShellLink *pLink;
-    IPersistFile *pFile;
-    WCHAR *pwszDest;
-    char *pszFileLnk;
-    HRESULT hRes;
-    
-    CoInitialize(NULL);
-    
-    if ((strlen(pszSrc) > _MAX_PATH) || (strlen(pszDest) + 4 > _MAX_PATH))
-    {
-      CoUninitialize();
-      errno = ENAMETOOLONG;
-      
-      return FALSE;
-    }
-    
-    /* Create Shortcut-Object */
-    if (CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
-        IID_IShellLink, (void **) &pLink) != S_OK)
-    {
-      CoUninitialize();
-      errno = ESTALE;
-      
-      return FALSE;
-    }
-  
-    /* Set target path */
-    pLink->SetPath(pszSrc);
-  
-    /* Get File-Object */
-    if (pLink->QueryInterface(IID_IPersistFile, (void **) &pFile) != S_OK)
-    {
-      free(pwszDest);
-      pLink->Release();
-      CoUninitialize();
-      errno = ESTALE;
-     
-      return FALSE;
-    }
-
-    /* shortcuts have the extension .lnk */
-    pszFileLnk = (char *) malloc(strlen(pszDest) + 5);
-    sprintf(pszFileLnk, "%s.lnk", pszDest);
-  
-    /* Turn filename into widechars */
-    pwszDest = (WCHAR *) malloc((_MAX_PATH + 5) * sizeof(WCHAR));
-    MultiByteToWideChar(CP_ACP, 0, pszFileLnk, -1, pwszDest, _MAX_PATH);
-    
-    free(pszFileLnk);
-    
-    /* Save shortcut */
-    if (FAILED(hRes = pFile->Save((LPCOLESTR) pwszDest, TRUE)))
-    {
-      free(pwszDest);
-      pLink->Release();
-      pFile->Release();
-      CoUninitialize();
-      SetErrnoFromHRESULT(hRes);
-  
-      return FALSE;
-    }
-  
-    free(pwszDest);
-    
-    pFile->Release();
-    pLink->Release();
-    CoUninitialize();
-    errno = 0;
-      
-    return TRUE;
-}
-
-BOOL DereferenceShortcut(char *pszShortcut)
-{
-  IShellLink *pLink;
-  IPersistFile *pFile;
-  WCHAR *pwszShortcut;
-  char *pszLnk;
-  int iErr, iLen;
-  HRESULT hRes;
-  HANDLE hLink;
-  char szTarget[_MAX_PATH + 1];
-
-  if (! *pszShortcut)
-    return TRUE;
-
-  CoInitialize(NULL);
-  szTarget[0] = 0;
-  
-  /* Create Shortcut-Object */
-  if (CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
-      IID_IShellLink, (void **) &pLink) != S_OK)
-  {
-    CoUninitialize();
-    errno = ESTALE;
-    
-    return FALSE;
-  }
-
-  /* Get File-Object */
-  if (pLink->QueryInterface(IID_IPersistFile, (void **) &pFile) != S_OK)
-  {
-    pLink->Release();
-    CoUninitialize();
-    errno = ESTALE;
-    
-    return FALSE;
-  }
-
-  pwszShortcut = (WCHAR *) malloc((_MAX_PATH + 1) * sizeof(WCHAR));
-
-  /* Shortcuts have the extension .lnk
-     If it isn't there, append it */
-  iLen = strlen(pszShortcut);
-  if (iLen > 4 && (strcmp(pszShortcut + iLen - 4, ".lnk") != 0))
-  {
-    HANDLE hLink;
-    
-    pszLnk = (char *) malloc(iLen + 5);
-    sprintf(pszLnk, "%s.lnk", pszShortcut);
-  }
-  else
-    pszLnk = strdup(pszShortcut);
-
-  /* Make sure the path refers to a file */
-  hLink = CreateFile(pszLnk, FILE_READ_DATA, FILE_SHARE_READ | 
FILE_SHARE_WRITE,
-                   NULL, OPEN_EXISTING, 0, NULL);
-  if (hLink == INVALID_HANDLE_VALUE)
-  {
-    free(pszLnk);
-    SetErrnoFromWinError(GetLastError());
-    
-    if (errno == ENOENT)
-    {
-      /* There's no path with the ".lnk" extension.
-         We don't quit here, because we have to decide whether the path doesn't
-         exist or the path isn't a link. */
-
-      /* Is it a directory? */
-      if (GetFileAttributes(pszShortcut) & FILE_ATTRIBUTE_DIRECTORY)
-      {
-        errno = EINVAL;
-        return FALSE;
-      }
-
-      pszLnk = strdup(pszShortcut);
-      
-      hLink = CreateFile(pszLnk, FILE_READ_DATA, FILE_SHARE_READ |
-                FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
-      SetErrnoFromWinError(GetLastError());      
-    }
-    else
-      return FALSE; /* File/link is there but unaccessible */
-  }
-    
-  MultiByteToWideChar(CP_ACP, 0, pszLnk, -1, pwszShortcut, _MAX_PATH);
-  
-  /* Open shortcut */
-  if (FAILED(hRes = pFile->Load((LPCOLESTR) pwszShortcut, STGM_READ)))
-  {
-    pLink->Release();
-    pFile->Release();
-    free(pwszShortcut);
-    CoUninitialize();
-    
-    /* For some reason, opening an invalid link sometimes fails with 
ACCESSDENIED.
-       Since we have opened the file previously, insufficient priviledges
-       are rather not the problem. */
-    if (hRes == E_FAIL || hRes == E_ACCESSDENIED)
-    {
-      /* Check file magic */
-      if (hLink != INVALID_HANDLE_VALUE)
-      {
-        DWORD dwRead;
-        char pMagic[4] = {0, 0, 0, 0};
-        
-        ReadFile(hLink, pMagic, 4, &dwRead, NULL);
-        if (memcmp(pMagic, "L\0\0\0", 4) == 0)
-          SetErrnoFromHRESULT(hRes);
-        else
-          errno = EINVAL; /* No link */
-      }
-      /* else: errno was set above! */
-    }
-    else
-      SetErrnoFromHRESULT(hRes);
-
-    free(pszLnk);
-          
-    CloseHandle(hLink);
-    return FALSE;
-  }
-  
-  CloseHandle(hLink);
-  free(pszLnk);
-  free(pwszShortcut);
-  
-  /* Get target file */
-  if (FAILED(hRes = pLink->GetPath(szTarget, _MAX_PATH, NULL, 0)))
-  {
-    pLink->Release();
-    pFile->Release();
-    CoUninitialize();
-    
-    if (hRes == E_FAIL)
-      errno = EINVAL; /* Not a symlink */
-    else
-      SetErrnoFromHRESULT(hRes);
-    
-    return FALSE;
-  }
-
-  pFile->Release();
-  pLink->Release();
-  CoUninitialize();
-  errno = 0;
-  
-  if (szTarget[0] != 0)
-    return TRUE;
-  else
-  {
-    /* GetPath() did not return a valid path */
-    errno = EINVAL;
-    return FALSE;
-  }
-}
-
 /**
  * Enumerate all network adapters
  */
@@ -430,7 +200,7 @@
   if (! GNOpenSCManager)
     return 1;
 
-  conv_to_win_path("/bin/gnunetd.exe", szEXE + 1);
+  plibc_conv_to_win_path("/bin/gnunetd.exe", szEXE + 1);
   strcat(szEXE, "\" --win-service");
   hManager = GNOpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
   if (! hManager)

Deleted: GNUnet/src/util/win/win_printf.c
===================================================================
--- GNUnet/src/util/win/win_printf.c    2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/util/win/win_printf.c    2005-04-29 22:30:41 UTC (rev 710)
@@ -1,1201 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2005 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_printf.c
- * @brief Unix compatible printf for Windows
- * @author Felix von Leitner
- * @author Nils Durner
- * @see <a href="http://www.fefe.de/dietlibc/";>diet libc</a>
- */
-
-/* Stolen from Felix von Leitners "diet libc" 0.28 */
-
-#include <stdarg.h>
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <limits.h>
-#include <ctype.h>
-#include <io.h>
-
-#define WANT_ERROR_PRINTF 1
-#define WANT_LONGLONG_PRINTF 1
-#define WANT_NULL_PRINTF 1
-#define WANT_FLOATING_POINT_IN_PRINTF 1
-
-#define WANT_FLOATING_POINT_IN_SCANF
-#define WANT_LONGLONG_SCANF
-#define WANT_CHARACTER_CLASSES_IN_SCANF
-
-struct str_data {
-  unsigned char* str;
-  size_t len;
-  size_t size;
-};
-
-struct arg_printf {
-  void *data;
-  int (*put)(void*,size_t,void*);
-};
-
-static inline unsigned int skip_to(const unsigned char *format) {
-  unsigned int nr;
-  for (nr=0; format[nr] && (format[nr]!='%'); ++nr);
-  return nr;
-}
-
-#define A_WRITE(fn,buf,sz)     ((fn)->put((void*)(buf),(sz),(fn)->data))
-
-static const char pad_line[2][16]= { "                ", "0000000000000000", };
-static inline int write_pad(struct arg_printf* fn, int len, int padwith) {
-  int nr=0;
-  for (;len>15;len-=16,nr+=16) {
-    A_WRITE(fn,pad_line[(padwith=='0')?1:0],16);
-  }
-  if (len>0) {
-    A_WRITE(fn,pad_line[(padwith=='0')?1:0],(unsigned int)len); nr+=len;
-  }
-  return nr;
-}
-
-int __lltostr(char *s, int size, unsigned long long i, int base, char UpCase)
-{
-  char *tmp;
-  unsigned int j=0;
-
-  s[--size]=0;
-
-  tmp=s+size;
-
-  if ((base==0)||(base>36)) base=10;
-
-  j=0;
-  if (!i)
-  {
-    *(--tmp)='0';
-    j=1;
-  }
-
-  while((tmp>s)&&(i))
-  {
-    tmp--;
-    if ((*tmp=i%base+'0')>'9') *tmp+=(UpCase?'A':'a')-'9'-1;
-    i=i/base;
-    j++;
-  }
-  memmove(s,tmp,j+1);
-
-  return j;
-}
-
-int __ltostr(char *s, unsigned int size, unsigned long i, unsigned int base, 
int UpCase)
-{
-  char *tmp;
-  unsigned int j=0;
-
-  s[--size]=0;
-
-  tmp=s+size;
-
-  if ((base==0)||(base>36)) base=10;
-
-  j=0;
-  if (!i)
-  {
-    *(--tmp)='0';
-    j=1;
-  }
-
-  while((tmp>s)&&(i))
-  {
-    tmp--;
-    if ((*tmp=i%base+'0')>'9') *tmp+=(UpCase?'A':'a')-'9'-1;
-    i=i/base;
-    j++;
-  }
-  memmove(s,tmp,j+1);
-
-  return j;
-}
-
-static int copystring(char* buf,int maxlen, const char* s) {
-  int i;
-  for (i=0; i<3&&i<maxlen; ++i)
-    buf[i]=s[i];
-  if (i<maxlen) { buf[i]=0; ++i; }
-  return i;
-}
-
-int isinf(double d) {
-  union {
-    unsigned long long l;
-    double d;
-  } u;
-  u.d=d;
-  return (u.l==0x7FF0000000000000ll?1:u.l==0xFFF0000000000000ll?-1:0);
-}
-
-int isnan(double d) {
-  union {
-    unsigned long long l;
-    double d;
-  } u;
-  u.d=d;
-  return (u.l==0x7FF8000000000000ll || u.l==0x7FF0000000000000ll || 
u.l==0xfff8000000000000ll);
-}
-
-int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned 
int prec2) {
-#if 1
-  union {
-    unsigned long long l;
-    double d;
-  } u = { .d=d };
-  /* step 1: extract sign, mantissa and exponent */
-  signed long e=((u.l>>52)&((1<<11)-1))-1023;
-#else
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-  signed long e=(((((unsigned long*)&d)[1])>>20)&((1<<11)-1))-1023;
-#else
-  signed long e=(((*((unsigned long*)&d))>>20)&((1<<11)-1))-1023;
-#endif
-#endif
-/*  unsigned long long m=u.l & ((1ull<<52)-1); */
-  /* step 2: exponent is base 2, compute exponent for base 10 */
-  signed long e10;
-  /* step 3: calculate 10^e10 */
-  unsigned int i;
-  double backup=d;
-  double tmp;
-  char *oldbuf=buf;
-
-  if ((i=isinf(d))) return copystring(buf,maxlen,i>0?"inf":"-inf");
-  if (isnan(d)) return copystring(buf,maxlen,"nan");
-  e10=1+(long)(e*0.30102999566398119802); /* log10(2) */
-  /* Wir iterieren von Links bis wir bei 0 sind oder maxlen erreicht
-   * ist.  Wenn maxlen erreicht ist, machen wir das nochmal in
-   * scientific notation.  Wenn dann von prec noch was �brig ist, geben
-   * wir einen Dezimalpunkt aus und geben prec2 Nachkommastellen aus.
-   * Wenn prec2 Null ist, geben wir so viel Stellen aus, wie von prec
-   * noch �brig ist. */
-  if (d==0.0) {
-    prec2=prec2==0?1:prec2+2;
-    prec2=prec2>maxlen?8:prec2;
-    i=0;
-    if (prec2 && (long long)u.l<0) { buf[0]='-'; ++i; }
-    for (; i<prec2; ++i) buf[i]='0';
-    buf[buf[0]=='0'?1:2]='.'; buf[i]=0;
-    return i;
-  }
-
-  if (d < 0.0) { d=-d; *buf='-'; --maxlen; ++buf; }
-
-   /*
-      Perform rounding. It needs to be done before we generate any
-      digits as the carry could propagate through the whole number.
-   */
-
-  tmp = 0.5;
-  for (i = 0; i < prec2; i++) { tmp *= 0.1; }
-  d += tmp;
-
-  if (d < 1.0) { *buf='0'; --maxlen; ++buf; }
-/*  printf("e=%d e10=%d prec=%d\n",e,e10,prec); */
-  if (e10>0) {
-    int first=1;       /* are we about to write the first digit? */
-    tmp = 10.0;
-    i=e10;
-    while (i>10) { tmp=tmp*1e10; i-=10; }
-    while (i>1) { tmp=tmp*10; --i; }
-    /* the number is greater than 1. Iterate through digits before the
-     * decimal point until we reach the decimal point or maxlen is
-     * reached (in which case we switch to scientific notation). */
-    while (tmp>0.9) {
-      char digit;
-      double fraction=d/tmp;
-       digit=(int)(fraction);          /* floor() */
-      if (!first || digit) {
-       first=0;
-       *buf=digit+'0'; ++buf;
-       if (!maxlen) {
-         /* use scientific notation */
-         int len=__dtostr(backup/tmp,oldbuf,maxlen,prec,prec2);
-         int initial=1;
-         if (len==0) return 0;
-         maxlen-=len; buf+=len;
-         if (maxlen>0) {
-           *buf='e';
-           ++buf;
-         }
-         --maxlen;
-         for (len=1000; len>0; len/=10) {
-           if (e10>=len || !initial) {
-             if (maxlen>0) {
-               *buf=(e10/len)+'0';
-               ++buf;
-             }
-             --maxlen;
-             initial=0;
-             e10=e10%len;
-           }
-         }
-         if (maxlen>0) goto fini;
-         return 0;
-       }
-       d-=digit*tmp;
-       --maxlen;
-      }
-      tmp/=10.0;
-    }
-  }
-  else
-  {
-     tmp = 0.1;
-  }
-
-  if (buf==oldbuf) {
-    if (!maxlen) return 0; --maxlen;
-    *buf='0'; ++buf;
-  }
-  if (prec2 || prec>(unsigned int)(buf-oldbuf)+1) {    /* more digits wanted */
-    if (!maxlen) return 0; --maxlen;
-    *buf='.'; ++buf;
-    prec-=buf-oldbuf-1;
-    if (prec2) prec=prec2;
-    if (prec>maxlen) return 0;
-    while (prec>0) {
-      char digit;
-      double fraction=d/tmp;
-      digit=(int)(fraction);           /* floor() */
-      *buf=digit+'0'; ++buf;
-      d-=digit*tmp;
-      tmp/=10.0;
-      --prec;
-    }
-  }
-fini:
-  *buf=0;
-  return buf-oldbuf;
-}
-
-int __v_printf(struct arg_printf* fn, const unsigned char *format, va_list 
arg_ptr)
-{
-  int len=0;
-#ifdef WANT_ERROR_PRINTF
-  int _my_errno = errno;
-#endif
-
-  while (*format) {
-    unsigned int sz = skip_to(format);
-    if (sz) {
-      A_WRITE(fn,format,sz); len+=sz;
-      format+=sz;
-    }
-    if (*format=='%') {
-      char buf[128];
-      union { char*s; } u_str;
-#define s u_str.s
-
-      int retval;
-      unsigned char ch, padwith=' ';
-
-      char flag_in_sign=0;
-      char flag_upcase=0;
-      char flag_hash=0;
-      char flag_left=0;
-      char flag_space=0;
-      char flag_sign=0;
-      char flag_dot=0;
-      signed char flag_long=0;
-
-      unsigned int base;
-      unsigned int width=0, preci=0;
-
-      long number=0;
-#ifdef WANT_LONGLONG_PRINTF
-      long long llnumber=0;
-#endif
-
-      ++format;
-inn_printf:
-      switch(ch=*format++) {
-      case 0:
-       return -1;
-       break;
-
-      /* FLAGS */
-      case '#':
-       flag_hash=-1;
-      case 'z':
-       goto inn_printf;
-
-      case 'h':
-       --flag_long;
-       goto inn_printf;
-      case 'q':                /* BSD ... */
-      case 'L':
-       ++flag_long; /* fall through */
-      case 'l':
-       ++flag_long;
-       goto inn_printf;
-
-      case '-':
-       flag_left=1;
-       goto inn_printf;
-
-      case ' ':
-       flag_space=1;
-       goto inn_printf;
-
-      case '+':
-       flag_sign=1;
-       goto inn_printf;
-
-      case '0':
-      case '1':
-      case '2':
-      case '3':
-      case '4':
-      case '5':
-      case '6':
-      case '7':
-      case '8':
-      case '9':
-       if(flag_dot) return -1;
-       width=strtoul(format-1,(char**)&s,10);
-       if (ch=='0' && !flag_left) padwith='0';
-       format=s;
-       goto inn_printf;
-
-      case '*':
-       width=va_arg(arg_ptr,int);
-       goto inn_printf;
-
-      case '.':
-       flag_dot=1;
-       if (*format=='*') {
-         int tmp=va_arg(arg_ptr,int);
-         preci=tmp<0?0:tmp;
-         ++format;
-       } else {
-         long int tmp=strtol(format,(char**)&s,10);
-         preci=tmp<0?0:tmp;
-         format=s;
-       }
-       goto inn_printf;
-
-      /* print a char or % */
-      case 'c':
-       ch=(char)va_arg(arg_ptr,int);
-      case '%':
-       A_WRITE(fn,&ch,1); ++len;
-       break;
-
-#ifdef WANT_ERROR_PRINTF
-      /* print an error message */
-      case 'm':
-       s=strerror(_my_errno);
-       sz=strlen(s);
-       A_WRITE(fn,s,sz); len+=sz;
-       break;
-#endif
-      /* print a string */
-      case 's':
-       s=va_arg(arg_ptr,char *);
-#ifdef WANT_NULL_PRINTF
-       if (!s) s="(null)";
-#endif
-       sz = strlen(s);
-       if (flag_dot && sz>preci) sz=preci;
-       preci=0;
-       flag_dot^=flag_dot;
-       padwith=' ';
-
-print_out:
-      {
-       char *sign=s;
-       int todo=0;
-       int vs;
-       
-       if (! (width||preci) ) {
-         A_WRITE(fn,s,sz); len+=sz;
-         break;
-       }
-       
-       if (flag_in_sign) todo=1;
-       if (flag_hash>0)  todo=flag_hash;
-       if (todo) {
-         s+=todo;
-         sz-=todo;
-         width-=todo;
-       }
-       
-       if (!flag_left) {
-         if (flag_dot) {
-           vs=preci>sz?preci:sz;
-           len+=write_pad(fn,(signed int)width-(signed int)vs,' ');
-           if (todo) {
-             A_WRITE(fn,sign,todo);
-             len+=todo;
-           }
-           len+=write_pad(fn,(signed int)preci-(signed int)sz,'0');
-         } else {
-           if (todo && padwith=='0') {
-             A_WRITE(fn,sign,todo);
-             len+=todo; todo=0;
-           }
-           len+=write_pad(fn,(signed int)width-(signed int)sz, padwith);
-           if (todo) {
-             A_WRITE(fn,sign,todo);
-             len+=todo;
-           }
-         }
-         A_WRITE(fn,s,sz); len+=sz;
-       } else if (flag_left) {
-         if (todo) {
-           A_WRITE(fn,sign,todo);
-           len+=todo;
-         }
-         len+=write_pad(fn,(signed int)preci-(signed int)sz, '0');
-         A_WRITE(fn,s,sz); len+=sz;
-         vs=preci>sz?preci:sz;
-         len+=write_pad(fn,(signed int)width-(signed int)vs, ' ');
-       } else {
-         A_WRITE(fn,s,sz); len+=sz;
-       }
-       break;
-      }
-
-      /* print an integer value */
-      case 'b':
-       base=2;
-       sz=0;
-       goto num_printf;
-      case 'p':
-       flag_hash=2;
-       flag_long=1;
-       ch='x';
-      case 'X':
-       flag_upcase=(ch=='X');
-      case 'x':
-       base=16;
-       sz=0;
-       if (flag_hash) {
-         buf[1]='0';
-         buf[2]=ch;
-         flag_hash=2;
-         sz=2;
-       }
-       if (preci>width) width=preci;
-       goto num_printf;
-      case 'd':
-      case 'i':
-       flag_in_sign=1;
-      case 'u':
-       base=10;
-       sz=0;
-       goto num_printf;
-      case 'o':
-       base=8;
-       sz=0;
-       if (flag_hash) {
-         buf[1]='0';
-         flag_hash=1;
-         ++sz;
-       }
-
-num_printf:
-       s=buf+1;
-
-       if (flag_long>0) {
-#ifdef WANT_LONGLONG_PRINTF
-         if (flag_long>1)
-           llnumber=va_arg(arg_ptr,long long);
-         else
-#endif
-           number=va_arg(arg_ptr,long);
-       }
-       else
-         number=va_arg(arg_ptr,int);
-
-       if (flag_in_sign) {
-#ifdef WANT_LONGLONG_PRINTF
-         if ((flag_long>1)&&(llnumber<0)) {
-           llnumber=-llnumber;
-           flag_in_sign=2;
-         } else
-#endif
-           if (number<0) {
-             number=-number;
-             flag_in_sign=2;
-           }
-       }
-       if (flag_long<0) number&=0xffff;
-       if (flag_long<-1) number&=0xff;
-#ifdef WANT_LONGLONG_PRINTF
-       if (flag_long>1)
-         retval = __lltostr(s+sz,sizeof(buf)-5,(unsigned long long) 
llnumber,base,flag_upcase);
-       else
-#endif
-         retval = __ltostr(s+sz,sizeof(buf)-5,(unsigned long) 
number,base,flag_upcase);
-
-       /* When 0 is printed with an explicit precision 0, the output is empty. 
*/
-       if (flag_dot && retval == 1 && s[sz] == '0') {
-         if (preci == 0||flag_hash > 0) {
-           sz = 0;
-         }
-         flag_hash = 0;
-       } else sz += retval;
-
-       if (flag_in_sign==2) {
-         *(--s)='-';
-         ++sz;
-       } else if ((flag_in_sign)&&(flag_sign || flag_space)) {
-         *(--s)=(flag_sign)?'+':' ';
-         ++sz;
-       } else flag_in_sign=0;
-
-       goto print_out;
-
-#ifdef WANT_FLOATING_POINT_IN_PRINTF
-      /* print a floating point value */
-      case 'f':
-      case 'g':
-       {
-         int g=(ch=='g');
-         double d=va_arg(arg_ptr,double);
-         s=buf+1;
-         if (width==0) width=1;
-         if (!flag_dot) preci=6;
-         if (flag_sign || d < +0.0) flag_in_sign=1;
-       
-         sz=__dtostr(d,s,sizeof(buf)-1,width,preci);
-       
-         if (flag_dot) {
-           char *tmp;
-           if ((tmp=strchr(s,'.'))) {
-             if (preci || flag_hash) ++tmp;
-             while (preci>0 && *++tmp) --preci;
-             *tmp=0;
-           } else if (flag_hash) {
-             s[sz]='.';
-             s[++sz]='\0';
-           }
-         }
-
-         if (g) {
-           char *tmp,*tmp1;    /* boy, is _this_ ugly! */
-           if ((tmp=strchr(s,'.'))) {
-             tmp1=strchr(tmp,'e');
-             while (*tmp) ++tmp;
-             if (tmp1) tmp=tmp1;
-             while (*--tmp=='0') ;
-             if (*tmp!='.') ++tmp;
-             *tmp=0;
-             if (tmp1) strcpy(tmp,tmp1);
-           }
-         }
-       
-         if ((flag_sign || flag_space) && d>=0) {
-           *(--s)=(flag_sign)?'+':' ';
-           ++sz;
-         }
-       
-         sz=strlen(s);
-         flag_dot=0;
-         flag_hash=0;
-         goto print_out;
-       }
-#endif
-
-      default:
-       break;
-      }
-    }
-  }
-  return len;
-}
-
-#undef s
-
-static int swrite(void*ptr, size_t nmemb, struct str_data* sd) {
-  size_t tmp=sd->size-sd->len;
-  if (tmp>0) {
-    size_t len=nmemb;
-    if (len>tmp) len=tmp;
-    if (sd->str) {
-      memcpy(sd->str+sd->len,ptr,len);
-      sd->str[sd->len+len]=0;
-    }
-    sd->len+=len;
-  }
-  return nmemb;
-}
-
-int _win_vsnprintf(char* str, size_t size, const char *format, va_list arg_ptr)
-{
-  long n;
-  struct str_data sd = { str, 0, size?size-1:0 };
-  struct arg_printf ap = { &sd, (int(*)(void*,size_t,void*)) swrite };
-  n=__v_printf(&ap,format,arg_ptr);
-  if (str && size && n>=0) {
-    if (size!=(size_t)-1 && ((size_t)n>=size)) str[size-1]=0;
-    else str[n]=0;
-  }
-  return n;
-}
-
-int _win_vsprintf(char *dest, const char *format, va_list arg_ptr)
-{
-  return _win_vsnprintf(dest,(size_t)-1,format,arg_ptr);
-}
-
-static int __fwrite(void*ptr, size_t nmemb, int fd) {
-  return fwrite(ptr, 1, nmemb, fd);
-}
-
-int _win_vfprintf(FILE *stream, const char *format, va_list arg_ptr)
-{
-  struct arg_printf ap = { stream, (int(*)(void*,size_t,void*)) __fwrite };
-  return __v_printf(&ap,format,arg_ptr);
-}
-
-int __stdio_outs(const char *s, size_t len) {
-  return (fwrite(s, 1, len, stdout)==(int)len)?1:0;
-}
-
-int _win_vprintf(const char *format, va_list ap)
-{
-  struct arg_printf _ap = { 0, (int(*)(void*,size_t,void*)) __stdio_outs };
-  return __v_printf(&_ap,format,ap);
-}
-
-int _win_fprintf(FILE *f,const char *format, ...)
-{
-  int n;
-  va_list arg_ptr;
-  va_start(arg_ptr,format);
-  n=_win_vfprintf(f,format,arg_ptr);
-  va_end(arg_ptr);
-  return n;
-}
-
-int _win_printf(const char *format, ...)
-{
-  int n;
-  va_list arg_ptr;
-  va_start(arg_ptr, format);
-  n=_win_vprintf(format, arg_ptr);
-  va_end(arg_ptr);
-  return n;
-}
-
-int _win_snprintf(char *str, size_t size, const char *format, ...)
-{
-  int n;
-  va_list arg_ptr;
-  va_start(arg_ptr, format);
-  n=vsnprintf(str,size,format,arg_ptr);
-  va_end (arg_ptr);
-  return n;
-}
-
-int _win_sprintf(char *dest, const char *format, ...)
-{
-  int n;
-  va_list arg_ptr;
-  va_start(arg_ptr, format);
-  n=vsprintf(dest,format,arg_ptr);
-  va_end (arg_ptr);
-  return n;
-}
-
-#define A_GETC(fn)  (++consumed,(fn)->getch((fn)->data))
-#define A_PUTC(c,fn)  (--consumed,(fn)->putch((c),(fn)->data))
-
-struct arg_scanf {
-  void *data;
-  int (*getch)(void*);
-  int (*putch)(int,void*);
-};
-
-int __v_scanf(struct arg_scanf* fn, const unsigned char *format, va_list 
arg_ptr)
-{
-  unsigned int ch;  /* format act. char */
-  int n=0;
-
-  /* arg_ptr tmps */
-#ifdef WANT_FLOATING_POINT_IN_SCANF
-  double *pd;
-  float  *pf;
-#endif
-#ifdef WANT_LONGLONG_SCANF
-  long long *pll;
-#endif
-  long   *pl;
-  short  *ph;
-  int    *pi;
-  char    *s;
-
-  unsigned int consumed=0;
-
-  /* get one char */
-  int tpch= A_GETC(fn);
-
-  //while ((tpch!=-1)&&(*format))
-  while (*format)
-  {
-    ch=*format++;
-    switch (ch) {
-    /* end of format string ?!? */
-    case 0: return 0;
-
-    /* skip spaces ... */
-    case ' ':
-    case '\f':
-    case '\t':
-    case '\v':
-    case '\n':
-    case '\r':
-      while((*format)&&(isspace(*format))) ++format;
-      while(isspace(tpch)) tpch=A_GETC(fn);
-      break;
-
-    /* format string ... */
-    case '%':
-      {
-  unsigned int _div=0;
-  int width=-1;
-  char flag_width=0;
-  char flag_discard=0;
-  char flag_half=0;
-  char flag_long=0;
-  char flag_longlong=0;
-
-in_scan:
-  ch=*format++;
-  if(ch!='n' && tpch==-1) goto err_out;
-  switch (ch) {
-  /* end of format string ?!? */
-  case 0: return 0;
-
-  /* check for % */
-  case '%':
-    if ((unsigned char)tpch != ch) goto err_out;
-    tpch=A_GETC(fn);
-    break;
-
-  /* FLAGS */
-  case '*':
-    flag_discard=1;
-    goto in_scan;
-  case 'h':
-    flag_half=1;
-    goto in_scan;
-  case 'l':
-    if (flag_long) flag_longlong=1;
-    flag_long=1;
-    goto in_scan;
-  case 'q':
-  case 'L':
-    flag_longlong=1;
-    goto in_scan;
-
-  /* WIDTH */
-  case '0':
-  case '1':
-  case '2':
-  case '3':
-  case '4':
-  case '5':
-  case '6':
-  case '7':
-  case '8':
-  case '9':
-    width=strtol(format-1,&s,10);
-    format=s;
-    flag_width=1;
-    goto in_scan;
-
-  /* scan for integer / strtol reimplementation ... */
-  case 'p':
-  case 'X':
-  case 'x':
-    _div+=6;
-  case 'd':
-    _div+=2;
-  case 'o':
-    _div+=8;
-  case 'u':
-  case 'i':
-    {
-#ifdef WANT_LONGLONG_SCANF
-      unsigned long long v=0;
-#else
-      unsigned long v=0;
-#endif
-      unsigned int consumedsofar;
-      int neg=0;
-      while(isspace(tpch)) tpch=A_GETC(fn);
-      if (tpch=='-') {
-        tpch=A_GETC(fn);
-        neg=1;
-      }
-
-      if (tpch=='+') tpch=A_GETC(fn);
-
-      if (tpch==-1) return n;
-      consumedsofar=consumed;
-
-      if (!flag_width) {
-        if ((_div==16) && (tpch=='0')) goto scan_hex;
-        if (!_div) {
-    _div=10;
-    if (tpch=='0') {
-      _div=8;
-scan_hex:
-      tpch=A_GETC(fn);
-      if ((tpch|32)=='x') {
-        tpch=A_GETC(fn);
-        _div=16;
-      }
-    }
-        }
-      }
-      while ((width)&&(tpch!=-1)) {
-        register unsigned long c=tpch&0xff;
-#ifdef WANT_LONGLONG_SCANF
-        register unsigned long long d=c|0x20;
-#else
-        register unsigned long d=c|0x20;
-#endif
-        c=(d>='a'?d-'a'+10:c<='9'?c-'0':0xff);
-        if (c>=_div) break;
-        d=v*_div;
-#ifdef WANT_LONGLONG_SCANF
-        v=(d<v)?ULLONG_MAX:d+c;
-#else
-        v=(d<v)?ULONG_MAX:d+c;
-#endif
-        --width;
-        tpch=A_GETC(fn);
-      }
-
-      if (consumedsofar==consumed) return n;
-
-      if ((ch|0x20)<'p') {
-#ifdef WANT_LONGLONG_SCANF
-        register long long l=v;
-        if (v>=-((unsigned long long)LLONG_MIN)) {
-    l=(neg)?LLONG_MIN:LLONG_MAX;
-        }
-        else {
-    if (neg) v*=-1;
-        }
-#else
-        register long l=v;
-        if (v>=-((unsigned long)LONG_MIN)) {
-    l=(neg)?LONG_MIN:LONG_MAX;
-        }
-        else {
-    if (neg) v*=-1;
-        }
-#endif
-      }
-      if (!flag_discard) {
-#ifdef WANT_LONGLONG_SCANF
-        if (flag_longlong) {
-    pll=(long long *)va_arg(arg_ptr,long long*);
-    *pll=v;
-        } else
-#endif
-        if (flag_long) {
-    pl=(long *)va_arg(arg_ptr,long*);
-    *pl=v;
-        } else if (flag_half) {
-    ph=(short*)va_arg(arg_ptr,short*);
-    *ph=v;
-        } else {
-    pi=(int *)va_arg(arg_ptr,int*);
-    *pi=v;
-        }
-        if(consumedsofar<consumed) ++n;
-      }
-    }
-    break;
-
-  /* FIXME: return value of *scanf with ONE float maybe -1 instead of 0 */
-#ifdef WANT_FLOATING_POINT_IN_SCANF
-  /* floating point numbers */
-  case 'e':
-  case 'E':
-  case 'f':
-  case 'g':
-    {
-      double d=0.0;
-      int neg=0;
-      unsigned int consumedsofar;
-
-      while(isspace(tpch)) tpch=A_GETC(fn);
-
-      if (tpch=='-') {
-        tpch=A_GETC(fn);
-        neg=1;
-      }
-      if (tpch=='+') tpch=A_GETC(fn);
-
-      consumedsofar=consumed;
-
-      while (isdigit(tpch)) {
-        d=d*10+(tpch-'0');
-        tpch=A_GETC(fn);
-      }
-      if (tpch=='.') {
-        double factor=.1;
-        consumedsofar++;
-        tpch=A_GETC(fn);
-        while (isdigit(tpch)) {
-    d=d+(factor*(tpch-'0'));
-    factor/=10;
-    tpch=A_GETC(fn);
-        }
-      }
-      if (consumedsofar==consumed) return n;  /* error */
-      if ((tpch|0x20)=='e') {
-        int exp=0, prec=tpch;
-        double factor=10;
-        tpch=A_GETC(fn);
-        if (tpch=='-') {
-    factor=0.1;
-    tpch=A_GETC(fn);
-        } else if (tpch=='+') {
-    tpch=A_GETC(fn);
-        } else {
-    d=0;
-    if (tpch!=-1) A_PUTC(tpch,fn);
-    tpch=prec;
-    goto exp_out;
-        }
-        consumedsofar=consumed;
-        while (isdigit(tpch)) {
-    exp=exp*10+(tpch-'0');
-    tpch=A_GETC(fn);
-        }
-        if (consumedsofar==consumed) return n;  /* error */
-        while (exp) { /* as in strtod: XXX: this introduces rounding errors */
-    d*=factor; --exp;
-        }
-      }
-exp_out:
-      if (!flag_discard) {
-        if (flag_long) {
-    pd=(double *)va_arg(arg_ptr,double*);
-    *pd=d;
-        } else {
-    pf=(float *)va_arg(arg_ptr,float*);
-    *pf=d;
-        }
-        ++n;
-      }
-    }
-    break;
-#endif
-
-  /* char-sequences */
-  case 'c':
-    if (!flag_discard) {
-      s=(char *)va_arg(arg_ptr,char*);
-      ++n;
-    }
-    if (!flag_width) width=1;
-    while (width && (tpch!=-1)) {
-      if (!flag_discard) *(s++)=tpch;
-      --width;
-      tpch=A_GETC(fn);
-    }
-    break;
-
-  /* string */
-  case 's':
-    if (!flag_discard) s=(char *)va_arg(arg_ptr,char*);
-    while(isspace(tpch)) tpch=A_GETC(fn);
-    if (tpch==-1) break;    /* end of scan -> error */
-    while (width && (tpch!=-1) && (!isspace(tpch))) {
-      if (!flag_discard) *s=tpch;
-      if (tpch) ++s; else break;
-      --width;
-      tpch=A_GETC(fn);
-    }
-    if (!flag_discard) { *s=0; ++n; }
-    break;
-
-  /* consumed-count */
-  case 'n':
-    if (!flag_discard) {
-      pi=(int *)va_arg(arg_ptr,int *);
-//      ++n;  /* in accordance to ANSI C we don't count this conversion */
-            *pi=consumed-1;
-    }
-    break;
-
-#ifdef WANT_CHARACTER_CLASSES_IN_SCANF
-  case '[':
-    {
-      char cset[256];
-      int flag_not=0;
-      int flag_dash=0;
-      memset(cset,0,sizeof(cset));
-      ch=*format++;
-      /* first char specials */
-      if (ch=='^') {
-        flag_not=1;
-        ch=*format++;
-      }
-      if ((ch=='-')||(ch==']')) {
-        cset[ch]=1;
-        ch=*format++;
-      }
-      /* almost all non special chars */
-      for (;(*format) && (*format!=']');++format) {
-        if (flag_dash) {
-    register unsigned char tmp=*format;
-    for (;ch<=tmp;++ch) cset[ch]=1;
-    flag_dash=0;
-    ch=*format;
-        }
-        else if (*format=='-') flag_dash=1;
-        else {
-    cset[ch]=1;
-    ch=*format;
-        }
-      }
-      /* last char specials */
-      if (flag_dash) cset['-']=1;
-      else cset[ch]=1;
-
-      /* like %c or %s */
-      if (!flag_discard) {
-        s=(char *)va_arg(arg_ptr,char*);
-        ++n;
-      }
-      while (width && (tpch>=0) && (cset[tpch]^flag_not)) {
-        if (!flag_discard) *s=tpch;
-        if (tpch) ++s; else break;
-        --width;
-        tpch=A_GETC(fn);
-      }
-      if (!flag_discard) *s=0;
-      ++format;
-    }
-    break;
-#endif
-  default:
-    goto err_out;
-  }
-      }
-      break;
-
-    /* check if equal format string... */
-    default:
-      if ((unsigned char)tpch != ch) goto err_out;
-      tpch=A_GETC(fn);
-      break;
-    }
-  }
-
-  /* maybe a "%n" follows */
-  if(*format) {
-    while(isspace(*format)) format++;
-    if(format[0] == '%' && format[1] == 'n') {
-      pi = (int *) va_arg(arg_ptr, int *);
-      *pi = consumed - 1;
-    }
-  }
-
-err_out:
-  if (tpch<0 && n==0) return EOF;
-  A_PUTC(tpch,fn);
-  return n;
-}
-
-struct scanf_str_data {
-  unsigned char* str;
-};
-
-static int sgetc(struct scanf_str_data* sd) {
-  register unsigned int ret = *(sd->str++);
-  return (ret)?(int)ret:-1;
-}
-
-static int sputc(int c, struct scanf_str_data* sd) {
-  return (*(--sd->str)==c)?c:-1;
-}
-
-int _win_vsscanf(const char* str, const char* format, va_list arg_ptr)
-{
-  struct scanf_str_data  fdat = { (unsigned char*)str };
-  struct arg_scanf farg = { (void*)&fdat, (int(*)(void*))sgetc, 
(int(*)(int,void*))sputc };
-  return __v_scanf(&farg,format,arg_ptr);
-}
-
-int _win_sscanf(const char *str, const char *format, ...)
-{
-  int n;
-  va_list arg_ptr;
-  va_start(arg_ptr, format);
-  n = _win_vsscanf(str,format,arg_ptr);
-  va_end (arg_ptr);
-  return n;
-}
-
-int _win_vfscanf(FILE *stream, const char *format, va_list arg_ptr)
-{
-  struct arg_scanf farg = { (void*)stream, (int(*)(void*))fgetc, 
(int(*)(int,void*))ungetc };
-  return __v_scanf(&farg,format,arg_ptr);
-}
-
-int _win_vscanf(const char *format, va_list arg_ptr)
-{
-  return _win_vfscanf(stdin,format,arg_ptr);
-}
-
-int _win_scanf(const char *format, ...)
-{
-  int n;
-  va_list arg_ptr;
-  va_start(arg_ptr, format);
-  n = _win_vfscanf(stdin,format,arg_ptr);
-  va_end (arg_ptr);
-  return n;
-}
-
-int _win_fscanf(FILE *stream, const char *format, ...)
-{
-  int n;
-  va_list arg_ptr;
-  va_start(arg_ptr, format);
-  n = _win_vfscanf(stream,format,arg_ptr);
-  va_end (arg_ptr);
-  return n;
-}
-
-/* end of win_printf.c */

Modified: GNUnet/src/util/win/winproc.c
===================================================================
--- GNUnet/src/util/win/winproc.c       2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/util/win/winproc.c       2005-04-29 22:30:41 UTC (rev 710)
@@ -31,35 +31,6 @@
 
 #ifdef MINGW
 
-const char *errlist[] = {
-  "No error",
-  "Unknown host",                       /* 1 HOST_NOT_FOUND */
-  "Host name lookup failure",           /* 2 TRY_AGAIN */
-  "Unknown server error",               /* 3 NO_RECOVERY */
-  "No address associated with name",    /* 4 NO_ADDRESS */
-  "Internal resolver error",            /* errno < 0 */
-  "Unknown resolver error"              /* errno > 4 */
-};
-
-typedef struct {
-  char *pStart;
-  HANDLE hMapping;
-} TMapping;
-
-static char szRootDir[_MAX_PATH + 1];
-static long lRootDirLen;
-static char szHomeDir[_MAX_PATH + 2];
-static long lHomeDirLen;
-static char szUser[261] = "";
-static OSVERSIONINFO theWinVersion;
-unsigned int uiSockCount = 0;
-Winsock *pSocks;
-HANDLE hSocksLock;
-static char __langinfo[251];
-static unsigned int uiMappingsCount = 0;
-static TMapping *pMappings;
-HANDLE hMappingsLock;
-
 static HINSTANCE hNTDLL, hIphlpapi, hAdvapi;
 TNtQuerySystemInformation GNNtQuerySystemInformation;
 TGetIfEntry GNGetIfEntry;
@@ -77,501 +48,22 @@
 TGetBestInterface GNGetBestInterface;
 TGetAdaptersInfo GGetAdaptersInfo;
 
-BOOL __win_IsHandleMarkedAsBlocking(SOCKET hHandle)
-{
-  BOOL bBlocking;
-  unsigned int uiIndex;
-
-  bBlocking = TRUE;
-  WaitForSingleObject(hSocksLock, INFINITE);
-  for(uiIndex = 0; uiIndex <= uiSockCount; uiIndex++)
-  {
-    if (pSocks[uiIndex].s == hHandle)
-    {
-      bBlocking = pSocks[uiIndex].bBlocking;
-      break;
-    }
-  }
-  ReleaseMutex(hSocksLock);
-
-  return bBlocking;
-}
-
-void __win_SetHandleBlockingMode(SOCKET s, BOOL bBlocking)
-{
-  unsigned int uiIndex = 0;
-  int bFound = 0;
-
-  WaitForSingleObject(hSocksLock, INFINITE);
-
-  for(uiIndex = 0; uiIndex <= uiSockCount; uiIndex++)
-  {
-    if (pSocks[uiIndex].s == s)
-    {
-      bFound = 1;
-      break;
-    }
-  }
-
-  if (bFound)
-    pSocks[uiIndex].bBlocking = bBlocking;
-  else
-  {
-    uiIndex = 0;
-
-    while(TRUE)
-    {
-      if (pSocks[uiIndex].s == -1)
-      {
-        pSocks[uiIndex].s = s;
-        pSocks[uiIndex].bBlocking = bBlocking;
-      }
-      if (uiIndex == uiSockCount)
-      {
-        uiSockCount++;
-        pSocks = (Winsock *) realloc(pSocks, (uiSockCount + 1) * 
sizeof(Winsock));
-        pSocks[uiSockCount].s = -1;
-
-        break;
-      }
-      uiIndex++;
-    }
-  }
-  ReleaseMutex(hSocksLock);
-}
-
-void __win_DiscardHandleBlockingMode(SOCKET s)
-{
-  unsigned int uiIndex;
-
-  WaitForSingleObject(hSocksLock, INFINITE);
-  for(uiIndex = 0; uiIndex < uiSockCount; uiIndex++)
-    if (pSocks[uiIndex].s == s)
-      pSocks[uiIndex].s = -1;
-  ReleaseMutex(hSocksLock);
-}
-
 /**
- * @author Prof. A Olowofoyeku (The African Chief)
- * @author Frank Heckenbach
- * @author Nils Durner
- * source: http://gd.tuwien.ac.at/gnu/mingw/os-hacks.h
+ * Log (panic) messages from PlibC
  */
-
-int truncate(const char *fname, int distance)
-{
-  int i;
-  HANDLE hFile;
-  char pszFile[_MAX_PATH + 1];
-  long lRet;
-
-  errno = 0;
-
-  if ((lRet = conv_to_win_path(fname, pszFile)) != ERROR_SUCCESS)
-  {
-    SetErrnoFromWinError(lRet);
-    return -1;
-  }
-
-  i = -1;
-  hFile = CreateFile(pszFile, GENERIC_READ | GENERIC_WRITE,
-                     FILE_SHARE_READ | FILE_SHARE_WRITE,
-                     NULL, OPEN_EXISTING,
-                     FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL);
-  if(hFile != INVALID_HANDLE_VALUE)
-  {
-    if(SetFilePointer(hFile, distance, NULL, FILE_BEGIN) != 0xFFFFFFFF)
-    {
-      if(SetEndOfFile(hFile))
-        i = 0;
-    }
-    CloseHandle(hFile);
-  }
-
-  return i;
+void plibc_panic(int err, char *msg) {
+       LOG((err = INT_MAX) ? LOG_DEBUG : LOG_FAILURE, "%s", msg);
 }
 
-/*********************** statfs ****************************/
-
 /**
- * @author Prof. A Olowofoyeku (The African Chief)
- * @author Frank Heckenbach
- * source: http://gd.tuwien.ac.at/gnu/mingw/os-hacks.h
- */
-
-int statfs(const char *path, struct statfs *buf)
-{
-  HINSTANCE h;
-  FARPROC f;
-  char tmp[MAX_PATH], resolved_path[MAX_PATH];
-  int retval = 0;
-
-  errno = 0;
-
-  realpath(path, resolved_path);
-  if(!resolved_path)
-    retval = -1;
-  else
-  {
-    /* check whether GetDiskFreeSpaceExA is supported */
-    h = LoadLibraryA("kernel32.dll");
-    if(h)
-      f = GetProcAddress(h, "GetDiskFreeSpaceExA");
-    else
-      f = NULL;
-    if(f)
-    {
-      ULARGE_INTEGER bytes_free, bytes_total, bytes_free2;
-      if(!f(resolved_path, &bytes_free2, &bytes_total, &bytes_free))
-      {
-        errno = ENOENT;
-        retval = -1;
-      }
-      else
-      {
-        buf->f_bsize = FAKED_BLOCK_SIZE;
-        buf->f_bfree = (bytes_free.QuadPart) / FAKED_BLOCK_SIZE;
-        buf->f_files = buf->f_blocks =
-          (bytes_total.QuadPart) / FAKED_BLOCK_SIZE;
-        buf->f_ffree = buf->f_bavail =
-          (bytes_free2.QuadPart) / FAKED_BLOCK_SIZE;
-      }
-    }
-    else
-    {
-      DWORD sectors_per_cluster, bytes_per_sector;
-      if(h)
-        FreeLibrary(h);
-      if(!GetDiskFreeSpaceA(resolved_path, &sectors_per_cluster,
-                            &bytes_per_sector, &buf->f_bavail,
-                            &buf->f_blocks))
-      {
-        errno = ENOENT;
-        retval = -1;
-      }
-      else
-      {
-        buf->f_bsize = sectors_per_cluster * bytes_per_sector;
-        buf->f_files = buf->f_blocks;
-        buf->f_ffree = buf->f_bavail;
-        buf->f_bfree = buf->f_bavail;
-      }
-    }
-    if(h)
-      FreeLibrary(h);
-  }
-
-  /* get the FS volume information */
-  if(strspn(":", resolved_path) > 0)
-    resolved_path[3] = '\0';    /* we want only the root */
-  if(GetVolumeInformation
-     (resolved_path, NULL, 0, &buf->f_fsid, &buf->f_namelen, NULL, tmp,
-      MAX_PATH))
-  {
-    if(strcasecmp("NTFS", tmp) == 0)
-    {
-      buf->f_type = NTFS_SUPER_MAGIC;
-    }
-    else
-    {
-      buf->f_type = MSDOS_SUPER_MAGIC;
-    }
-  }
-  else
-  {
-    errno = ENOENT;
-    retval = -1;
-  }
-  return retval;
-}
-
-/*********************** End of statfs **********************/
-
-const char *hstrerror(int err)
-{
-  if(err < 0)
-    err = 5;
-  else if(err > 4)
-    err = 6;
-
-  return errlist[err];
-}
-
-void gettimeofday(struct timeval *tp, void *tzp)
-{
-  struct _timeb theTime;
-
-  errno = 0;
-
-  _ftime(&theTime);
-  tp->tv_sec = theTime.time;
-  tp->tv_usec = theTime.millitm * 1000;
-}
-
-int mkstemp(char *tmplate)
-{
-  static const char letters[]
-    = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
-  int iLen, iRnd;
-  char *pChr;
-  char szDest[_MAX_PATH + 1];
-
-  errno = 0;
-
-  iLen = strlen(tmplate);
-  if(iLen >= 6)
-  {
-    pChr = tmplate + iLen - 6;
-    srand((unsigned int) time(NULL));
-
-    if(strncmp(pChr, "XXXXXX", 6) == 0)
-    {
-      int iChr;
-      for(iChr = 0; iChr < 6; iChr++)
-      {
-        /* 528.5 = RAND_MAX / letters */
-        iRnd = rand() / 528.5;
-        *(pChr++) = letters[iRnd > 0 ? iRnd - 1 : 0];
-      }
-    }
-    else
-    {
-      errno = EINVAL;
-      return -1;
-    }
-  }
-  else
-  {
-    errno = EINVAL;
-    return -1;
-  }
-
-  conv_to_win_path(tmplate, szDest);
-
-  return _open(szDest, _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE);
-}
-
-/*********************** posix path -> win path ****************************/
-
-/**
- * Get information from the Windows registry
- * @param hMainKey handle to (main-)key to query (HKEY_LOCAL_MACHINE etc.)
- * @param pszKey name of key to query
- * @param pszSubKey name of subkey to query
- * @param pszBuffer buffer for returned string
- * @param pdLength receives size of returned string
+ * Initialize PlibC and set up Windows environment
  * @return Error code from winerror.h, ERROR_SUCCESS on success
- */
-long QueryRegistry(HKEY hMainKey, char *pszKey, char *pszSubKey,
-              char *pszBuffer, long *pdLength)
-{
-  HKEY hKey;
-  long lRet;
-
-  if((lRet = RegOpenKeyEx(hMainKey, pszKey, 0, KEY_EXECUTE, &hKey)) ==
-     ERROR_SUCCESS)
-  {
-    lRet = RegQueryValueEx(hKey, pszSubKey, 0, NULL, pszBuffer, pdLength);
-
-    RegCloseKey(hKey);
-  }
-
-  return lRet;
-}
-
-/**
- * Determine the Windows path of our / directory
- * @return Error code from winerror.h, ERROR_SUCCESS on success
- */
-long DetermineRootDir()
-{
-  char szModule[_MAX_PATH], szDrv[_MAX_DRIVE], szDir[_MAX_DIR];
-  long lDirLen;
-
-  /* Get the path of the calling module.
-     It should be located in one of the "bin" directories */
-  GetModuleFileName(NULL, szModule, MAX_PATH);
-  _splitpath(szModule, szDrv, szDir, NULL, NULL);
-
-  lDirLen = strlen(szDir);
-
-  if(stricmp(szDir + lDirLen - 15, "\\usr\\local\\bin\\") == 0)
-    szDir[lDirLen -= 14] = 0;
-  /* "\\local\\bin" is right, "/usr" points to "/" under MinGW */
-  else if(stricmp(szDir + lDirLen - 11, "\\local\\bin\\") == 0)
-    szDir[lDirLen -= 10] = 0;
-  else if(stricmp(szDir + lDirLen - 9, "\\usr\\bin\\") == 0)
-    szDir[lDirLen -= 8] = 0;
-  else if(stricmp(szDir + lDirLen - 5, "\\bin\\") == 0)
-    szDir[lDirLen -= 4] = 0;
-  else
-  {
-    /* Get the installation path from the registry */
-    lDirLen = _MAX_PATH - 1;
-
-    if(QueryRegistry
-       (HKEY_CURRENT_USER, "Software\\GNU\\GNUnet", "InstallDir",
-        szRootDir, &lDirLen) != ERROR_SUCCESS)
-    {
-      lDirLen = _MAX_PATH - 1;
-
-      if(QueryRegistry
-         (HKEY_LOCAL_MACHINE, "Software\\GNU\\GNUnet", "InstallDir",
-          szRootDir, &lDirLen) != ERROR_SUCCESS)
-      {
-        return ERROR_BAD_ENVIRONMENT;
-      }
-    }
-    strcat(szRootDir, "\\");
-    lRootDirLen = lDirLen;
-    szDrv[0] = 0;
-  }
-
-  if(szDrv[0])
-  {
-    strcpy(szRootDir, szDrv);
-    lRootDirLen = 3 + lDirLen - 1;      /* 3 = strlen(szDir) */
-    if(lRootDirLen > _MAX_PATH)
-      return ERROR_BUFFER_OVERFLOW;
-
-    strcat(szRootDir, szDir);
-  }
-
-  return ERROR_SUCCESS;
-}
-
-/**
- * Determine the user's home directory
- * @return Error code from winerror.h, ERROR_SUCCESS on success
 */
-long DetermineHomeDir()
-{
-  char *lpszProfile = getenv("USERPROFILE");
-  if(lpszProfile != NULL && lpszProfile[0] != 0)        /* Windows NT */
-  {
-    lHomeDirLen = strlen(lpszProfile);
-    if(lHomeDirLen + 1 > _MAX_PATH)
-      return ERROR_BUFFER_OVERFLOW;
-
-    strcpy(szHomeDir, lpszProfile);
-    if(szHomeDir[lHomeDirLen - 1] != '\\')
-    {
-      szHomeDir[lHomeDirLen] = '\\';
-      szHomeDir[++lHomeDirLen] = 0;
-    }
-  }
-  else
-  {
-    /* C:\My Documents */
-    long lRet;
-
-    lHomeDirLen = _MAX_PATH;
-    lRet = QueryRegistry(HKEY_CURRENT_USER,
-                         "Software\\Microsoft\\Windows\\CurrentVersion\\"
-                         "Explorer\\Shell Folders",
-                         "Personal", szHomeDir, &lHomeDirLen);
-
-    if(lRet == ERROR_BUFFER_OVERFLOW)
-      return ERROR_BUFFER_OVERFLOW;
-    else if(lRet == ERROR_SUCCESS)
-    {
-      /* lHomeDirLen includes \0 */
-      if (lHomeDirLen <= _MAX_PATH)
-        strcat(szHomeDir, "\\");
-      else
-        return ERROR_BUFFER_OVERFLOW;
-    }
-    else
-    {
-      /* C:\Program Files\GNUnet\home\... */
-      /* 5 = strlen("home\\") */
-      lHomeDirLen = strlen(szRootDir) + strlen(szUser) + 5 + 1;
-
-      if(_MAX_PATH < lHomeDirLen)
-        return ERROR_BUFFER_OVERFLOW;
-
-      strcpy(szHomeDir, szRootDir);
-      strcat(szHomeDir, "home\\");
-      strcat(szHomeDir, szUser);
-      strcat(szHomeDir, "\\");
-    }
-  }
-
-  return ERROR_SUCCESS;
-}
-
-/**
- * Initialize POSIX emulation and set up Windows environment
- * @return Error code from winerror.h, ERROR_SUCCESS on success
-*/
 void InitWinEnv()
 {
-  long lRet;
-  WSADATA wsaData;
-  enum {ROOT, USER, HOME} eAction = ROOT;
-  UINT uiCP;
+       plibc_init("GNU", PACKAGE);
+       plibc_set_panic_proc(plibc_panic);
 
-  /* Init path translation */
-  if((lRet = DetermineRootDir()) == ERROR_SUCCESS)
-  {
-    DWORD dwSize = 261;
-
-    eAction = USER;
-    GetUserName(szUser, &dwSize);
-
-    eAction = HOME;
-    lRet = DetermineHomeDir();
-  }
-
-  if(lRet != ERROR_SUCCESS)
-  {
-    char *pszMsg, *pszMsg2;
-
-    lRet =
-      FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
-                    FORMAT_MESSAGE_FROM_SYSTEM |
-                    FORMAT_MESSAGE_IGNORE_INSERTS, NULL, lRet, 0,
-                    (LPTSTR) & pszMsg, 0, NULL);
-
-    pszMsg2 = (char *) MALLOC(lRet + 1);
-    strcpy(pszMsg2, pszMsg);
-    if(pszMsg2[lRet - 2] == '\r')
-      pszMsg2[lRet - 2] = 0;
-
-    LOG(LOG_FAILURE, "Cannot determine %s (%s)\n",
-            eAction == ROOT ? "root directory" :
-              "home directory", pszMsg2);
-    LocalFree(pszMsg);
-    FREE(pszMsg2);
-
-    exit(1);
-  }
-
-  /* Init Winsock */
-  if (WSAStartup(257, &wsaData) != 0)
-  {
-    LOG(LOG_FAILURE, "Cannot initialize Winsock.\n");
-
-    exit(1);
-  }
-
-  /* To keep track of blocking/non-blocking sockets */
-  pSocks = (Winsock *) malloc(sizeof(Winsock) + (uiSockCount + 1));
-  pSocks[0].s = -1;
-  hSocksLock = CreateMutex(NULL, FALSE, NULL);
-
-  /* To keep track of mapped files */
-  pMappings = (TMapping *) malloc(sizeof(TMapping));
-  pMappings[0].pStart = NULL;
-  hMappingsLock = CreateMutex(NULL, FALSE, NULL);
-
-  /* Open files in binary mode */
-  _fmode = _O_BINARY;
-
-  /* Get Windows version */
-  theWinVersion.dwOSVersionInfoSize = sizeof(theWinVersion);
-  GetVersionEx(&theWinVersion);
-
   hNTDLL = LoadLibrary("ntdll.dll");
 
   /* Function to get CPU usage under Win NT */
@@ -629,17 +121,7 @@
       GetProcAddress(hAdvapi, "ControlService");
     GNOpenService = (TOpenService)
       GetProcAddress(hAdvapi, "OpenServiceA");
-
   }
-
-  /* Use ANSI codepage for console IO */
-  uiCP = GetACP();
-  SetConsoleCP(uiCP);
-  SetConsoleOutputCP(uiCP);
-  setlocale( LC_ALL, ".OCP" );
-
-  /* Initialize COM library */
-  CoInitializeEx(NULL, COINIT_MULTITHREADED);
 }
 
 /**
@@ -647,13 +129,8 @@
  */
 void ShutdownWinEnv()
 {
-  WSACleanup();
-  free(pSocks);
-  CloseHandle(hSocksLock);
+       plibc_shutdown();
 
-  free(pMappings);
-  CloseHandle(hMappingsLock);
-
   FreeLibrary(hNTDLL);
   FreeLibrary(hIphlpapi);
   FreeLibrary(hAdvapi);
@@ -661,2465 +138,6 @@
   CoUninitialize();
 }
 
-/**
- * Dereference a symlink recursively
- */
-int __win_deref(char *path)
-{
-  int iDepth = 0;
-
-  errno = 0;
-
-  while (DereferenceShortcut(path))
-  {
-    if (iDepth++ > 10)
-    {
-      errno = ELOOP;
-      return -1;
-    }
-  }
-
-  return errno ? -1 : 0;
-}
-
-/**
- * Convert a POSIX-sytle path to a Windows-style path
- * @param pszUnix POSIX path
- * @param pszWindows Windows path
- * @param derefLinks 1 to dereference links
- * @return Error code from winerror.h, ERROR_SUCCESS on success
-*/
-int conv_to_win_path_ex(const char *pszUnix, char *pszWindows, int derefLinks)
-{
-  char *pSrc, *pDest;
-  long iSpaceUsed;
-  int iUnixLen;
-
-  iUnixLen = strlen(pszUnix);
-
-  /* Check if we already have a windows path */
-  if((strchr(pszUnix, '\\') != NULL) || (strchr(pszUnix, ':') != NULL))
-  {
-    if(iUnixLen > MAX_PATH)
-      return ERROR_BUFFER_OVERFLOW;
-    strcpy(pszWindows, pszUnix);
-  }
-
-  /* Is the unix path a full path? */
-  if(pszUnix[0] == '/')
-  {
-    strcpy(pszWindows, szRootDir);
-    iSpaceUsed = lRootDirLen;
-    pDest = pszWindows + lRootDirLen;
-    pSrc = (char *) pszUnix + 1;
-  }
-  /* Temp. dir? */
-  else if(strncmp(pszUnix, "/tmp/", 5) == 0)
-  {
-    iSpaceUsed = GetTempPath(_MAX_PATH, pszWindows);
-    if (iSpaceUsed > _MAX_PATH)
-      return ERROR_BUFFER_OVERFLOW;
-    pDest = pszWindows + iSpaceUsed;
-    pSrc = (char *) pszUnix + 5;
-  }
-  /* Home dir? */
-  else if(strncmp(pszUnix, "~/", 2) == 0)
-  {
-    strcpy(pszWindows, szHomeDir);
-    iSpaceUsed = lHomeDirLen;
-    pDest = pszWindows + lHomeDirLen;
-    pSrc = (char *) pszUnix + 2;
-  }
-  /* Bit bucket? */
-  else if (strncmp(pszUnix, "/dev/null", 9) == 0)
-  {
-    strcpy(pszWindows, "nul");
-    iSpaceUsed = 3;
-    pDest = pszWindows + lHomeDirLen;
-    pSrc = (char *) pszUnix + 9;
-  }
-  else
-  {
-    pDest = pszWindows;
-    iSpaceUsed = 0;
-    pSrc = (char *) pszUnix;
-  }
-
-  if(iSpaceUsed + strlen(pSrc) + 1 > _MAX_PATH)
-    return ERROR_BUFFER_OVERFLOW;
-
-  /* substitute all slashes */
-  while(*pSrc)
-  {
-    if(*pSrc == '/')
-      *pDest = '\\';
-    else
-      *pDest = *pSrc;
-
-    pDest++;
-    pSrc++;
-  }
-  *pDest = 0;
-
-  if (derefLinks)
-    __win_deref(pszWindows);
-
-#if DEBUG_WINPROC
-  LOG(LOG_EVERYTHING, "Posix path %s resolved to %s\n", pszUnix, pszWindows);
-#endif
-
-  return ERROR_SUCCESS;
-}
-
-/*********************** posix path -> win path ****************************/
-
-/**
- * Set errno according to a Windows error
- * @param lWinError Error code defined in winerror.h
- */
-void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine)
-{
-  switch(lWinError)
-  {
-    case ERROR_SUCCESS:
-      errno = 0;
-      break;
-
-    case ERROR_INVALID_FUNCTION:
-      errno = EBADRQC;
-      break;
-
-    case ERROR_FILE_NOT_FOUND:
-      errno = ENOENT;
-      break;
-
-    case ERROR_PATH_NOT_FOUND:
-      errno = ENOENT;
-      break;
-
-    case ERROR_TOO_MANY_OPEN_FILES:
-      errno = EMFILE;
-      break;
-
-    case ERROR_ACCESS_DENIED:
-      errno = EACCES;
-      break;
-
-    case ERROR_INVALID_HANDLE:
-      errno = EBADF;
-      break;
-
-    case ERROR_NOT_ENOUGH_MEMORY:
-      errno = ENOMEM;
-      break;
-
-    case ERROR_INVALID_DATA:
-      errno = EINVAL;
-      break;
-
-    case ERROR_OUTOFMEMORY:
-      errno = ENOMEM;
-      break;
-
-    case ERROR_INVALID_DRIVE:
-      errno = ENODEV;
-      break;
-
-    case ERROR_NOT_SAME_DEVICE:
-      errno = EXDEV;
-      break;
-
-    case ERROR_NO_MORE_FILES:
-      errno = ENMFILE;
-      break;
-
-    case ERROR_WRITE_PROTECT:
-      errno = EROFS;
-      break;
-
-    case ERROR_BAD_UNIT:
-      errno = ENODEV;
-      break;
-
-    case ERROR_SHARING_VIOLATION:
-      errno = EACCES;
-      break;
-
-    case ERROR_LOCK_VIOLATION:
-      errno = EACCES;
-      break;
-
-    case ERROR_SHARING_BUFFER_EXCEEDED:
-      errno = ENOLCK;
-      break;
-
-    case ERROR_HANDLE_EOF:
-      errno = ENODATA;
-      break;
-
-    case ERROR_HANDLE_DISK_FULL:
-      errno = ENOSPC;
-      break;
-
-    case ERROR_NOT_SUPPORTED:
-      errno = ENOSYS;
-      break;
-
-    case ERROR_REM_NOT_LIST:
-      errno = ENONET;
-      break;
-
-    case ERROR_DUP_NAME:
-      errno = ENOTUNIQ;
-      break;
-
-    case ERROR_BAD_NETPATH:
-      errno = ENOSHARE;
-      break;
-
-    case ERROR_BAD_NET_NAME:
-      errno = ENOSHARE;
-      break;
-
-    case ERROR_FILE_EXISTS:
-      errno = EEXIST;
-      break;
-
-    case ERROR_CANNOT_MAKE:
-      errno = EPERM;
-      break;
-
-    case ERROR_INVALID_PARAMETER:
-      errno = EINVAL;
-      break;
-
-    case ERROR_NO_PROC_SLOTS:
-      errno = EAGAIN;
-      break;
-
-    case ERROR_BROKEN_PIPE:
-      errno = EPIPE;
-      break;
-
-    case ERROR_OPEN_FAILED:
-      errno = EIO;
-      break;
-
-    case ERROR_NO_MORE_SEARCH_HANDLES:
-      errno = ENFILE;
-      break;
-
-    case ERROR_CALL_NOT_IMPLEMENTED:
-      errno = ENOSYS;
-      break;
-
-    case ERROR_INVALID_NAME:
-      errno = ENOENT;
-      break;
-
-    case ERROR_WAIT_NO_CHILDREN:
-      errno = ECHILD;
-      break;
-
-    case ERROR_CHILD_NOT_COMPLETE:
-      errno = EBUSY;
-      break;
-
-    case ERROR_DIR_NOT_EMPTY:
-      errno = ENOTEMPTY;
-      break;
-
-    case ERROR_SIGNAL_REFUSED:
-      errno = EIO;
-      break;
-
-    case ERROR_BAD_PATHNAME:
-      errno = ENOENT;
-      break;
-
-    case ERROR_SIGNAL_PENDING:
-      errno = EBUSY;
-      break;
-
-    case ERROR_MAX_THRDS_REACHED:
-      errno = EAGAIN;
-      break;
-
-    case ERROR_BUSY:
-      errno = EBUSY;
-      break;
-
-    case ERROR_ALREADY_EXISTS:
-      errno = EEXIST;
-      break;
-
-    case ERROR_NO_SIGNAL_SENT:
-      errno = EIO;
-      break;
-
-    case ERROR_FILENAME_EXCED_RANGE:
-      errno = EINVAL;
-      break;
-
-    case ERROR_META_EXPANSION_TOO_LONG:
-      errno = EINVAL;
-      break;
-
-    case ERROR_INVALID_SIGNAL_NUMBER:
-      errno = EINVAL;
-      break;
-
-    case ERROR_THREAD_1_INACTIVE:
-      errno = EINVAL;
-      break;
-
-    case ERROR_BAD_PIPE:
-      errno = EINVAL;
-      break;
-
-    case ERROR_PIPE_BUSY:
-      errno = EBUSY;
-      break;
-
-    case ERROR_NO_DATA:
-      errno = EPIPE;
-      break;
-
-    case ERROR_PIPE_NOT_CONNECTED:
-      errno = ECOMM;
-      break;
-
-    case ERROR_MORE_DATA:
-      errno = EAGAIN;
-      break;
-
-    case ERROR_DIRECTORY:
-      errno = ENOTDIR;
-      break;
-
-    case ERROR_PIPE_CONNECTED:
-      errno = EBUSY;
-      break;
-
-    case ERROR_PIPE_LISTENING:
-      errno = ECOMM;
-      break;
-
-    case ERROR_NO_TOKEN:
-      errno = EINVAL;
-      break;
-
-    case ERROR_PROCESS_ABORTED:
-      errno = EFAULT;
-      break;
-
-    case ERROR_BAD_DEVICE:
-      errno = ENODEV;
-      break;
-
-    case ERROR_BAD_USERNAME:
-      errno = EINVAL;
-      break;
-
-    case ERROR_NOT_CONNECTED:
-      errno = ENOLINK;
-      break;
-
-    case ERROR_OPEN_FILES:
-      errno = EAGAIN;
-      break;
-
-    case ERROR_ACTIVE_CONNECTIONS:
-      errno = EAGAIN;
-      break;
-
-    case ERROR_DEVICE_IN_USE:
-      errno = EAGAIN;
-      break;
-
-    case ERROR_INVALID_AT_INTERRUPT_TIME:
-      errno = EINTR;
-      break;
-
-    case ERROR_IO_DEVICE:
-      errno = EIO;
-      break;
-
-    case ERROR_NOT_OWNER:
-      errno = EPERM;
-      break;
-
-    case ERROR_END_OF_MEDIA:
-      errno = ENOSPC;
-      break;
-
-    case ERROR_EOM_OVERFLOW:
-      errno = ENOSPC;
-      break;
-
-    case ERROR_BEGINNING_OF_MEDIA:
-      errno = ESPIPE;
-      break;
-
-    case ERROR_SETMARK_DETECTED:
-      errno = ESPIPE;
-      break;
-
-    case ERROR_NO_DATA_DETECTED:
-      errno = ENOSPC;
-      break;
-
-    case ERROR_POSSIBLE_DEADLOCK:
-      errno = EDEADLOCK;
-      break;
-
-    case ERROR_CRC:
-      errno = EIO;
-      break;
-
-    case ERROR_NEGATIVE_SEEK:
-      errno = EINVAL;
-      break;
-
-    case ERROR_NOT_READY:
-      errno = ENOMEDIUM;
-      break;
-
-    case ERROR_DISK_FULL:
-      errno = ENOSPC;
-      break;
-
-    case ERROR_NOACCESS:
-      errno = EFAULT;
-      break;
-
-    case ERROR_FILE_INVALID:
-      errno = ENXIO;
-      break;
-
-    case ERROR_INVALID_ADDRESS:
-      errno = EFAULT;
-      break;
-
-    case ERROR_BUFFER_OVERFLOW:
-      errno = ENOMEM;
-      break;
-
-    case ERROR_SERVICE_DOES_NOT_EXIST:
-      errno = ESRCH;
-      break;
-
-    case ERROR_SERVICE_EXISTS:
-      errno = EEXIST;
-      break;
-
-    default:
-      errno = ESTALE;
-      LOG(LOG_ERROR, " Unknown error %i in SetErrnoFromWinError(). " \
-          "Source: %s:%i\n", lWinError, pszCaller, iLine);
-      break;
-  }
-}
-
-/**
- * Set errno according to a Winsock error
- * @param lWinError Error code defined in winsock.h
- */
-void SetErrnoFromWinsockError(long lWinError)
-{
-  switch(lWinError)
-  {
-    case 0:
-      errno = 0;
-      break;
-    case WSAEINTR:
-      errno = EINTR;
-      break;
-
-    case WSAEWOULDBLOCK:
-      errno = EWOULDBLOCK;
-      break;
-
-    case WSAEINPROGRESS:
-      errno = EINPROGRESS;
-      break;
-
-    case WSAEALREADY:
-      errno = EALREADY;
-      break;
-
-    case WSAENOTSOCK:
-      errno = ENOTSOCK;
-      break;
-
-    case WSAEDESTADDRREQ:
-      errno = EDESTADDRREQ;
-      break;
-
-    case WSAEMSGSIZE:
-      errno = EMSGSIZE;
-      break;
-
-    case WSAEPROTOTYPE:
-      errno = EPROTOTYPE;
-      break;
-
-    case WSAENOPROTOOPT:
-      errno = ENOPROTOOPT;
-      break;
-
-    case WSAEPROTONOSUPPORT:
-      errno = EPROTONOSUPPORT;
-      break;
-
-    case WSAESOCKTNOSUPPORT:
-      errno = ESOCKTNOSUPPORT;
-      break;
-
-    case WSAEOPNOTSUPP:
-      errno = EOPNOTSUPP;
-      break;
-
-    case WSAEPFNOSUPPORT:
-      errno = EPFNOSUPPORT;
-      break;
-
-    case WSAEAFNOSUPPORT:
-      errno = EAFNOSUPPORT;
-      break;
-
-    case WSAEADDRINUSE:
-      errno = EADDRINUSE;
-      break;
-
-    case WSAEADDRNOTAVAIL:
-      errno = EADDRNOTAVAIL;
-      break;
-
-    case WSAENETDOWN:
-      errno = ENETDOWN;
-      break;
-
-    case WSAENETUNREACH:
-      errno = ENETUNREACH;
-      break;
-
-    case WSAENETRESET:
-      errno = ENETRESET;
-      break;
-
-    case WSAECONNABORTED:
-      errno = ECONNABORTED;
-      break;
-
-    case WSAECONNRESET:
-      errno = ECONNRESET;
-      break;
-
-    case WSAENOBUFS:
-      errno = ENOBUFS;
-      break;
-
-    case WSAEISCONN:
-      errno = EISCONN;
-      break;
-
-    case WSAENOTCONN:
-      errno = ENOTCONN;
-      break;
-
-    case WSAESHUTDOWN:
-      errno = ESHUTDOWN;
-      break;
-
-    case WSAETOOMANYREFS:
-      errno = ETOOMANYREFS;
-      break;
-
-    case WSAETIMEDOUT:
-      errno = ETIMEDOUT;
-      break;
-
-    case WSAECONNREFUSED:
-      errno = ECONNREFUSED;
-      break;
-
-    case WSAELOOP:
-      errno = ELOOP;
-      break;
-
-    case WSAENAMETOOLONG:
-      errno = ENAMETOOLONG;
-      break;
-
-    case WSAEHOSTDOWN:
-      errno = EHOSTDOWN;
-      break;
-
-    case WSAEHOSTUNREACH:
-      errno = EHOSTUNREACH;
-      break;
-
-    case WSAENOTEMPTY:
-      errno = ENOTEMPTY;
-      break;
-
-    case WSAEPROCLIM:
-      errno = EPROCLIM;
-      break;
-
-    case WSAEUSERS:
-      errno = EUSERS;
-      break;
-
-    case WSAEDQUOT:
-      errno = EDQUOT;
-      break;
-
-    case WSAESTALE:
-      errno = ESTALE;
-      break;
-
-    case WSAEREMOTE:
-      errno = EREMOTE;
-      break;
-
-    case WSAEINVAL:
-      errno = EINVAL;
-      break;
-
-    case WSAEFAULT:
-      errno = EFAULT;
-      break;
-
-    default:
-      errno = ESTALE;
-      LOG(LOG_ERROR, " Unknown error %i in SetErrnoFromWinsockError()\n",
-          lWinError);
-      break;
-  }
-}
-
-/**
- * Set errno according to a HRESULT (COM error code)
- */
-void SetErrnoFromHRESULT(HRESULT hRes)
-{
-  switch(hRes)
-  {
-    case NOERROR:
-      errno = 0;
-      break;
-    case E_UNEXPECTED:
-    case E_FAIL:
-    case S_FALSE:
-      errno = ESTALE;
-    case E_NOTIMPL:
-      errno = ENOSYS;
-      break;
-    case E_OUTOFMEMORY:
-      errno = ENOMEM;
-      break;
-    case E_INVALIDARG:
-    case E_NOINTERFACE:
-      errno = EINVAL;
-      break;
-    case E_POINTER:
-    case E_ABORT:
-      errno = EFAULT;
-      break;
-    case E_HANDLE:
-      errno = EBADF;
-      break;
-    case E_ACCESSDENIED:
-      errno = EACCES;
-      break;
-    case E_PENDING:
-      errno = EBUSY;
-      break;
-    default:
-      SetErrnoFromWinError(HRESULT_CODE(hRes));
-  }
-}
-
-/**
- * Set h_errno according to a Windows error
- * @param lWinError Error code defined in winerror.h
- */
-void SetHErrnoFromWinError(long lWinError)
-{
-  switch(lWinError)
-  {
-    case WSAHOST_NOT_FOUND:
-      /* h_errno is defined as WSAGetLastError */
-      WSASetLastError(HOST_NOT_FOUND);
-      break;
-
-    case WSATRY_AGAIN:
-      WSASetLastError(TRY_AGAIN);
-      break;
-
-    case WSANO_RECOVERY:
-      WSASetLastError(NO_RECOVERY);
-      break;
-
-    case WSANO_DATA:
-      WSASetLastError(NO_DATA);
-      break;
-  }
-}
-
-/**
- * Apply or remove an advisory lock on an open file
- */
-int flock(int fd, int operation)
-{
-  DWORD dwFlags;
-  HANDLE hFile;
-  OVERLAPPED theOvInfo;
-  BOOL bRet;
-
-  errno = 0;
-
-  hFile = (HANDLE) _get_osfhandle(fd);
-  memset(&theOvInfo, 0, sizeof(OVERLAPPED));
-
-  /* Don't deadlock ourselves */
-  if (theWinVersion.dwPlatformId == VER_PLATFORM_WIN32_NT)
-    bRet = UnlockFileEx(hFile, 0, 1, 0, &theOvInfo);
-  else
-    bRet = UnlockFile(hFile, 0, 0, 1, 0);
-
-  if (operation & LOCK_UN)
-  {
-    if (!bRet && ((dwFlags = GetLastError()) != ERROR_NOT_LOCKED))
-    {
-      SetErrnoFromWinError(dwFlags);
-      return -1;
-    }
-    else
-      return 0;
-  }
-
-  if (operation & LOCK_EX)
-  {
-    dwFlags = LOCKFILE_EXCLUSIVE_LOCK;
-  }
-  else if (operation & LOCK_SH)
-  {
-    dwFlags = 0;
-  }
-  else
-  {
-    errno = EINVAL;
-    return -1;
-  }
-
-  if (operation & LOCK_NB)
-    dwFlags |= LOCKFILE_FAIL_IMMEDIATELY;
-
-  if (theWinVersion.dwPlatformId == VER_PLATFORM_WIN32_NT)
-    bRet = LockFileEx(hFile, dwFlags, 0, 1, 0, &theOvInfo);
-  else
-    bRet = LockFile(hFile, 0, 0, 1, 0);
-
-  if (! bRet)
-  {
-    SetErrnoFromWinError(GetLastError());
-    return -1;
-  }
-  else
-    return 0;
-}
-
-/**
- * Synchronize changes to a file
- */
-int fsync(int fildes)
-{
-  if (!FlushFileBuffers((HANDLE) _get_osfhandle(fildes)))
-  {
-    SetErrnoFromWinError(GetLastError());
-    return -1;
-  }
-  else
-  {
-    errno = 0;
-    return 0;
-  }
-}
-
-/**
- * Open a file
- */
-FILE *_win_fopen(const char *filename, const char *mode)
-{
-  char szFile[_MAX_PATH + 1];
-  FILE *hFile;
-  int i;
-
-  if ((i = conv_to_win_path(filename, szFile)) != ERROR_SUCCESS)
-  {
-    SetErrnoFromWinError(i);
-
-    return NULL;
-  }
-
-  hFile = fopen(szFile, mode);
-  SetErrnoFromWinError(GetLastError());
-
-  return hFile;
-}
-
-/**
- * Open a directory
- */
-DIR *_win_opendir(const char *dirname)
-{
-  char szDir[_MAX_PATH + 1];
-  long lRet;
-
-  if ((lRet = conv_to_win_path(dirname, szDir)) != ERROR_SUCCESS)
-  {
-    SetErrnoFromWinError(lRet);
-    return NULL;
-  }
-
-  /* opendir sets errno */
-  return opendir(szDir);
-}
-
-/**
- * Change directory
- */
-int _win_chdir(const char *path)
-{
-  char szDir[_MAX_PATH + 1];
-  long lRet;
-
-  if ((lRet = conv_to_win_path(path, szDir)) != ERROR_SUCCESS)
-  {
-    SetErrnoFromWinError(lRet);
-    return -1;
-  }
-
-  /* chdir sets errno */
-  return chdir(szDir);
-}
-
-/**
- * Get information about an open file.
- */
-int _win_fstat(int handle, struct stat *buffer)
-{
-  errno = 0;
-
-  /* File */
-  if (fstat(handle, buffer) == -1)
-  {
-    /* We just check for a valid handle here */
-
-    /* Handle */
-    memset(buffer, 0, sizeof(struct stat));
-    GetFileType((HANDLE) handle);
-    if (GetLastError() != NO_ERROR)
-    {
-      /* socket */
-      unsigned long lRead;
-      if (ioctlsocket(handle, FIONREAD, &lRead) == SOCKET_ERROR)
-        /* Invalid handle */
-        return -1;
-    }
-  }
-
-  return 0;
-}
-
-/**
- * Remove directory
- */
-int _win_rmdir(const char *path)
-{
-  char szDir[_MAX_PATH + 1];
-  long lRet;
-
-  if ((lRet = conv_to_win_path(path, szDir)) != ERROR_SUCCESS)
-  {
-    SetErrnoFromWinError(lRet);
-    return -1;
-  }
-
-  /* rmdir sets errno */
-  return rmdir(szDir);
-}
-
-/**
- * Create a pipe for reading and writing
- */
-int _win_pipe(int *phandles)
-{
-  /* To get non-blocking pipes we could use CreateNamedPipe here. But it isn't
-     implemented under Win9x. */
-  if (!CreatePipe((HANDLE *) &phandles[0],(HANDLE *) &phandles[1], NULL, 0))
-  {
-    SetErrnoFromWinError(GetLastError());
-
-    return -1;
-  }
-  else
-  {
-    errno = 0;
-    return 0;
-  }
-}
-
-/**
- * Determine file-access permission.
- */
-int _win_access( const char *path, int mode )
-{
-  char szFile[_MAX_PATH + 1];
-  long lRet;
-
-  if ((lRet = conv_to_win_path(path, szFile)) != ERROR_SUCCESS)
-  {
-    SetErrnoFromWinError(lRet);
-    return -1;
-  }
-
-  /* access sets errno */
-  return access(szFile, mode);
-}
-
-/**
- * Change the file-permission settings.
- */
-int _win_chmod(const char *filename, int pmode)
-{
-  char szFile[_MAX_PATH + 1];
-  long lRet;
-
-  if ((lRet = conv_to_win_path(filename, szFile)) != ERROR_SUCCESS)
-  {
-    SetErrnoFromWinError(lRet);
-    return -1;
-  }
-
-  /* chmod sets errno */
-  return access(szFile, pmode);
-}
-
-
-char *realpath(const char *file_name, char *resolved_name)
-{
-  char szFile[_MAX_PATH + 1];
-  long lRet;
-  char *pszRet;
-
-  if ((lRet = conv_to_win_path(file_name, szFile)) != ERROR_SUCCESS)
-  {
-    SetErrnoFromWinError(lRet);
-    return NULL;
-  }
-
-  pszRet = _fullpath(szFile, resolved_name, MAX_PATH);
-  SetErrnoFromWinError(GetLastError());
-
-  return pszRet;
-}
-
-/**
- * Delete a file
- * If path is a link, the link itself is removed
- */
-int _win_remove(const char *path)
-{
-  char szFile[_MAX_PATH + 1];
-  long lRet;
-
-  if ((lRet = conv_to_win_path_ex(path, szFile, 0)) != ERROR_SUCCESS)
-  {
-    SetErrnoFromWinError(lRet);
-    return -1;
-  }
-
-  /* remove sets errno */
-  return remove(szFile);
-}
-
-/**
- * Rename a file
- * If oldname is a link, the link itself is renamed
- */
-int _win_rename(const char *oldname, const char *newname)
-{
-  char szOldName[_MAX_PATH + 1];
-  char szNewName[_MAX_PATH + 1];
-  long lRet;
-
-  if ((lRet = conv_to_win_path_ex(oldname, szOldName, 0)) != ERROR_SUCCESS)
-  {
-    SetErrnoFromWinError(lRet);
-    return -1;
-  }
-
-  if ((lRet = conv_to_win_path(newname, szNewName)) != ERROR_SUCCESS)
-  {
-    SetErrnoFromWinError(lRet);
-    return -1;
-  }
-
-  /* rename sets errno */
-  return rename(szOldName, szNewName);
-}
-
-/**
- * Get status information on a file
- */
-int __win_stat(const char *path, struct stat *buffer, int iDeref)
-{
-  char szFile[_MAX_PATH + 1];
-  long lRet;
-
-  if ((lRet = conv_to_win_path(path, szFile)) != ERROR_SUCCESS)
-  {
-    SetErrnoFromWinError(lRet);
-    return -1;
-  }
-
-  /* Remove trailing slash */
-  lRet = strlen(szFile) - 1;
-  if (szFile[lRet] == '\\')
-  {
-    szFile[lRet] = 0;
-  }
-
-  /* Dereference symlinks */
-  if (iDeref)
-  {
-    if (__win_deref(szFile) == -1 && errno != EINVAL)
-      return -1;
-  }
-
-  /* stat sets errno */
-  return stat(szFile, buffer);
-}
-
-/**
- * Get status information on a file
- */
-int _win_stat(const char *path, struct stat *buffer)
-{
-  return __win_stat(path, buffer, 1);
-}
-
-/**
- * Delete a file
- * If filename is a link, the link itself it removed.
- */
-int _win_unlink(const char *filename)
-{
-  char szFile[_MAX_PATH + 1];
-  long lRet;
-
-  if ((lRet = conv_to_win_path_ex(filename, szFile, 0)) != ERROR_SUCCESS)
-  {
-    SetErrnoFromWinError(lRet);
-    return -1;
-  }
-
-  /* unlink sets errno */
-  return unlink(szFile);
-}
-
-DWORD WINAPI __win_Write(TReadWriteInfo *pInfo)
-{
-  int iRet;
-
-  errno = 0;
-  if ((iRet = write(pInfo->fildes, pInfo->buf, pInfo->nbyte)) == -1)
-  {
-    DWORD dwWritten;
-    if (!WriteFile((HANDLE) pInfo->fildes, pInfo->buf, pInfo->nbyte,
-      &dwWritten, NULL))
-    {
-      SetErrnoFromWinError(GetLastError());
-      return -1;
-    }
-    else
-      return dwWritten;
-  }
-  else
-    return iRet;
-}
-
-/**
- * Write on a file
- * If the handle is in non-blocking mode, this function
- * always returns 1 for non-sockets.
- */
-int _win_write(int fildes, const void *buf, size_t nbyte)
-{
-  if (isSocketValid(fildes))
-  {
-    return _win_send(fildes, buf, nbyte, 0);
-  }
-  else
-  {
-    TReadWriteInfo theInfo;
-    theInfo.fildes = fildes;
-    theInfo.buf = (void *) buf;
-    theInfo.nbyte = nbyte;
-
-    if (__win_IsHandleMarkedAsBlocking(fildes))
-      return __win_Write(&theInfo);
-    else
-    {
-      DWORD dwTID; /* Last ptr of CreateThread my not be NULL under Win9x */
-      CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) __win_Write, &theInfo, 0, 
&dwTID);
-      return 1;
-    }
-  }
-}
-
-DWORD WINAPI __win_Read(TReadWriteInfo *pInfo)
-{
-  int iRet;
-
-  errno = 0;
-  if ((iRet = read(pInfo->fildes, pInfo->buf, pInfo->nbyte)) == -1)
-  {
-    DWORD dwRead;
-    if (!ReadFile((HANDLE) pInfo->fildes, pInfo->buf, pInfo->nbyte, &dwRead,
-      NULL))
-    {
-      SetErrnoFromWinError(GetLastError());
-      return -1;
-    }
-    else
-      return dwRead;
-  }
-  else
-    return iRet;
-}
-
-/**
- * Reads data from a file.
- * If the handle is in non-blocking mode, this function
- * always returns 1 for non-sockets.
- */
-int _win_read(int fildes, void *buf, size_t nbyte)
-{
-  if (isSocketValid(fildes))
-  {
-    return _win_recv(fildes, (char *) buf, nbyte, 0);
-  }
-  else
-  {
-    TReadWriteInfo theInfo;
-    theInfo.fildes = fildes;
-    theInfo.buf = buf;
-    theInfo.nbyte = nbyte;
-
-    if (__win_IsHandleMarkedAsBlocking(fildes))
-      return __win_Read(&theInfo);
-    else
-    {
-      DWORD dwTID; /* Last ptr of CreateThread my not be NULL under Win9x */
-      CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) __win_Read, &theInfo, 0, 
&dwTID);
-      return 1;
-    }
-  }
-}
-
-/**
- * Writes data to a stream
- */
-size_t _win_fwrite(const void *buffer, size_t size, size_t count, FILE *stream)
-{
-  DWORD dwWritten;
-
-  WriteFile((HANDLE) _get_osfhandle(fileno(stream)), buffer, size, &dwWritten,
-            NULL);
-  SetErrnoFromWinError(GetLastError());
-
-  return dwWritten;
-}
-
-/**
- * Reads data from a stream
- */
-size_t _win_fread( void *buffer, size_t size, size_t count, FILE *stream )
-{
-  DWORD dwRead;
-  int iItemsRead;
-  void *pDest = buffer;
-
-  for(iItemsRead = 0; iItemsRead < count; iItemsRead++)
-  {
-    if (!ReadFile((HANDLE) _get_osfhandle(fileno(stream)), pDest, size,
-                  &dwRead, NULL))
-      break;
-    pDest += size;
-  }
-
-  SetErrnoFromWinError(GetLastError());
-
-  return iItemsRead;
-}
-
-/***
- * Make a link to a file
- **/
-int _win_symlink(const char *path1, const char *path2)
-{
-  char szFile1[_MAX_PATH + 1], szFile2[_MAX_PATH + 1];
-  long lRet;
-
-  if ((lRet = conv_to_win_path(path1, szFile1)) != ERROR_SUCCESS)
-  {
-    SetErrnoFromWinError(lRet);
-    return -1;
-  }
-
-  if ((lRet = conv_to_win_path(path2, szFile2)) != ERROR_SUCCESS)
-  {
-    SetErrnoFromWinError(lRet);
-    return -1;
-  }
-
-  /* CreateShortcut sets errno */
-  lRet = CreateShortcut(szFile1, szFile2);
-
-  return lRet ? 0 : -1;
-}
-
-/**
- * map files into memory
- * @author Cygwin team
- * @author Nils Durner
- */
-void *_win_mmap(void *start, size_t len, int access, int flags, int fd,
-                unsigned long long off) {
-  DWORD protect, high, low, access_param;
-  HANDLE h, hFile;
-  SECURITY_ATTRIBUTES sec_none;
-  void *base;
-  BOOL bFound = FALSE;
-  unsigned int uiIndex;
-
-  errno = 0;
-
-  switch(access)
-  {
-    case PROT_WRITE:
-      protect = PAGE_READWRITE;
-      access_param = FILE_MAP_WRITE;
-      break;
-    case PROT_READ:
-      protect = PAGE_READONLY;
-      access_param = FILE_MAP_READ;
-      break;
-    default:
-      protect = PAGE_WRITECOPY;
-      access_param = FILE_MAP_COPY;
-      break;
-  }
-
-  sec_none.nLength = sizeof(SECURITY_ATTRIBUTES);
-  sec_none.bInheritHandle = TRUE;
-  sec_none.lpSecurityDescriptor = NULL;
-
-  hFile = (HANDLE) _get_osfhandle(fd);
-
-  h = CreateFileMapping(hFile, &sec_none, protect, 0, 0, NULL);
-
-  if (! h)
-  {
-    SetErrnoFromWinError(GetLastError());
-    return (void *) -1;
-  }
-
-  high = off >> 32;
-  low = off & ULONG_MAX;
-  base = NULL;
-
-  /* If a non-zero start is given, try mapping using the given address first.
-     If it fails and flags is not MAP_FIXED, try again with NULL address. */
-  if (start)
-    base = MapViewOfFileEx(h, access_param, high, low, len, start);
-  if (!base && !(flags & MAP_FIXED))
-    base = MapViewOfFileEx(h, access_param, high, low, len, NULL);
-
-  if (!base || ((flags & MAP_FIXED) && base != start))
-  {
-    if (!base)
-      SetErrnoFromWinError(GetLastError());
-    else
-      errno = EINVAL;
-
-    CloseHandle(h);
-    return (void *) -1;
-  }
-
-  /* Save mapping handle */
-  WaitForSingleObject(hMappingsLock, INFINITE);
-
-  for(uiIndex = 0; uiIndex <= uiMappingsCount; uiIndex++)
-  {
-    if (pMappings[uiIndex].pStart == base)
-    {
-      bFound = 1;
-      break;
-    }
-  }
-
-  if (! bFound)
-  {
-    uiIndex = 0;
-
-    while(TRUE)
-    {
-      if (pMappings[uiIndex].pStart == NULL)
-      {
-        pMappings[uiIndex].pStart = base;
-        pMappings[uiIndex].hMapping = h;
-      }
-      if (uiIndex == uiMappingsCount)
-      {
-        uiMappingsCount++;
-        pMappings = (TMapping *) realloc(pMappings, (uiMappingsCount + 1) * 
sizeof(TMapping));
-        pMappings[uiMappingsCount].pStart = NULL;
-
-        break;
-      }
-      uiIndex++;
-    }
-  }
-  ReleaseMutex(hMappingsLock);
-
-  return base;
-}
-
-/**
- * Unmap files from memory
- * @author Cygwin team
- * @author Nils Durner
- */
-int _win_munmap(void *start, size_t length)
-{
-  unsigned uiIndex;
-  BOOL success = UnmapViewOfFile(start);
-  SetErrnoFromWinError(GetLastError());
-
-  if (success)
-  {
-    /* Release mapping handle */
-    WaitForSingleObject(hMappingsLock, INFINITE);
-
-    for(uiIndex = 0; uiIndex <= uiMappingsCount; uiIndex++)
-    {
-      if (pMappings[uiIndex].pStart == start)
-      {
-        success = CloseHandle(pMappings[uiIndex].hMapping);
-        SetErrnoFromWinError(GetLastError());
-        pMappings[uiIndex].pStart = NULL;
-        pMappings[uiIndex].hMapping = NULL;
-
-        break;
-      }
-    }
-
-    ReleaseMutex(hMappingsLock);
-  }
-
-  return success ? 0 : -1;
-}
-
-/**
- * Get symbolic link status
- */
-int _win_lstat(const char *path, struct stat *buf)
-{
-  return __win_stat(path, buf, 0);
-}
-
-/**
- * Read the contents of a symbolic link
- */
-int _win_readlink(const char *path, char *buf, size_t bufsize)
-{
-  char szDeref[_MAX_PATH + 1];
-  int iLen;
-
-  if(strlen(path) > _MAX_PATH)
-  {
-    errno = ENAMETOOLONG;
-    return -1;
-  }
-
-  strcpy(szDeref, path);
-
-  if (__win_deref(szDeref) == -1)
-    return -1;
-
-  if ((iLen = strlen(szDeref)) > bufsize)
-  {
-    errno = ENAMETOOLONG;
-    return -1;
-  }
-
-  errno = 0;
-  return iLen;
-}
-
-/**
- * language information
- */
-#ifndef HAVE_LANGINFO_H
-char *nl_langinfo(int item)
-{
-  unsigned int loc;
-
-  loc = GetThreadLocale();
-
-  switch(item)
-  {
-    case CODESET:
-      {
-        unsigned int cp = GetACP();
-
-        if (cp)
-          sprintf(__langinfo, "CP%u", cp);
-        else
-          strcpy(__langinfo, "UTF-8"); /* ? */
-        return __langinfo;
-      }
-    case D_T_FMT:
-    case T_FMT_AMPM:
-    case ERA_D_T_FMT:
-      strcpy(__langinfo, "%c");
-      return __langinfo;
-    case D_FMT:
-    case ERA_D_FMT:
-      strcpy(__langinfo, "%x");
-      return __langinfo;
-    case T_FMT:
-    case ERA_T_FMT:
-      strcpy(__langinfo, "%X");
-      return __langinfo;
-    case AM_STR:
-      GetLocaleInfo(loc, LOCALE_S1159, __langinfo, 251);
-      return __langinfo;
-    case PM_STR:
-      GetLocaleInfo(loc, LOCALE_S2359, __langinfo, 251);
-      return __langinfo;
-    case DAY_1:
-      GetLocaleInfo(loc, LOCALE_SDAYNAME1, __langinfo, 251);
-      return __langinfo;
-    case DAY_2:
-      GetLocaleInfo(loc, LOCALE_SDAYNAME2, __langinfo, 251);
-      return __langinfo;
-    case DAY_3:
-      GetLocaleInfo(loc, LOCALE_SDAYNAME3, __langinfo, 251);
-      return __langinfo;
-    case DAY_4:
-      GetLocaleInfo(loc, LOCALE_SDAYNAME4, __langinfo, 251);
-      return __langinfo;
-    case DAY_5:
-      GetLocaleInfo(loc, LOCALE_SDAYNAME5, __langinfo, 251);
-      return __langinfo;
-    case DAY_6:
-      GetLocaleInfo(loc, LOCALE_SDAYNAME6, __langinfo, 251);
-      return __langinfo;
-    case DAY_7:
-      GetLocaleInfo(loc, LOCALE_SDAYNAME7, __langinfo, 251);
-      return __langinfo;
-    case ABDAY_1:
-      GetLocaleInfo(loc, LOCALE_SABBREVDAYNAME1, __langinfo, 251);
-      return __langinfo;
-    case ABDAY_2:
-      GetLocaleInfo(loc, LOCALE_SABBREVDAYNAME2, __langinfo, 251);
-      return __langinfo;
-    case ABDAY_3:
-      GetLocaleInfo(loc, LOCALE_SABBREVDAYNAME3, __langinfo, 251);
-      return __langinfo;
-    case ABDAY_4:
-      GetLocaleInfo(loc, LOCALE_SABBREVDAYNAME4, __langinfo, 251);
-      return __langinfo;
-    case ABDAY_5:
-      GetLocaleInfo(loc, LOCALE_SABBREVDAYNAME5, __langinfo, 251);
-      return __langinfo;
-    case ABDAY_6:
-      GetLocaleInfo(loc, LOCALE_SABBREVDAYNAME6, __langinfo, 251);
-      return __langinfo;
-    case ABDAY_7:
-      GetLocaleInfo(loc, LOCALE_SABBREVDAYNAME7, __langinfo, 251);
-      return __langinfo;
-    case MON_1:
-      GetLocaleInfo(loc, LOCALE_SMONTHNAME1, __langinfo, 251);
-      return __langinfo;
-    case MON_2:
-      GetLocaleInfo(loc, LOCALE_SMONTHNAME2, __langinfo, 251);
-      return __langinfo;
-    case MON_3:
-      GetLocaleInfo(loc, LOCALE_SMONTHNAME3, __langinfo, 251);
-      return __langinfo;
-    case MON_4:
-      GetLocaleInfo(loc, LOCALE_SMONTHNAME4, __langinfo, 251);
-      return __langinfo;
-    case MON_5:
-      GetLocaleInfo(loc, LOCALE_SMONTHNAME5, __langinfo, 251);
-      return __langinfo;
-    case MON_6:
-      GetLocaleInfo(loc, LOCALE_SMONTHNAME6, __langinfo, 251);
-      return __langinfo;
-    case MON_7:
-      GetLocaleInfo(loc, LOCALE_SMONTHNAME7, __langinfo, 251);
-      return __langinfo;
-    case MON_8:
-      GetLocaleInfo(loc, LOCALE_SMONTHNAME8, __langinfo, 251);
-      return __langinfo;
-    case MON_9:
-      GetLocaleInfo(loc, LOCALE_SMONTHNAME9, __langinfo, 251);
-      return __langinfo;
-    case MON_10:
-      GetLocaleInfo(loc, LOCALE_SMONTHNAME10, __langinfo, 251);
-      return __langinfo;
-    case MON_11:
-      GetLocaleInfo(loc, LOCALE_SMONTHNAME11, __langinfo, 251);
-      return __langinfo;
-    case MON_12:
-      GetLocaleInfo(loc, LOCALE_SMONTHNAME12, __langinfo, 251);
-      return __langinfo;
-    case ABMON_1:
-      GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME1, __langinfo, 251);
-      return __langinfo;
-    case ABMON_2:
-      GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME2, __langinfo, 251);
-      return __langinfo;
-    case ABMON_3:
-      GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME3, __langinfo, 251);
-      return __langinfo;
-    case ABMON_4:
-      GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME4, __langinfo, 251);
-      return __langinfo;
-    case ABMON_5:
-      GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME5, __langinfo, 251);
-      return __langinfo;
-    case ABMON_6:
-      GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME6, __langinfo, 251);
-      return __langinfo;
-    case ABMON_7:
-      GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME7, __langinfo, 251);
-      return __langinfo;
-    case ABMON_8:
-      GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME8, __langinfo, 251);
-      return __langinfo;
-    case ABMON_9:
-      GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME9, __langinfo, 251);
-      return __langinfo;
-    case ABMON_10:
-      GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME10, __langinfo, 251);
-      return __langinfo;
-    case ABMON_11:
-      GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME11, __langinfo, 251);
-      return __langinfo;
-    case ABMON_12:
-      GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME12, __langinfo, 251);
-      return __langinfo;
-    case ERA:
-      /* Not implemented */
-      __langinfo[0] = 0;
-      return __langinfo;
-    case ALT_DIGITS:
-      GetLocaleInfo(loc, LOCALE_SNATIVEDIGITS, __langinfo, 251);
-      return __langinfo;
-    case RADIXCHAR:
-      GetLocaleInfo(loc, LOCALE_SDECIMAL, __langinfo, 251);
-      return __langinfo;
-    case THOUSEP:
-      GetLocaleInfo(loc, LOCALE_STHOUSAND, __langinfo, 251);
-      return __langinfo;
-    case YESEXPR:
-      /* Not localized */
-      strcpy(__langinfo, "^[yY]");
-      return __langinfo;
-    case NOEXPR:
-      /* Not localized */
-      strcpy(__langinfo, "^[nN]");
-      return __langinfo;
-    case CRNCYSTR:
-      GetLocaleInfo(loc, LOCALE_STHOUSAND, __langinfo, 251);
-      if (__langinfo[0] == '0' || __langinfo[0] == '2')
-        __langinfo[0] = '-';
-      else
-        __langinfo[0] = '+';
-      GetLocaleInfo(loc, LOCALE_SCURRENCY, __langinfo + 1, 251);
-    default:
-      __langinfo[0] = 0;
-      return __langinfo;
-  }
-}
-#endif
-
-/**
- * Accepts an incoming connection attempt on a socket
- */
-int _win_accept(SOCKET s, struct sockaddr *addr, int *addrlen)
-{
-  int iRet = accept(s, addr, addrlen);
-
-  SetErrnoFromWinsockError(WSAGetLastError());
-
-  return iRet;
-}
-
-/**
- * Accept a new connection on a socket
- */
-int _win_bind(SOCKET s, const struct sockaddr *name, int namelen)
-{
-  int iRet = bind(s, name, namelen);
-
-  SetErrnoFromWinsockError(WSAGetLastError());
-
-  return iRet;
-}
-
-/**
- * Initiate a connection on a socket
- */
-int _win_connect(SOCKET s,const struct sockaddr *name, int namelen)
-{
-  int iRet, iWSErr;
-  BOOL bBlocking;
-
-  /* connect()ing a non-blocking socket always fails under Windows.
-     Check whether it is blocking */
-  bBlocking = __win_IsHandleMarkedAsBlocking(s);
-  if (! bBlocking)
-  {
-    u_long l;
-    l = 0;
-    ioctlsocket(s, FIONBIO, &l);
-  }
-
-  iRet = connect(s, name, namelen);
-  iWSErr = WSAGetLastError();
-
-  if (! bBlocking)
-  {
-    u_long l;
-    l = 1;
-    ioctlsocket(s, FIONBIO, &l);
-  }
-
-  SetErrnoFromWinsockError(iWSErr);
-
-  return iRet;
-}
-
-/**
- * Get the name of the peer socket
- */
-int _win_getpeername(SOCKET s, struct sockaddr *name,
-                int *namelen)
-{
-  int iRet = getpeername(s, name, namelen);
-
-  SetErrnoFromWinsockError(WSAGetLastError());
-
-  return iRet;
-}
-
-/**
- * Get the socket name
- */
-int _win_getsockname(SOCKET s, struct sockaddr *name,
-                int *namelen)
-{
-  int iRet = getsockname(s, name, namelen);
-
-  SetErrnoFromWinsockError(WSAGetLastError());
-
-  return iRet;
-}
-
-/**
- * Get the socket options
- */
-int _win_getsockopt(SOCKET s, int level, int optname, char *optval, int 
*optlen)
-{
-  int iRet = getsockopt(s, level, optname, optval, optlen);
-
-  SetErrnoFromWinsockError(WSAGetLastError());
-
-  return iRet;
-}
-
-/**
- * Listen for socket connections and limit the queue of incoming connections
- */
-int _win_listen(SOCKET s, int backlog)
-{
-  int iRet = listen(s, backlog);
-
-  SetErrnoFromWinsockError(WSAGetLastError());
-
-  return iRet;
-}
-
-/**
- * Receive a message from a connected socket
- */
-int _win_recv(SOCKET s, char *buf, int len, int flags)
-{
-  int iRet = recv(s, buf, len, flags);
-
-  SetErrnoFromWinsockError(WSAGetLastError());
-
-  return iRet;
-}
-
-/**
- * Receive a message from a socket
- */
-int _win_recvfrom(SOCKET s, void *buf, int len, int flags,
-             struct sockaddr *from, int *fromlen)
-{
-  int iRet = recvfrom(s, buf, len, flags, from, fromlen);
-
-  SetErrnoFromWinsockError(WSAGetLastError());
-
-  return iRet;
-}
-
-/**
- * Send a message on a socket
- */
-int _win_send(SOCKET s, const char *buf, int len, int flags)
-{
-  int iRet = send(s, buf, len, flags);
-
-  SetErrnoFromWinsockError(WSAGetLastError());
-
-  return iRet;
-}
-
-/**
- * Send a message on a socket
- */
-int _win_sendto(SOCKET s, const char *buf, int len, int flags,
-                const struct sockaddr *to, int tolen)
-{
-  int iRet = sendto(s, buf, len, flags, to, tolen);
-
-  SetErrnoFromWinsockError(WSAGetLastError());
-
-  return iRet;
-}
-
-/**
- * Set the socket options
- */
-int _win_setsockopt(SOCKET s, int level, int optname, const void *optval,
-                    int optlen)
-{
-  int iRet = setsockopt(s, level, optname, (const char *) optval, optlen);
-
-  SetErrnoFromWinsockError(WSAGetLastError());
-
-  return iRet;
-}
-
-/**
- * Shut down socket send and receive operations
- */
-int _win_shutdown(SOCKET s, int how)
-{
-  int iRet = shutdown(s, how);
-
-  SetErrnoFromWinsockError(WSAGetLastError());
-
-  return iRet;
-}
-
-/**
- * Create an endpoint for communication
- */
-SOCKET _win_socket(int af, int type, int protocol)
-{
-  int iRet;
-
-  errno = 0;
-
-  iRet = socket(af, type, protocol);
-  if (iRet == SOCKET_ERROR)
-  {
-    SetErrnoFromWinsockError(WSAGetLastError());
-
-    return -1;
-  }
-  else
-  {
-    /* Sockets are not blocking by default under Windows 9x */
-    u_long l;
-    l = 0;
-    ioctlsocket(iRet, FIONBIO, &l);
-
-    return iRet;
-  }
-}
-
-/**
- * Retrieve the host information corresponding to a network address
- */
-struct hostent *_win_gethostbyaddr(const char *addr, int len, int type)
-{
-  struct hostent *pHost = gethostbyaddr(addr, len, type);
-
-  SetHErrnoFromWinError(WSAGetLastError());
-  SetErrnoFromWinsockError(WSAGetLastError());
-
-  return pHost;
-}
-
-/**
- * Retrieves host information corresponding to a host name from a host database
- */
-struct hostent *_win_gethostbyname(const char *name)
-{
-  struct hostent *pHost = gethostbyname(name);
-
-  SetHErrnoFromWinError(WSAGetLastError());
-  SetErrnoFromWinsockError(WSAGetLastError());
-
-  return pHost;
-}
-
-/**
- * Get a system error message
- */
-char *_win_strerror(int errnum)
-{
-  char *error;
-
-  switch (errnum)
-    {
-#ifdef EPERM
-    case EPERM:
-      error = "Not super-user";
-      break;
-#endif
-#ifdef ENOENT
-    case ENOENT:
-      error = "No such file or directory";
-      break;
-#endif
-#ifdef ESRCH
-    case ESRCH:
-      error = "No such process";
-      break;
-#endif
-#ifdef EINTR
-    case EINTR:
-      error = "Interrupted system call";
-      break;
-#endif
-#ifdef EIO
-    case EIO:
-      error = "I/O error";
-      break;
-#endif
-#ifdef ENXIO
-    case ENXIO:
-      error = "No such device or address";
-      break;
-#endif
-#ifdef E2BIG
-    case E2BIG:
-      error = "Arg list too long";
-      break;
-#endif
-#ifdef ENOEXEC
-    case ENOEXEC:
-      error = "Exec format error";
-      break;
-#endif
-#ifdef EBADF
-    case EBADF:
-      error = "Bad file number";
-      break;
-#endif
-#ifdef ECHILD
-    case ECHILD:
-      error = "No children";
-      break;
-#endif
-#ifdef EAGAIN
-    case EAGAIN:
-      error = "Resource unavailable or operation would block, try again";
-      break;
-#endif
-#ifdef ENOMEM
-    case ENOMEM:
-      error = "Not enough memory";
-      break;
-#endif
-#ifdef EACCES
-    case EACCES:
-      error = "Permission denied";
-      break;
-#endif
-#ifdef EFAULT
-    case EFAULT:
-      error = "Bad address";
-      break;
-#endif
-#ifdef ENOTBLK
-    case ENOTBLK:
-      error = "Block device required";
-      break;
-#endif
-#ifdef EBUSY
-    case EBUSY:
-      error = "Mount device busy";
-      break;
-#endif
-#ifdef EEXIST
-    case EEXIST:
-      error = "File exists";
-      break;
-#endif
-#ifdef EXDEV
-    case EXDEV:
-      error = "Cross-device link";
-      break;
-#endif
-#ifdef ENODEV
-    case ENODEV:
-      error = "No such device";
-      break;
-#endif
-#ifdef ENOTDIR
-    case ENOTDIR:
-      error = "Not a directory";
-      break;
-#endif
-#ifdef EISDIR
-    case EISDIR:
-      error = "Is a directory";
-      break;
-#endif
-#ifdef EINVAL
-    case EINVAL:
-      error = "Invalid argument";
-      break;
-#endif
-#ifdef ENFILE
-    case ENFILE:
-      error = "Too many open files in system";
-      break;
-#endif
-#ifdef EMFILE
-    case EMFILE:
-      error = "Too many open files";
-      break;
-#endif
-#ifdef ENOTTY
-    case ENOTTY:
-      error = "Not a typewriter";
-      break;
-#endif
-#ifdef ETXTBSY
-    case ETXTBSY:
-      error = "Text file busy";
-      break;
-#endif
-#ifdef EFBIG
-    case EFBIG:
-      error = "File too large";
-      break;
-#endif
-#ifdef ENOSPC
-    case ENOSPC:
-      error = "No space left on device";
-      break;
-#endif
-#ifdef ESPIPE
-    case ESPIPE:
-      error = "Illegal seek";
-      break;
-#endif
-#ifdef EROFS
-    case EROFS:
-      error = "Read only file system";
-      break;
-#endif
-#ifdef EMLINK
-    case EMLINK:
-      error = "Too many links";
-      break;
-#endif
-#ifdef EPIPE
-    case EPIPE:
-      error = "Broken pipe";
-      break;
-#endif
-#ifdef EDOM
-    case EDOM:
-      error = "Math arg out of domain of func";
-      break;
-#endif
-#ifdef ERANGE
-    case ERANGE:
-      error = "Math result not representable";
-      break;
-#endif
-#ifdef ENOMSG
-    case ENOMSG:
-      error = "No message of desired type";
-      break;
-#endif
-#ifdef EIDRM
-    case EIDRM:
-      error = "Identifier removed";
-      break;
-#endif
-#ifdef ECHRNG
-    case ECHRNG:
-      error = "Channel number out of range";
-      break;
-#endif
-#ifdef EL2NSYNC
-    case EL2NSYNC:
-      error = "Level 2 not synchronized";
-      break;
-#endif
-#ifdef L3HLT
-    case L3HLT:
-      error = "Level 3 halted";
-      break;
-#endif
-#ifdef EL3RST
-    case EL3RST:
-      error = "Level 3 reset";
-      break;
-#endif
-#ifdef ELNRNG
-    case ELNRNG:
-      error = "Link number out of range";
-      break;
-#endif
-#ifdef EUNATCH
-    case EUNATCH:
-      error = "Protocol driver not attached";
-      break;
-#endif
-#ifdef ENOCSI
-    case ENOCSI:
-      error = "No CSI structure available";
-      break;
-#endif
-#ifdef EL2HLT
-    case EL2HLT:
-      error = "Level 2 halted";
-      break;
-#endif
-#ifdef EDEADLK
-    case EDEADLK:
-      error = "Deadlock condition";
-      break;
-#endif
-#ifdef ENOLCK
-    case ENOLCK:
-      error = "No record locks available";
-      break;
-#endif
-#ifdef EBADE
-    case EBADE:
-      error = "Invalid exchange";
-      break;
-#endif
-#ifdef EBADR
-    case EBADR:
-      error = "Invalid request descriptor";
-      break;
-#endif
-#ifdef EXFULL
-    case EXFULL:
-      error = "Exchange full";
-      break;
-#endif
-#ifdef ENOANO
-    case ENOANO:
-      error = "No anode";
-      break;
-#endif
-#ifdef EBADRQC
-    case EBADRQC:
-      error = "Invalid request code";
-      break;
-#endif
-#ifdef EBADSLT
-    case EBADSLT:
-      error = "Invalid slot";
-      break;
-#endif
-#ifdef EDEADLOCK
-    case EDEADLOCK:
-      error = "File locking deadlock error";
-      break;
-#endif
-#ifdef EBFONT
-    case EBFONT:
-      error = "Bad font file fmt";
-      break;
-#endif
-#ifdef ENOSTR
-    case ENOSTR:
-      error = "Device not a stream";
-      break;
-#endif
-#ifdef ENODATA
-    case ENODATA:
-      error = "No data (for no delay io)";
-      break;
-#endif
-#ifdef ETIME
-    case ETIME:
-      error = "Timer expired";
-      break;
-#endif
-#ifdef ENOSR
-    case ENOSR:
-      error = "Out of streams resources";
-      break;
-#endif
-#ifdef ENONET
-    case ENONET:
-      error = "Machine is not on the network";
-      break;
-#endif
-#ifdef ENOPKG
-    case ENOPKG:
-      error = "Package not installed";
-      break;
-#endif
-#ifdef EREMOTE
-    case EREMOTE:
-      error = "The object is remote";
-      break;
-#endif
-#ifdef ENOLINK
-    case ENOLINK:
-      error = "The link has been severed";
-      break;
-#endif
-#ifdef EADV
-    case EADV:
-      error = "Advertise error";
-      break;
-#endif
-#ifdef ESRMNT
-    case ESRMNT:
-      error = "Srmount error";
-      break;
-#endif
-#ifdef ECOMM
-    case ECOMM:
-      error = "Communication error on send";
-      break;
-#endif
-#ifdef EPROTO
-    case EPROTO:
-      error = "Protocol error";
-      break;
-#endif
-#ifdef EMULTIHOP
-    case EMULTIHOP:
-      error = "Multihop attempted";
-      break;
-#endif
-#ifdef ELBIN
-    case ELBIN:
-      error = "Inode is remote (not really error)";
-      break;
-#endif
-#ifdef EDOTDOT
-    case EDOTDOT:
-      error = "Cross mount point (not really error)";
-      break;
-#endif
-#ifdef EBADMSG
-    case EBADMSG:
-      error = "Trying to read unreadable message";
-      break;
-#endif
-#ifdef ENOTUNIQ
-    case ENOTUNIQ:
-      error = "Given log. name not unique";
-      break;
-#endif
-#ifdef EBADFD
-    case EBADFD:
-      error = "f.d. invalid for this operation";
-      break;
-#endif
-#ifdef EREMCHG
-    case EREMCHG:
-      error = "Remote address changed";
-      break;
-#endif
-#ifdef ELIBACC
-    case ELIBACC:
-      error = "Can't access a needed shared lib";
-      break;
-#endif
-#ifdef ELIBBAD
-    case ELIBBAD:
-      error = "Accessing a corrupted shared lib";
-      break;
-#endif
-#ifdef ELIBSCN
-    case ELIBSCN:
-      error = ".lib section in a.out corrupted";
-      break;
-#endif
-#ifdef ELIBMAX
-    case ELIBMAX:
-      error = "Attempting to link in too many libs";
-      break;
-#endif
-#ifdef ELIBEXEC
-    case ELIBEXEC:
-      error = "Attempting to exec a shared library";
-      break;
-#endif
-#ifdef ENOSYS
-    case ENOSYS:
-      error = "Function not implemented";
-      break;
-#endif
-#ifdef ENMFILE
-    case ENMFILE:
-      error = "No more files";
-      break;
-#endif
-#ifdef ENOTEMPTY
-    case ENOTEMPTY:
-      error = "Directory not empty";
-      break;
-#endif
-#ifdef ENAMETOOLONG
-    case ENAMETOOLONG:
-      error = "File or path name too long";
-      break;
-#endif
-#ifdef ELOOP
-    case ELOOP:
-      error = "Too many symbolic links";
-      break;
-#endif
-#ifdef EOPNOTSUPP
-    case EOPNOTSUPP:
-      error = "Operation not supported on transport endpoint";
-      break;
-#endif
-#ifdef EPFNOSUPPORT
-    case EPFNOSUPPORT:
-      error = "Protocol family not supported";
-      break;
-#endif
-#ifdef ECONNRESET
-    case ECONNRESET:
-      error = "Connection reset by peer";
-      break;
-#endif
-#ifdef ENOBUFS
-    case ENOBUFS:
-      error = "No buffer space available";
-      break;
-#endif
-#ifdef EAFNOSUPPORT
-    case EAFNOSUPPORT:
-      error = "Address family not supported by protocol family";
-      break;
-#endif
-#ifdef EPROTOTYPE
-    case EPROTOTYPE:
-      error = "Protocol wrong type for socket";
-      break;
-#endif
-#ifdef ENOTSOCK
-    case ENOTSOCK:
-      error = "Socket operation on non-socket";
-      break;
-#endif
-#ifdef ENOPROTOOPT
-    case ENOPROTOOPT:
-      error = "Protocol not available";
-      break;
-#endif
-#ifdef ESHUTDOWN
-    case ESHUTDOWN:
-      error = "Can't send after socket shutdown";
-      break;
-#endif
-#ifdef ECONNREFUSED
-    case ECONNREFUSED:
-      error = "Connection refused";
-      break;
-#endif
-#ifdef EADDRINUSE
-    case EADDRINUSE:
-      error = "Address already in use";
-      break;
-#endif
-#ifdef ECONNABORTED
-    case ECONNABORTED:
-      error = "Connection aborted";
-      break;
-#endif
-#ifdef ENETUNREACH
-    case ENETUNREACH:
-      error = "Network is unreachable";
-      break;
-#endif
-#ifdef ENETDOWN
-    case ENETDOWN:
-      error = "Network interface is not configured";
-      break;
-#endif
-#ifdef ETIMEDOUT
-    case ETIMEDOUT:
-      error = "Connection timed out";
-      break;
-#endif
-#ifdef EHOSTDOWN
-    case EHOSTDOWN:
-      error = "Host is down";
-      break;
-#endif
-#ifdef EHOSTUNREACH
-    case EHOSTUNREACH:
-      error = "Host is unreachable";
-      break;
-#endif
-#ifdef EINPROGRESS
-    case EINPROGRESS:
-      error = "Connection already in progress";
-      break;
-#endif
-#ifdef EALREADY
-    case EALREADY:
-      error = "Socket already connected";
-      break;
-#endif
-#ifdef EDESTADDRREQ
-    case EDESTADDRREQ:
-      error = "Destination address required";
-      break;
-#endif
-#ifdef EMSGSIZE
-    case EMSGSIZE:
-      error = "Message too long";
-      break;
-#endif
-#ifdef EPROTONOSUPPORT
-    case EPROTONOSUPPORT:
-      error = "Unknown protocol";
-      break;
-#endif
-#ifdef ESOCKTNOSUPPORT
-    case ESOCKTNOSUPPORT:
-      error = "Socket type not supported";
-      break;
-#endif
-#ifdef EADDRNOTAVAIL
-    case EADDRNOTAVAIL:
-      error = "Address not available";
-      break;
-#endif
-#ifdef ENETRESET
-    case ENETRESET:
-      error = "Connection aborted by network";
-      break;
-#endif
-#ifdef EISCONN
-    case EISCONN:
-      error = "Socket is already connected";
-      break;
-#endif
-#ifdef ENOTCONN
-    case ENOTCONN:
-      error = "Socket is not connected";
-      break;
-#endif
-#ifdef ETOOMANYREFS
-    case ETOOMANYREFS:
-      error = "Too many references: cannot splice";
-      break;
-#endif
-#ifdef EPROCLIM
-    case EPROCLIM:
-      error = "Too many processes";
-      break;
-#endif
-#ifdef EUSERS
-    case EUSERS:
-      error = "Too many users";
-      break;
-#endif
-#ifdef EDQUOT
-    case EDQUOT:
-      error = "Disk quota exceeded";
-      break;
-#endif
-#ifdef ESTALE
-    case ESTALE:
-      error = "Unknown error";
-      break;
-#endif
-#ifdef ENOTSUP
-    case ENOTSUP:
-      error = "Not supported";
-      break;
-#endif
-#ifdef ENOMEDIUM
-    case ENOMEDIUM:
-      error = "No medium (in tape drive)";
-      break;
-#endif
-#ifdef ENOSHARE
-    case ENOSHARE:
-      error = "No such host or network path";
-      break;
-#endif
-#ifdef ECASECLASH
-    case ECASECLASH:
-      error = "Filename exists with different case";
-      break;
-#endif
-    case 0:
-      error = "No error";
-      break;
-    default:
-      error = "Unknown error";
-      LOG(LOG_ERROR, " Unknown error %i in _win_strerror()\n",
-          errnum);
-      break;
-    }
-
-  return error;
-}
-
-int IsWinNT()
-{
-  return theWinVersion.dwPlatformId == VER_PLATFORM_WIN32_NT;
-}
-
 #endif /* MINGW */
 
 #if !HAVE_ATOLL

Deleted: GNUnet/src/util/win/winselect.c
===================================================================
--- GNUnet/src/util/win/winselect.c     2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/util/win/winselect.c     2005-04-29 22:30:41 UTC (rev 710)
@@ -1,245 +0,0 @@
-/*
-     This file is part of GNUnet
-
-     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.
-*/
-/**
- * Code originally written by Wez Furlong <address@hidden>
- * who originally placed it under the PHP License Version 3.0.
- * Adapted for GNUnet by Nils Durner <address@hidden>.
- * GPLed with permission from Wez Furlong (see E-mail on
- * gnunet-developers, also quoted in the CVS logs).
- *
- * @file util/winselect.c
- * @brief select implementation for Win32
- * @author Wez Furlong <address@hidden>
- * @author Nils Durner (GNUnet extensions)
- */
-
-#include "platform.h"
-
-/**
- * Win32 select() will only work with sockets, so we roll our own
- * implementation here.
- * - If you supply only sockets, this simply passes through to winsock 
select().
- * - If you supply file handles, there is no way to distinguish between
- *   ready for read/write or OOB, so any set in which the handle is found will
- *   be marked as ready.
- * - If you supply a mixture of handles and sockets, the system will interleave
- *   calls between select() and WaitForMultipleObjects(). The time slicing may
- *   cause this function call to take up to 100 ms longer than you specified.
- * - Pipes are not checked for writability or errors (errno = ENOSYS)
- */
-int _win_select(int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds,
-                const struct timeval *tv)
-{
-  DWORD ms_total, limit;
-  HANDLE handles[MAXIMUM_WAIT_OBJECTS], hPipes[MAXIMUM_WAIT_OBJECTS];
-  int handle_slot_to_fd[MAXIMUM_WAIT_OBJECTS];
-  int n_handles, i, iPipes;
-  fd_set sock_read, sock_write, sock_except;
-  fd_set aread, awrite, aexcept;
-  int sock_max_fd;
-  struct timeval tvslice;
-  int retcode;
-
-#define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set))
-
-  n_handles = 0;
-  sock_max_fd = -1;
-  iPipes = 0;
-
-  /* calculate how long we need to wait in milliseconds */
-  if(tv == NULL)
-    ms_total = INFINITE;
-  else
-  {
-    ms_total = tv->tv_sec * 1000;
-    ms_total += tv->tv_usec / 1000;
-  }
-
-  /* select() may be used as a portable way to sleep */
-  if (!(rfds || wfds || efds))
-  {
-    Sleep(ms_total);
-
-    return 0;
-  }
-
-  FD_ZERO(&sock_read);
-  FD_ZERO(&sock_write);
-  FD_ZERO(&sock_except);
-
-  /* build an array of handles for non-sockets */
-  for(i = 0; i < max_fd; i++)
-  {
-    if(SAFE_FD_ISSET(i, rfds) || SAFE_FD_ISSET(i, wfds) ||
-       SAFE_FD_ISSET(i, efds))
-    {
-      unsigned long ulVal;
-
-      if (ioctlsocket(i, FIONBIO, &ulVal) != SOCKET_ERROR)
-      {
-        /* socket */
-        if(SAFE_FD_ISSET(i, rfds))
-          FD_SET(i, &sock_read);
-
-        if(SAFE_FD_ISSET(i, wfds))
-          FD_SET(i, &sock_write);
-
-        if(SAFE_FD_ISSET(i, efds))
-          FD_SET(i, &sock_except);
-
-        if(i > sock_max_fd)
-          sock_max_fd = i;
-      }
-      else
-      {
-        if (GetFileType((HANDLE) i) == FILE_TYPE_PIPE)
-          hPipes[iPipes++] = (HANDLE) i;  /* Pipe */
-        else
-        {
-          handles[n_handles] = (HANDLE) _get_osfhandle(i);
-          if ((DWORD) handles[n_handles] == 0xffffffff)
-            handles[n_handles] = (HANDLE) i;
-          handle_slot_to_fd[n_handles] = i;
-          n_handles++;
-        }
-      }
-    }
-  }
-
-  if((n_handles == 0) && (iPipes == 0))
-  {
-    /* plain sockets only - let winsock handle the whole thing */
-    return select(max_fd, rfds, wfds, efds, tv);
-  }
-
-  /* mixture of handles and sockets; lets multiplex between
-   * winsock and waiting on the handles */
-
-  FD_ZERO(&aread);
-  FD_ZERO(&awrite);
-  FD_ZERO(&aexcept);
-
-  limit = GetTickCount() + ms_total;
-  do
-  {
-    retcode = 0;
-
-    if(sock_max_fd >= 0)
-    {
-      /* overwrite the zero'd sets here; the select call
-       * will clear those that are not active */
-      aread = sock_read;
-      awrite = sock_write;
-      aexcept = sock_except;
-
-      tvslice.tv_sec = 0;
-      tvslice.tv_usec = 100000;
-
-      if ((retcode = select(sock_max_fd + 1, &aread, &awrite, &aexcept,
-                            &tvslice)) == SOCKET_ERROR)
-      {
-        SetErrnoFromWinsockError(WSAGetLastError());
-
-        return -1;
-      }
-    }
-
-    if(n_handles > 0)
-    {
-      /* check handles */
-      DWORD wret;
-
-      wret =
-        MsgWaitForMultipleObjects(n_handles, handles, FALSE,
-                                  retcode > 0 ? 0 : 100, QS_ALLEVENTS);
-
-      if(wret == WAIT_TIMEOUT)
-      {
-        /* set retcode to 0; this is the default.
-         * select() may have set it to something else,
-         * in which case we leave it alone, so this branch
-         * does nothing */
-        ;
-      }
-      else if(wret == WAIT_FAILED)
-      {
-        SetErrnoFromWinError(GetLastError());
-
-        return -1;
-      }
-      else
-      {
-        for(i = 0; i < n_handles; i++)
-        {
-          if(WAIT_OBJECT_0 == WaitForSingleObject(handles[i], 0))
-          {
-            if(SAFE_FD_ISSET(handle_slot_to_fd[i], rfds))
-            {
-              FD_SET(handle_slot_to_fd[i], &aread);
-            }
-
-            if(SAFE_FD_ISSET(handle_slot_to_fd[i], wfds))
-              FD_SET(handle_slot_to_fd[i], &awrite);
-
-            if(SAFE_FD_ISSET(handle_slot_to_fd[i], efds))
-              FD_SET(handle_slot_to_fd[i], &aexcept);
-
-            retcode++;
-          }
-        }
-      }
-    }
-
-    /* Poll Pipes */
-    for(i = 0; i < iPipes; i++)
-    {
-      DWORD dwBytes;
-      if(SAFE_FD_ISSET(hPipes[i], rfds))
-      {
-           if (! PeekNamedPipe(hPipes[i], NULL, 0, NULL, &dwBytes, NULL))
-           {
-             retcode = -1;
-             SetErrnoFromWinError(GetLastError());
-           }
-           else if (dwBytes)
-           {
-             FD_SET((int) hPipes[i], &aread);
-             retcode++;
-           }
-      }
-      else if (SAFE_FD_ISSET(hPipes[i], wfds) || SAFE_FD_ISSET(hPipes[i], 
efds))
-      {
-        errno = ENOSYS;
-        return -1;  /* Not implemented */
-      }
-    }
-  }
-  while(retcode == 0 && (ms_total == INFINITE || GetTickCount() < limit));
-
-  if(rfds)
-    *rfds = aread;
-
-  if(wfds)
-    *wfds = awrite;
-
-  if(efds)
-    *efds = aexcept;
-
-  return retcode;
-}

Deleted: GNUnet/src/util/win/winstrptime.c
===================================================================
--- GNUnet/src/util/win/winstrptime.c   2005-04-28 20:50:54 UTC (rev 709)
+++ GNUnet/src/util/win/winstrptime.c   2005-04-29 22:30:41 UTC (rev 710)
@@ -1,563 +0,0 @@
-/* Convert a string representation of time to a time value.
-   Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <address@hidden>, 1996.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
-
-   The GNU C 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
-   Library General Public License for more details.
-
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
-
-/* This is a slightly modified version by the
-   "R Project" <http://www.r-project.org/> with locale support removed. */
-
-void get_locale_strings(void);
-
-/* XXX This version of the implementation is not really complete.
-   Some of the fields cannot add information alone.  But if seeing
-   some of them in the same format (such as year, week and weekday)
-   this is enough information for determining the date.  */
-
-#include <ctype.h>
-#include <limits.h>
-#include <string.h>
-#include <time.h>
-
-#define match_char(ch1, ch2) if (ch1 != ch2) return NULL
-
-#ifndef Macintosh
-#if defined __GNUC__ && __GNUC__ >= 2
-# define match_string(cs1, s2) \
-  ({ size_t len = strlen (cs1);                                                
      \
-     int result = strncasecmp ((cs1), (s2), len) == 0;                       \
-     if (result) (s2) += len;                                                \
-     result; })
-#else
-/* Oh come on.  Get a reasonable compiler.  */
-# define match_string(cs1, s2) \
-  (strncasecmp ((cs1), (s2), strlen (cs1)) ? 0 : ((s2) += strlen (cs1), 1))
-#endif
-#else
-# define match_string(cs1, s2) \
-  (strncmp ((cs1), (s2), strlen (cs1)) ? 0 : ((s2) += strlen (cs1), 1))
-#endif /* mac */
-
-/* We intentionally do not use isdigit() for testing because this will
-   lead to problems with the wide character version.  */
-#define get_number(from, to, n) \
-  do {                                                                       \
-    int __n = n;                                                             \
-    val = 0;                                                                 \
-    while (*rp == ' ')                                                       \
-      ++rp;                                                                  \
-    if (*rp < '0' || *rp > '9')                                                
      \
-      return NULL;                                                           \
-    do {                                                                     \
-      val *= 10;                                                             \
-      val += *rp++ - '0';                                                    \
-    } while (--__n > 0 && val * 10 <= to && *rp >= '0' && *rp <= '9');       \
-    if (val < from || val > to)                                                
      \
-      return NULL;                                                           \
-  } while (0)
-# define get_alt_number(from, to, n) \
-  /* We don't have the alternate representation.  */                         \
-  get_number(from, to, n)
-#define recursive(new_fmt) \
-  (*(new_fmt) != '\0'                                                        \
-   && (rp = strptime_internal (rp, (new_fmt), tm, decided)) != NULL)
-
-/* This version: may overwrite these with versions for the locale */
-static char weekday_name[][20] =
-{
-    "Sunday", "Monday", "Tuesday", "Wednesday",
-    "Thursday", "Friday", "Saturday"
-};
-static char ab_weekday_name[][10] =
-{
-    "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
-};
-static char month_name[][20] =
-{
-    "January", "February", "March", "April", "May", "June",
-    "July", "August", "September", "October", "November", "December"
-};
-static char ab_month_name[][10] =
-{
-    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
-
-static char am_pm[][4] = {"AM", "PM"};
-
-
-# define HERE_D_T_FMT "%a %b %e %H:%M:%S %Y"
-# define HERE_D_FMT "%y/%m/%d"
-# define HERE_T_FMT_AMPM "%I:%M:%S %p"
-# define HERE_T_FMT "%H:%M:%S"
-
-static const unsigned short int __mon_yday[2][13] =
-{
-    /* Normal years.  */
-    { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
-    /* Leap years.  */
-    { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
-};
-
-
-/* Status of lookup: do we use the locale data or the raw data?  */
-enum locale_status { not, loc, raw };
-
-# define __isleap(year)        \
-  ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
-
-/* Compute the day of the week.  */
-void
-day_of_the_week (struct tm *tm)
-{
-    /* We know that January 1st 1970 was a Thursday (= 4).  Compute the
-       the difference between this data in the one on TM and so determine
-       the weekday.  */
-    int corr_year = 1900 + tm->tm_year - (tm->tm_mon < 2);
-    int wday = (-473
-               + (365 * (tm->tm_year - 70))
-               + (corr_year / 4)
-               - ((corr_year / 4) / 25) + ((corr_year / 4) % 25 < 0)
-               + (((corr_year / 4) / 25) / 4)
-               + __mon_yday[0][tm->tm_mon]
-               + tm->tm_mday - 1);
-    tm->tm_wday = ((wday % 7) + 7) % 7;
-}
-
-/* Compute the day of the year.  */
-void
-day_of_the_year (struct tm *tm)
-{
-    tm->tm_yday = (__mon_yday[__isleap (1900 + tm->tm_year)][tm->tm_mon]
-                  + (tm->tm_mday - 1));
-}
-
-char *
-strptime_internal (const char *rp, const char *fmt, struct tm *tm,
-                  enum locale_status *decided)
-{
-    const char *rp_backup;
-    int cnt;
-    size_t val;
-    int have_I, is_pm;
-    int century, want_century;
-    int have_wday, want_xday;
-    int have_yday;
-    int have_mon, have_mday;
-
-    have_I = is_pm = 0;
-    century = -1;
-    want_century = 0;
-    have_wday = want_xday = have_yday = have_mon = have_mday = 0;
-
-    while (*fmt != '\0')
-    {
-       /* A white space in the format string matches 0 more or white
-          space in the input string.  */
-       if (isspace (*fmt))
-       {
-           while (isspace (*rp))
-               ++rp;
-           ++fmt;
-           continue;
-       }
-
-       /* Any character but `%' must be matched by the same character
-          in the iput string.  */
-       if (*fmt != '%')
-       {
-           match_char (*fmt++, *rp++);
-           continue;
-       }
-
-       ++fmt;
-
-       /* We need this for handling the `E' modifier.  */
-    start_over:
-
-        /* Make back up of current processing pointer.  */
-       rp_backup = rp;
-
-       switch (*fmt++)
-       {
-       case '%':
-           /* Match the `%' character itself.  */
-           match_char ('%', *rp++);
-           break;
-       case 'a':
-       case 'A':
-           /* Match day of week.  */
-           for (cnt = 0; cnt < 7; ++cnt)
-           {
-               if (*decided != loc
-                   && (match_string (weekday_name[cnt], rp)
-                       || match_string (ab_weekday_name[cnt], rp)))
-               {
-                   *decided = raw;
-                   break;
-               }
-           }
-           if (cnt == 7)
-               /* Does not match a weekday name.  */
-               return NULL;
-           tm->tm_wday = cnt;
-           have_wday = 1;
-           break;
-       case 'b':
-       case 'B':
-       case 'h':
-           /* Match month name.  */
-           for (cnt = 0; cnt < 12; ++cnt)
-           {
-               if (match_string (month_name[cnt], rp)
-                   || match_string (ab_month_name[cnt], rp))
-               {
-                   *decided = raw;
-                   break;
-               }
-           }
-           if (cnt == 12)
-               /* Does not match a month name.  */
-               return NULL;
-           tm->tm_mon = cnt;
-           want_xday = 1;
-           break;
-       case 'c':
-           /* Match locale's date and time format.  */
-           if (!recursive (HERE_T_FMT_AMPM))
-               return NULL;
-           break;
-       case 'C':
-         /* Match century number.  */
-         get_number (0, 99, 2);
-         century = val;
-         want_xday = 1;
-         break;
-       case 'd':
-       case 'e':
-         /* Match day of month.  */
-         get_number (1, 31, 2);
-         tm->tm_mday = val;
-         have_mday = 1;
-         want_xday = 1;
-         break;
-       case 'F':
-         if (!recursive ("%Y-%m-%d"))
-           return NULL;
-         want_xday = 1;
-         break;
-       case 'x':
-         /* Fall through.  */
-       case 'D':
-         /* Match standard day format.  */
-         if (!recursive (HERE_D_FMT))
-           return NULL;
-         want_xday = 1;
-         break;
-       case 'k':
-       case 'H':
-         /* Match hour in 24-hour clock.  */
-         get_number (0, 23, 2);
-         tm->tm_hour = val;
-         have_I = 0;
-         break;
-       case 'I':
-         /* Match hour in 12-hour clock.  */
-         get_number (1, 12, 2);
-         tm->tm_hour = val % 12;
-         have_I = 1;
-         break;
-       case 'j':
-         /* Match day number of year.  */
-         get_number (1, 366, 3);
-         tm->tm_yday = val - 1;
-         have_yday = 1;
-         break;
-       case 'm':
-         /* Match number of month.  */
-         get_number (1, 12, 2);
-         tm->tm_mon = val - 1;
-         have_mon = 1;
-         want_xday = 1;
-         break;
-       case 'M':
-         /* Match minute.  */
-         get_number (0, 59, 2);
-         tm->tm_min = val;
-         break;
-       case 'n':
-       case 't':
-         /* Match any white space.  */
-         while (isspace (*rp))
-           ++rp;
-         break;
-       case 'p':
-         /* Match locale's equivalent of AM/PM.  */
-         if (!match_string (am_pm[0], rp))
-           if (match_string (am_pm[1], rp))
-             is_pm = 1;
-           else
-             return NULL;
-         break;
-       case 'r':
-         if (!recursive (HERE_T_FMT_AMPM))
-           return NULL;
-         break;
-       case 'R':
-           if (!recursive ("%H:%M"))
-               return NULL;
-           break;
-       case 's':
-       {
-           /* The number of seconds may be very high so we cannot use
-              the `get_number' macro.  Instead read the number
-              character for character and construct the result while
-              doing this.  */
-           time_t secs = 0;
-           if (*rp < '0' || *rp > '9')
-               /* We need at least one digit.  */
-               return NULL;
-
-           do
-           {
-               secs *= 10;
-               secs += *rp++ - '0';
-           }
-           while (*rp >= '0' && *rp <= '9');
-
-           if ((tm = localtime (&secs)) == NULL)
-               /* Error in function.  */
-               return NULL;
-       }
-       break;
-       case 'S':
-           get_number (0, 61, 2);
-           tm->tm_sec = val;
-           break;
-       case 'X':
-           /* Fall through.  */
-       case 'T':
-           if (!recursive (HERE_T_FMT))
-               return NULL;
-           break;
-       case 'u':
-           get_number (1, 7, 1);
-           tm->tm_wday = val % 7;
-           have_wday = 1;
-           break;
-       case 'g':
-           get_number (0, 99, 2);
-           /* XXX This cannot determine any field in TM.  */
-           break;
-       case 'G':
-           if (*rp < '0' || *rp > '9')
-               return NULL;
-           /* XXX Ignore the number since we would need some more
-              information to compute a real date.  */
-           do
-               ++rp;
-           while (*rp >= '0' && *rp <= '9');
-           break;
-       case 'U':
-       case 'V':
-       case 'W':
-           get_number (0, 53, 2);
-           /* XXX This cannot determine any field in TM without some
-              information.  */
-           break;
-       case 'w':
-           /* Match number of weekday.  */
-           get_number (0, 6, 1);
-           tm->tm_wday = val;
-           have_wday = 1;
-           break;
-       case 'y':
-           /* Match year within century.  */
-           get_number (0, 99, 2);
-           /* The "Year 2000: The Millennium Rollover" paper suggests that
-              values in the range 69-99 refer to the twentieth century.  */
-           tm->tm_year = val >= 69 ? val : val + 100;
-           /* Indicate that we want to use the century, if specified.  */
-           want_century = 1;
-           want_xday = 1;
-           break;
-       case 'Y':
-           /* Match year including century number.  */
-           get_number (0, 9999, 4);
-           tm->tm_year = val - 1900;
-           want_century = 0;
-           want_xday = 1;
-           break;
-       case 'Z':
-           /* XXX How to handle this?  */
-           break;
-       case 'E':
-           /* We have no information about the era format.  Just use
-              the normal format.  */
-           if (*fmt != 'c' && *fmt != 'C' && *fmt != 'y' && *fmt != 'Y'
-               && *fmt != 'x' && *fmt != 'X')
-               /* This is an invalid format.  */
-               return NULL;
-
-           goto start_over;
-       case 'O':
-           switch (*fmt++)
-           {
-           case 'd':
-           case 'e':
-               /* Match day of month using alternate numeric symbols.  */
-               get_alt_number (1, 31, 2);
-               tm->tm_mday = val;
-               have_mday = 1;
-               want_xday = 1;
-               break;
-           case 'H':
-               /* Match hour in 24-hour clock using alternate numeric
-                  symbols.  */
-               get_alt_number (0, 23, 2);
-               tm->tm_hour = val;
-               have_I = 0;
-               break;
-           case 'I':
-               /* Match hour in 12-hour clock using alternate numeric
-                  symbols.  */
-               get_alt_number (1, 12, 2);
-               tm->tm_hour = val - 1;
-               have_I = 1;
-               break;
-           case 'm':
-               /* Match month using alternate numeric symbols.  */
-               get_alt_number (1, 12, 2);
-               tm->tm_mon = val - 1;
-               have_mon = 1;
-               want_xday = 1;
-               break;
-           case 'M':
-               /* Match minutes using alternate numeric symbols.  */
-               get_alt_number (0, 59, 2);
-               tm->tm_min = val;
-               break;
-           case 'S':
-               /* Match seconds using alternate numeric symbols.  */
-               get_alt_number (0, 61, 2);
-               tm->tm_sec = val;
-               break;
-           case 'U':
-           case 'V':
-           case 'W':
-               get_alt_number (0, 53, 2);
-               /* XXX This cannot determine any field in TM without
-                  further information.  */
-               break;
-           case 'w':
-               /* Match number of weekday using alternate numeric symbols.  */
-               get_alt_number (0, 6, 1);
-               tm->tm_wday = val;
-               have_wday = 1;
-               break;
-           case 'y':
-               /* Match year within century using alternate numeric symbols.  
*/
-               get_alt_number (0, 99, 2);
-               tm->tm_year = val >= 69 ? val : val + 100;
-               want_xday = 1;
-               break;
-           default:
-               return NULL;
-           }
-           break;
-       default:
-           return NULL;
-       }
-    }
-
-    if (have_I && is_pm)
-       tm->tm_hour += 12;
-
-    if (century != -1)
-    {
-       if (want_century)
-           tm->tm_year = tm->tm_year % 100 + (century - 19) * 100;
-       else
-           /* Only the century, but not the year.  Strange, but so be it.  */
-           tm->tm_year = (century - 19) * 100;
-    }
-
-    if (want_xday && !have_wday) {
-       if ( !(have_mon && have_mday) && have_yday)  {
-           /* we don't have tm_mon and/or tm_mday, compute them */
-           int t_mon = 0;
-           while (__mon_yday[__isleap(1900 + tm->tm_year)][t_mon] <= 
tm->tm_yday)
-               t_mon++;
-           if (!have_mon)
-               tm->tm_mon = t_mon - 1;
-           if (!have_mday)
-               tm->tm_mday = tm->tm_yday - __mon_yday[__isleap(1900 + 
tm->tm_year)][t_mon - 1] + 1;
-       }
-       day_of_the_week (tm);
-    }
-    if (want_xday && !have_yday)
-       day_of_the_year (tm);
-
-    return (char *) rp;
-}
-
-char *
-strptime (const char *buf, const char *format, struct tm *tm)
-{
-    enum locale_status decided;
-#ifdef HAVE_LOCALE_H
-    if(!have_used_strptime) {
-       get_locale_strings();
-       /* have_used_strptime = 1; might change locale during session */
-    }
-#endif
-    decided = raw;
-    return strptime_internal (buf, format, tm, &decided);
-}
-
-#ifdef HAVE_LOCALE_H
-void get_locale_strings(void)
-{
-    int i;
-    struct tm tm;
-    char buff[4];
-
-    tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon
-       = tm.tm_isdst = 0;
-    tm.tm_year = 30;
-    for(i = 0; i < 12; i++) {
-       tm.tm_mon = i;
-       strftime(ab_month_name[i], 10, "%b", &tm);
-       strftime(month_name[i], 20, "%B", &tm);
-    }
-    tm.tm_mon = 0;
-    for(i = 0; i < 7; i++) {
-       tm.tm_mday = tm.tm_yday = i+1; /* 2000-1-2 was a Sunday */
-       tm.tm_wday = i;
-       strftime(ab_weekday_name[i], 10, "%a", &tm);
-       strftime(weekday_name[i], 20, "%A", &tm);
-    }
-    tm.tm_hour = 1;
-    /* in locales where these are unused, they may be empty: better
-       not to reset them then */
-    strftime(buff, 4, "%p", &tm);
-    if(strlen(buff)) strcpy(am_pm[0], buff);
-    tm.tm_hour = 13;
-    strftime(buff, 4, "%p", &tm);
-    if(strlen(buff)) strcpy(am_pm[1], buff);
-}
-#endif





reply via email to

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