Index: trunk/thirds/cgic206/Makefile
===================================================================
--- trunk/thirds/cgic206/Makefile	(revision 986)
+++ trunk/thirds/cgic206/Makefile	(revision 1)
@@ -1,22 +1,15 @@
-OS:=$(shell uname -s)
-CPU:=$(shell uname -m)
-ifeq ($(OS),Darwin)
-	MACOS_CFLAGS=-arch x86_64
-	LIBS= -L./ -lcgic /usr/local/lib/libfcgi.dylib
-else
-	LIBS= -L./ -lcgic /usr/lib/libfcgi.a
-endif
-CFLAGS=-I/usr/local/include -g -Wall ${MACOS_CFLAGS}
+CFLAGS=-g -Wall
 CC=gcc
 AR=ar
 RANLIB=ranlib
+LIBS=-L./ -lcgic ../fcgi-2.4.0/libfcgi/.libs/libfcgi.a 
+CFLAGS=-I//var/www/localhost/include
 
 all: libcgic.a cgictest.cgi capture
 
 install: libcgic.a
-	mkdir -p ../../dist/lib
 	cp libcgic.a  ../../dist/lib
-	cp cgic.h  ../../dist/include
-	@echo libcgic.a is in  ../../dist/lib/ and cgic.h is in  ../../dist/include/
+	cp cgic.h  ../../dist//include
+	@echo libcgic.a is in  ../../dist/lib and cgic.h is in  ../../dist//include.
 
 libcgic.a: cgic.o cgic.h
Index: trunk/thirds/cgic206/cgic.c
===================================================================
--- trunk/thirds/cgic206/cgic.c	(revision 986)
+++ trunk/thirds/cgic206/cgic.c	(revision 1)
@@ -23,8 +23,4 @@
 #define CGICDEBUGEND
 #endif /* CGICDEBUG */
-
-#ifdef WIN32
-#define _INC_STDIO
-#endif
 
 #include <stdio.h>
@@ -72,5 +68,4 @@
 char *cgiUserAgent;
 char *cgiReferrer;
-char *cgiSid;
 
 FILE *cgiIn;
@@ -79,5 +74,4 @@
 /* True if CGI environment was restored from a file. */
 static int cgiRestored = 0;
-static int cgiTreatUrlEncoding;
 
 static void cgiGetenv(char **s, char *var);
@@ -142,17 +136,8 @@
 	cgiGetenv(&cgiServerPort, "SERVER_PORT");
 	cgiGetenv(&cgiRequestMethod, "REQUEST_METHOD");
-	if(strcmp(cgiRequestMethod,"")==0 && argc>=1)
-		cgiRequestMethod="GET";
 	cgiGetenv(&cgiPathInfo, "PATH_INFO");
 	cgiGetenv(&cgiPathTranslated, "PATH_TRANSLATED");
 	cgiGetenv(&cgiScriptName, "SCRIPT_NAME");
 	cgiGetenv(&cgiQueryString, "QUERY_STRING");
-	cgiSid=NULL;
-	if(cgiQueryString!=NULL && argc>=2){
-		cgiQueryString=argv[1];
-		if(argc>2){
-		  cgiSid=argv[2];
-		}
-	}
 	cgiGetenv(&cgiRemoteHost, "REMOTE_HOST");
 	cgiGetenv(&cgiRemoteAddr, "REMOTE_ADDR");
@@ -205,7 +190,4 @@
 	cgiGetenv(&cgiContentLengthString, "CONTENT_LENGTH");
 	cgiContentLength = atoi(cgiContentLengthString);	
-	if(cgiContentLength==0 && argc>=2){
-		cgiContentLength=strlen(argv[1]);
-	}
 	cgiGetenv(&cgiAccept, "HTTP_ACCEPT");
 	cgiGetenv(&cgiUserAgent, "HTTP_USER_AGENT");
@@ -226,6 +208,6 @@
 #endif /* WIN32 */
 	cgiFormEntryFirst = 0;
-	cgiIn = FCGI_stdin;
-	cgiOut = FCGI_stdout;
+	cgiIn = stdin;
+	cgiOut = stdout;
 	cgiRestored = 0;
 
@@ -241,7 +223,5 @@
 
 
-	cgiTreatUrlEncoding=0;
 	if (cgiStrEqNc(cgiRequestMethod, "post")) {
-		cgiTreatUrlEncoding=0;
 #ifdef CGICDEBUG
 		CGICDEBUGSTART
@@ -313,5 +293,4 @@
 	cgiFreeResources();
 	}
-	FCGI_Finish();
 	return result;
 }
@@ -1118,5 +1097,4 @@
 	while (srcPos < len) {
 		int ch = cp[srcPos];
-		if(cgiTreatUrlEncoding==1)
 		switch (escapeState) {
 			case cgiEscapeRest:
@@ -1126,5 +1104,5 @@
 				s[dstPos++] = ' ';
 			} else {
-				s[dstPos++] = ch;
+				s[dstPos++] = ch;	
 			}
 			break;
@@ -1139,6 +1117,4 @@
 			break;
 		}
-		else
-		  s[dstPos++] = ch;
 		srcPos++;
 	}
Index: trunk/thirds/cgic206/cgic.h
===================================================================
--- trunk/thirds/cgic206/cgic.h	(revision 986)
+++ trunk/thirds/cgic206/cgic.h	(revision 1)
@@ -124,10 +124,4 @@
 #endif
 char *cgiCookie;
-
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
-char *cgiSid;
 
 /* A macro providing the same incorrect spelling that is
Index: trunk/thirds/cgic206/cgic.html
===================================================================
--- trunk/thirds/cgic206/cgic.html	(revision 986)
+++ trunk/thirds/cgic206/cgic.html	(revision 1)
@@ -1630,5 +1630,5 @@
 </strong><br><dd>
 cgiHeaderLocation() should be called if the programmer wishes to
-redirect the user to a different URL. No further output
+redirect the user to a different URL. No futher output
 is needed in this case.
 <p>
Index: trunk/thirds/cgic206/cgictest.c
===================================================================
--- trunk/thirds/cgic206/cgictest.c	(revision 986)
+++ trunk/thirds/cgic206/cgictest.c	(revision 1)
@@ -23,10 +23,8 @@
 	cgiReadEnvironment("/home/boutell/public_html/capcgi.dat");
 #endif
-	dup2(cgiOut,stdout);
-	printf("Content-Type: text/html; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
-	//cgiHeaderContentType("text/html");
-	printf( "<HTML><HEAD>\n");
-	printf( "<TITLE>cgic test</TITLE></HEAD>\n");
-	printf( "<BODY><H1>cgic test</H1>\n");
+	cgiHeaderContentType("text/html");
+	fprintf(cgiOut, "<HTML><HEAD>\n");
+	fprintf(cgiOut, "<TITLE>cgic test</TITLE></HEAD>\n");
+	fprintf(cgiOut, "<BODY><H1>cgic test</H1>\n");
 	Name();
 	Address();
@@ -38,5 +36,5 @@
 	NonExButtons();
 	RadioButtons();
-	printf( "</BODY></HTML>\n");
+	fprintf(cgiOut, "</BODY></HTML>\n");
 	return 0;
 }
@@ -47,23 +45,23 @@
 	switch (result) {
 		case cgiFormSuccess:
-		printf( "Name fetched, result code: cgiFormSuccess<br>\n");
+		fprintf(cgiOut, "Name fetched, result code: cgiFormSuccess<br>\n");
 		break;
 		case cgiFormTruncated:
-		printf( "Name fetched, result code: cgiFormTruncated<br>\n");
+		fprintf(cgiOut, "Name fetched, result code: cgiFormTruncated<br>\n");
 		break;
 		case cgiFormEmpty:
-		printf( "Name fetched, result code: cgiFormEmpty<br>\n");
+		fprintf(cgiOut, "Name fetched, result code: cgiFormEmpty<br>\n");
 		break;
 		case cgiFormNotFound:
-		printf( "Name fetched, result code: cgiFormNotFound<br>\n");
+		fprintf(cgiOut, "Name fetched, result code: cgiFormNotFound<br>\n");
 		break;
 		case cgiFormMemory:
-		printf( "Name fetched, result code: cgiFormMemory<br>\n");
+		fprintf(cgiOut, "Name fetched, result code: cgiFormMemory<br>\n");
 		break;
 		default:
-		printf( "Name fetched, unexpected result code: %d\n", result);
+		fprintf(cgiOut, "Name fetched, unexpected result code: %d\n", result);
 		break;
 	}	
-	printf( "Name: %s<BR>\n", name);
+	fprintf(cgiOut, "Name: %s<BR>\n", name);
 }
 	
@@ -71,12 +69,12 @@
 	char address[241];
 	cgiFormString("address", address, 241);
-	printf( "Address: <PRE>\n%s</PRE>\n", address);
+	fprintf(cgiOut, "Address: <PRE>\n%s</PRE>\n", address);
 }
 
 void Hungry() {
 	if (cgiFormCheckboxSingle("hungry") == cgiFormSuccess) {
-		printf( "I'm Hungry!<BR>\n");
+		fprintf(cgiOut, "I'm Hungry!<BR>\n");
 	} else {
-		printf( "I'm Not Hungry!<BR>\n");
+		fprintf(cgiOut, "I'm Not Hungry!<BR>\n");
 	}
 }
@@ -85,5 +83,5 @@
 	double temperature;
 	cgiFormDoubleBounded("temperature", &temperature, 80.0, 120.0, 98.6);
-	printf( "My temperature is %f.<BR>\n", temperature);
+	fprintf(cgiOut, "My temperature is %f.<BR>\n", temperature);
 }
 	
@@ -91,5 +89,5 @@
 	int frogsEaten;
 	cgiFormInteger("frogs", &frogsEaten, 0);
-	printf( "I have eaten %d frogs.<BR>\n", frogsEaten);
+	fprintf(cgiOut, "I have eaten %d frogs.<BR>\n", frogsEaten);
 }
 
@@ -103,5 +101,5 @@
 	int colorChoice;
 	cgiFormSelectSingle("colors", colors, 3, &colorChoice, 0);
-	printf( "I am: %s<BR>\n", colors[colorChoice]);
+	fprintf(cgiOut, "I am: %s<BR>\n", colors[colorChoice]);
 }	 
 
@@ -120,14 +118,14 @@
 		flavorChoices, &invalid);
 	if (result == cgiFormNotFound) {
-		printf( "I hate ice cream.<p>\n");
+		fprintf(cgiOut, "I hate ice cream.<p>\n");
 	} else {	
-		printf( "My favorite ice cream flavors are:\n");
-		printf( "<ul>\n");
+		fprintf(cgiOut, "My favorite ice cream flavors are:\n");
+		fprintf(cgiOut, "<ul>\n");
 		for (i=0; (i < 3); i++) {
 			if (flavorChoices[i]) {
-				printf( "<li>%s\n", flavors[i]);
+				fprintf(cgiOut, "<li>%s\n", flavors[i]);
 			}
 		}
-		printf( "</ul>\n");
+		fprintf(cgiOut, "</ul>\n");
 	}
 }
@@ -148,5 +146,5 @@
 	cgiFormRadio("age", ages, 4, &ageChoice, 0);
 
-	printf( "Age of Truck: %s (method #1)<BR>\n", 
+	fprintf(cgiOut, "Age of Truck: %s (method #1)<BR>\n", 
 		ages[ageChoice]);
 
@@ -159,5 +157,5 @@
 	cgiFormString("age", ageText, 10);
 
-	printf( "Age of Truck: %s (method #2)<BR>\n", ageText);
+	fprintf(cgiOut, "Age of Truck: %s (method #2)<BR>\n", ageText);
 }
 
@@ -180,18 +178,18 @@
 		since votes for nonexistent candidates should probably
 		be discounted... */
-	printf( "Votes (method 1):<BR>\n");
+	fprintf(cgiOut, "Votes (method 1):<BR>\n");
 	result = cgiFormCheckboxMultiple("vote", votes, 4, 
 		voteChoices, &invalid);
 	if (result == cgiFormNotFound) {
-		printf( "I hate them all!<p>\n");
+		fprintf(cgiOut, "I hate them all!<p>\n");
 	} else {	
-		printf( "My preferred candidates are:\n");
-		printf( "<ul>\n");
+		fprintf(cgiOut, "My preferred candidates are:\n");
+		fprintf(cgiOut, "<ul>\n");
 		for (i=0; (i < 4); i++) {
 			if (voteChoices[i]) {
-				printf( "<li>%s\n", votes[i]);
+				fprintf(cgiOut, "<li>%s\n", votes[i]);
 			}
 		}
-		printf( "</ul>\n");
+		fprintf(cgiOut, "</ul>\n");
 	}
 
@@ -200,17 +198,17 @@
 		than the code and invented responses are not a danger
 		or can be checked in some other way. */
-	printf( "Votes (method 2):<BR>\n");
+	fprintf(cgiOut, "Votes (method 2):<BR>\n");
 	result = cgiFormStringMultiple("vote", &responses);
 	if (result == cgiFormNotFound) {	
-		printf( "I hate them all!<p>\n");
+		fprintf(cgiOut, "I hate them all!<p>\n");
 	} else {
 		int i = 0;
-		printf( "My preferred candidates are:\n");
-		printf( "<ul>\n");
+		fprintf(cgiOut, "My preferred candidates are:\n");
+		fprintf(cgiOut, "<ul>\n");
 		while (responses[i]) {
-			printf( "<li>%s\n", responses[i]);
+			fprintf(cgiOut, "<li>%s\n", responses[i]);
 			i++;
 		}
-		printf( "</ul>\n");
+		fprintf(cgiOut, "</ul>\n");
 	}
 	/* We must be sure to free the string array or a memory
Index: trunk/thirds/cgic206/makefile.vc
===================================================================
--- trunk/thirds/cgic206/makefile.vc	(revision 986)
+++ trunk/thirds/cgic206/makefile.vc	(revision 1)
@@ -1,13 +1,13 @@
-GEODIR=\MMBK\SRCS\fcgi-2.4.1-SNAP-0311112127\ 
-DESTDIR=..
+GEODIR=C:/OSGeo4W
+DESTDIR=C:\OSGeo4W
 CFLAGS=-g -Wall
 CC=cl /TP
-LIBS=$(GEODIR)/libfcgi/Release/libfcgi.lib /nologo
+LIBS=$(GEODIR)/lib/libfcgi.lib /nologo
 LIBS1=./libcgic.lib
 
-CFLAGS=/EHa /nologo /DCRT_SECURE_NO_WARNING /MD /W2 /O2 /D "WIN32" \
-	-I $(GEODIR)\include 
+CFLAGS=/EHa /nologo /DCRT_SECURE_NO_WARNING /MT /W2 /O2 /D "WIN32" \
+	-I $(GEODIR)/include 
 
-all: libcgic.lib #cgictest.exe capture.exe 
+all: libcgic.lib cgictest.exe capture.exe
 
 install: libcgic.lib
@@ -24,5 +24,5 @@
 
 cgictest.exe: cgictest.obj 
-	link cgictest.obj $(LIBS) /out:cgictest.exe
+	link cgictest.obj $(LIBS1) /out:cgictest.exe
 
 cgic.obj: 
@@ -30,5 +30,5 @@
 
 capture.exe: capture.obj libcgic.lib
-	$(CC) $(CFLAGS) capture.c $(LIBS)
+	$(CC) $(CFLAGS) capture.c $(LIBS1)
 
 clean:
Index: trunk/thirds/dirent-win32/dirent.c
===================================================================
--- trunk/thirds/dirent-win32/dirent.c	(revision 1)
+++ trunk/thirds/dirent-win32/dirent.c	(revision 1)
@@ -0,0 +1,146 @@
+/*
+
+    Implementation of POSIX directory browsing functions and types for Win32.
+
+    Author:  Kevlin Henney (kevlin@acm.org, kevlin@curbralan.com)
+    History: Created March 1997. Updated June 2003.
+    Rights:  See end of file.
+
+*/
+
+#include <dirent.h>
+#include <errno.h>
+#include <io.h> /* _findfirst and _findnext set errno iff they return -1 */
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+struct DIR
+{
+    long                handle; /* -1 for failed rewind */
+    struct _finddata_t  info;
+    struct dirent       result; /* d_name null iff first time */
+    char                *name;  /* null-terminated char string */
+};
+
+DIR *opendir(const char *name)
+{
+    DIR *dir = 0;
+
+    if(name && name[0])
+    {
+        size_t base_length = strlen(name);
+        const char *all = /* search pattern must end with suitable wildcard */
+            strchr("/\\", name[base_length - 1]) ? "*" : "/*";
+
+        if((dir = (DIR *) malloc(sizeof *dir)) != 0 &&
+           (dir->name = (char *) malloc(base_length + strlen(all) + 1)) != 0)
+        {
+            strcat(strcpy(dir->name, name), all);
+
+            if((dir->handle = (long) _findfirst(dir->name, &dir->info)) != -1)
+            {
+                dir->result.d_name = 0;
+            }
+            else /* rollback */
+            {
+                free(dir->name);
+                free(dir);
+                dir = 0;
+            }
+        }
+        else /* rollback */
+        {
+            free(dir);
+            dir   = 0;
+            errno = ENOMEM;
+        }
+    }
+    else
+    {
+        errno = EINVAL;
+    }
+
+    return dir;
+}
+
+int closedir(DIR *dir)
+{
+    int result = -1;
+
+    if(dir)
+    {
+        if(dir->handle != -1)
+        {
+            result = _findclose(dir->handle);
+        }
+
+        free(dir->name);
+        free(dir);
+    }
+
+    if(result == -1) /* map all errors to EBADF */
+    {
+        errno = EBADF;
+    }
+
+    return result;
+}
+
+struct dirent *readdir(DIR *dir)
+{
+    struct dirent *result = 0;
+
+    if(dir && dir->handle != -1)
+    {
+        if(!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1)
+        {
+            result         = &dir->result;
+            result->d_name = dir->info.name;
+        }
+    }
+    else
+    {
+        errno = EBADF;
+    }
+
+    return result;
+}
+
+void rewinddir(DIR *dir)
+{
+    if(dir && dir->handle != -1)
+    {
+        _findclose(dir->handle);
+        dir->handle = (long) _findfirst(dir->name, &dir->info);
+        dir->result.d_name = 0;
+    }
+    else
+    {
+        errno = EBADF;
+    }
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+/*
+
+    Copyright Kevlin Henney, 1997, 2003. All rights reserved.
+
+    Permission to use, copy, modify, and distribute this software and its
+    documentation for any purpose is hereby granted without fee, provided
+    that this copyright and permissions notice appear in all copies and
+    derivatives.
+    
+    This software is supplied "as is" without express or implied warranty.
+
+    But that said, if there are any problems please get in touch.
+
+*/
+
Index: trunk/thirds/dirent-win32/dirent.h
===================================================================
--- trunk/thirds/dirent-win32/dirent.h	(revision 986)
+++ trunk/thirds/dirent-win32/dirent.h	(revision 1)
@@ -1,373 +1,50 @@
-/*****************************************************************************
- * dirent.h - dirent API for Microsoft Visual Studio
- *
- * Copyright (C) 2006 Toni Ronkko
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * ``Software''), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Mar 15, 2011, Toni Ronkko
- * Defined FILE_ATTRIBUTE_DEVICE for MSVC 6.0.
- *
- * Aug 11, 2010, Toni Ronkko
- * Added d_type and d_namlen fields to dirent structure.  The former is
- * especially useful for determining whether directory entry represents a
- * file or a directory.  For more information, see
- * http://www.delorie.com/gnu/docs/glibc/libc_270.html
- *
- * Aug 11, 2010, Toni Ronkko
- * Improved conformance to the standards.  For example, errno is now set
- * properly on failure and assert() is never used.  Thanks to Peter Brockam
- * for suggestions.
- *
- * Aug 11, 2010, Toni Ronkko
- * Fixed a bug in rewinddir(): when using relative directory names, change
- * of working directory no longer causes rewinddir() to fail.
- *
- * Dec 15, 2009, John Cunningham
- * Added rewinddir member function
- *
- * Jan 18, 2008, Toni Ronkko
- * Using FindFirstFileA and WIN32_FIND_DATAA to avoid converting string
- * between multi-byte and unicode representations.  This makes the
- * code simpler and also allows the code to be compiled under MingW.  Thanks
- * to Azriel Fasten for the suggestion.
- *
- * Mar 4, 2007, Toni Ronkko
- * Bug fix: due to the strncpy_s() function this file only compiled in
- * Visual Studio 2005.  Using the new string functions only when the
- * compiler version allows.
- *
- * Nov  2, 2006, Toni Ronkko
- * Major update: removed support for Watcom C, MS-DOS and Turbo C to
- * simplify the file, updated the code to compile cleanly on Visual
- * Studio 2005 with both unicode and multi-byte character strings,
- * removed rewinddir() as it had a bug.
- *
- * Aug 20, 2006, Toni Ronkko
- * Removed all remarks about MSVC 1.0, which is antiqued now.  Simplified
- * comments by removing SGML tags.
- *
- * May 14 2002, Toni Ronkko
- * Embedded the function definitions directly to the header so that no
- * source modules need to be included in the Visual Studio project.  Removed
- * all the dependencies to other projects so that this very header can be
- * used independently.
- *
- * May 28 1998, Toni Ronkko
- * First version.
- *****************************************************************************/
-#ifndef DIRENT_H
-#define DIRENT_H
+#ifndef DIRENT_INCLUDED
+#define DIRENT_INCLUDED
 
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
+/*
 
-/* Entries missing from MSVC 6.0 */
-#if !defined(FILE_ATTRIBUTE_DEVICE)
-# define FILE_ATTRIBUTE_DEVICE 0x40
+    Declaration of POSIX directory browsing functions and types for Win32.
+
+    Author:  Kevlin Henney (kevlin@acm.org, kevlin@curbralan.com)
+    History: Created March 1997. Updated June 2003.
+    Rights:  See end of file.
+    
+*/
+
+#ifdef __cplusplus
+extern "C"
+{
 #endif
 
-/* File type and permission flags for stat() */
-#if defined(_MSC_VER)  &&  !defined(S_IREAD)
-# define S_IFMT   _S_IFMT                      /* file type mask */
-# define S_IFDIR  _S_IFDIR                     /* directory */
-# define S_IFCHR  _S_IFCHR                     /* character device */
-# define S_IFFIFO _S_IFFIFO                    /* pipe */
-# define S_IFREG  _S_IFREG                     /* regular file */
-# define S_IREAD  _S_IREAD                     /* read permission */
-# define S_IWRITE _S_IWRITE                    /* write permission */
-# define S_IEXEC  _S_IEXEC                     /* execute permission */
-#endif
-#define S_IFBLK   0                            /* block device */
-#define S_IFLNK   0                            /* link */
-#define S_IFSOCK  0                            /* socket */
+typedef struct DIR DIR;
 
-#if defined(_MSC_VER)
-# define S_IRUSR  S_IREAD                      /* read, user */
-# define S_IWUSR  S_IWRITE                     /* write, user */
-# define S_IXUSR  0                            /* execute, user */
-# define S_IRGRP  0                            /* read, group */
-# define S_IWGRP  0                            /* write, group */
-# define S_IXGRP  0                            /* execute, group */
-# define S_IROTH  0                            /* read, others */
-# define S_IWOTH  0                            /* write, others */
-# define S_IXOTH  0                            /* execute, others */
-#endif
+struct dirent
+{
+    char *d_name;
+};
 
-/* Indicates that d_type field is available in dirent structure */
-#define _DIRENT_HAVE_D_TYPE
-
-/* File type flags for d_type */
-#define DT_LNK -100
-#define DT_UNKNOWN  0
-#define DT_REG      S_IFREG
-#define DT_DIR      S_IFDIR
-#define DT_FIFO     S_IFFIFO
-#define DT_SOCK     S_IFSOCK
-#define DT_CHR      S_IFCHR
-#define DT_BLK      S_IFBLK
-
-/* Macros for converting between st_mode and d_type */
-#define IFTODT(mode) ((mode) & S_IFMT)
-#define DTTOIF(type) (type)
+DIR           *opendir(const char *);
+int           closedir(DIR *);
+struct dirent *readdir(DIR *);
+void          rewinddir(DIR *);
 
 /*
- * File type macros.  Note that block devices, sockets and links cannot be
- * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are
- * only defined for compatibility.  These macros should always return false
- * on Windows.
- */
-#define	S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFFIFO)
-#define	S_ISDIR(mode)  (((mode) & S_IFMT) == S_IFDIR)
-#define	S_ISREG(mode)  (((mode) & S_IFMT) == S_IFREG)
-#define	S_ISLNK(mode)  (((mode) & S_IFMT) == S_IFLNK)
-#define	S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
-#define	S_ISCHR(mode)  (((mode) & S_IFMT) == S_IFCHR)
-#define	S_ISBLK(mode)  (((mode) & S_IFMT) == S_IFBLK)
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+    Copyright Kevlin Henney, 1997, 2003. All rights reserved.
 
+    Permission to use, copy, modify, and distribute this software and its
+    documentation for any purpose is hereby granted without fee, provided
+    that this copyright and permissions notice appear in all copies and
+    derivatives.
+    
+    This software is supplied "as is" without express or implied warranty.
 
-typedef struct dirent
-{
-   char d_name[MAX_PATH + 1];                  /* File name */
-   size_t d_namlen;                            /* Length of name without \0 */
-   int d_type;                                 /* File type */
-} dirent;
+    But that said, if there are any problems please get in touch.
 
-
-typedef struct DIR
-{
-   dirent           curentry;                  /* Current directory entry */
-   WIN32_FIND_DATAA find_data;                 /* Private file data */
-   int              cached;                    /* True if data is valid */
-   HANDLE           search_handle;             /* Win32 search handle */
-   char             patt[MAX_PATH + 3];        /* Initial directory name */
-} DIR;
-
-
-/* Forward declarations */
-static DIR *opendir(const char *dirname);
-static struct dirent *readdir(DIR *dirp);
-static int closedir(DIR *dirp);
-static void rewinddir(DIR* dirp);
-
-
-/* Use the new safe string functions introduced in Visual Studio 2005 */
-#if defined(_MSC_VER) && _MSC_VER >= 1400
-# define DIRENT_STRNCPY(dest,src,size) strncpy_s((dest),(size),(src),_TRUNCATE)
-#else
-# define DIRENT_STRNCPY(dest,src,size) strncpy((dest),(src),(size))
-#endif
-
-/* Set errno variable */
-#if defined(_MSC_VER)
-#define DIRENT_SET_ERRNO(x) _set_errno (x)
-#else
-#define DIRENT_SET_ERRNO(x) (errno = (x))
-#endif
-
-
-
-/*****************************************************************************
- * Open directory stream DIRNAME for read and return a pointer to the
- * internal working area that is used to retrieve individual directory
- * entries.
- */
-static DIR *opendir(const char *dirname)
-{
-   DIR *dirp;
-
-   /* ensure that the resulting search pattern will be a valid file name */
-   if (dirname == NULL) {
-      DIRENT_SET_ERRNO (ENOENT);
-      return NULL;
-   }
-   if (strlen (dirname) + 3 >= MAX_PATH) {
-      DIRENT_SET_ERRNO (ENAMETOOLONG);
-      return NULL;
-   }
-
-   /* construct new DIR structure */
-   dirp = (DIR*) malloc (sizeof (struct DIR));
-   if (dirp != NULL) {
-      int error;
-
-      /*
-       * Convert relative directory name to an absolute one.  This
-       * allows rewinddir() to function correctly when the current working
-       * directory is changed between opendir() and rewinddir().
-       */
-      if (GetFullPathNameA (dirname, MAX_PATH, dirp->patt, NULL)) {
-         char *p;
-
-         /* append the search pattern "\\*\0" to the directory name */
-         p = strchr (dirp->patt, '\0');
-         if (dirp->patt < p  &&  *(p-1) != '\\'  &&  *(p-1) != ':') {
-           *p++ = '\\';
-         }
-         *p++ = '*';
-         *p = '\0';
-
-         /* open directory stream and retrieve the first entry */
-         dirp->search_handle = FindFirstFileA (dirp->patt, &dirp->find_data);
-         if (dirp->search_handle != INVALID_HANDLE_VALUE) {
-            /* a directory entry is now waiting in memory */
-            dirp->cached = 1;
-            error = 0;
-         } else {
-            /* search pattern is not a directory name? */
-            DIRENT_SET_ERRNO (ENOENT);
-            error = 1;
-         }
-      } else {
-         /* buffer too small */
-         DIRENT_SET_ERRNO (ENOMEM);
-         error = 1;
-      }
-
-      if (error) {
-         free (dirp);
-         dirp = NULL;
-      }
-   }
-
-   return dirp;
-}
-
-
-/*****************************************************************************
- * Read a directory entry, and return a pointer to a dirent structure
- * containing the name of the entry in d_name field.  Individual directory
- * entries returned by this very function include regular files,
- * sub-directories, pseudo-directories "." and "..", but also volume labels,
- * hidden files and system files may be returned.
- */
-static struct dirent *readdir(DIR *dirp)
-{
-   DWORD attr;
-   if (dirp == NULL) {
-      /* directory stream did not open */
-      DIRENT_SET_ERRNO (EBADF);
-      return NULL;
-   }
-
-   /* get next directory entry */
-   if (dirp->cached != 0) {
-      /* a valid directory entry already in memory */
-      dirp->cached = 0;
-   } else {
-      /* get the next directory entry from stream */
-      if (dirp->search_handle == INVALID_HANDLE_VALUE) {
-         return NULL;
-      }
-      if (FindNextFileA (dirp->search_handle, &dirp->find_data) == FALSE) {
-         /* the very last entry has been processed or an error occurred */
-         FindClose (dirp->search_handle);
-         dirp->search_handle = INVALID_HANDLE_VALUE;
-         return NULL;
-      }
-   }
-
-   /* copy as a multibyte character string */
-   DIRENT_STRNCPY ( dirp->curentry.d_name,
-             dirp->find_data.cFileName,
-             sizeof(dirp->curentry.d_name) );
-   dirp->curentry.d_name[MAX_PATH] = '\0';
-
-   /* compute the length of name */
-   dirp->curentry.d_namlen = strlen (dirp->curentry.d_name);
-
-   /* determine file type */
-   attr = dirp->find_data.dwFileAttributes;
-   if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) {
-      dirp->curentry.d_type = DT_CHR;
-   } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
-      dirp->curentry.d_type = DT_DIR;
-   } else {
-      dirp->curentry.d_type = DT_REG;
-   }
-   return &dirp->curentry;
-}
-
-
-/*****************************************************************************
- * Close directory stream opened by opendir() function.  Close of the
- * directory stream invalidates the DIR structure as well as any previously
- * read directory entry.
- */
-static int closedir(DIR *dirp)
-{
-   if (dirp == NULL) {
-      /* invalid directory stream */
-      DIRENT_SET_ERRNO (EBADF);
-      return -1;
-   }
-
-   /* release search handle */
-   if (dirp->search_handle != INVALID_HANDLE_VALUE) {
-      FindClose (dirp->search_handle);
-      dirp->search_handle = INVALID_HANDLE_VALUE;
-   }
-
-   /* release directory structure */
-   free (dirp);
-   return 0;
-}
-
-
-/*****************************************************************************
- * Resets the position of the directory stream to which dirp refers to the
- * beginning of the directory.  It also causes the directory stream to refer
- * to the current state of the corresponding directory, as a call to opendir()
- * would have done.  If dirp does not refer to a directory stream, the effect
- * is undefined.
- */
-static void rewinddir(DIR* dirp)
-{
-   if (dirp != NULL) {
-      /* release search handle */
-      if (dirp->search_handle != INVALID_HANDLE_VALUE) {
-         FindClose (dirp->search_handle);
-      }
-
-      /* open new search handle and retrieve the first entry */
-      dirp->search_handle = FindFirstFileA (dirp->patt, &dirp->find_data);
-      if (dirp->search_handle != INVALID_HANDLE_VALUE) {
-         /* a directory entry is now waiting in memory */
-         dirp->cached = 1;
-      } else {
-         /* failed to re-open directory: no directory entry in memory */
-         dirp->cached = 0;
-      }
-   }
-}
+*/
 
 #ifdef __cplusplus
 }
 #endif
-#endif /*DIRENT_H*/
+
+#endif
