Index: trunk/Server/server.c
===================================================================
--- trunk/Server/server.c	(revision 214)
+++ trunk/Server/server.c	(revision 215)
@@ -16,5 +16,5 @@
 #include "tw_version.h"
 
-#ifndef _MSC_VER
+#if !defined(_MSC_VER) && !defined(__BORLANDC__)
 #include <unistd.h>
 #endif
@@ -33,5 +33,5 @@
 #include <cm_dir.h>
 
-#if defined(__MINGW32__) || defined(_MSC_VER)
+#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__)
 #ifndef NO_GETADDRINFO
 #include <ws2tcpip.h>
@@ -84,5 +84,5 @@
 int sockets[MAX_PORTS];
 
-#if defined(__MINGW32__) || defined(_MSC_VER)
+#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__)
 const char* reserved_names[] = {"CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"};
 #endif
@@ -111,5 +111,5 @@
 
 void close_socket(int sock) {
-#if defined(__MINGW32__) || defined(_MSC_VER)
+#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__)
 	closesocket(sock);
 #else
@@ -120,5 +120,5 @@
 int tw_server_init(void) {
 	int i;
-#if defined(__MINGW32__) || defined(_MSC_VER)
+#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__)
 	WSADATA wsa;
 	WSAStartup(MAKEWORD(2, 0), &wsa);
@@ -135,5 +135,5 @@
 		int sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
 #endif
-#if defined(__MINGW32__) || defined(_MSC_VER)
+#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__)
 		if(sock == INVALID_SOCKET)
 #else
@@ -238,5 +238,5 @@
 		doc = NULL;
 	}
-#ifdef _MSC_VER
+#if defined(_MSC_VER) || defined(__BORLANDC__)
 	sprintf(construct, "%lu", (unsigned long)size);
 #else
@@ -451,4 +451,6 @@
 #if defined(__MINGW32__) || defined(_MSC_VER)
 unsigned int WINAPI tw_server_pass(void* ptr) {
+#elif defined(__BORLANDC__)
+void tw_server_pass(void* ptr) {
 #elif defined(__HAIKU__)
 int32_t tw_server_pass(void* ptr) {
@@ -456,5 +458,5 @@
 int tw_server_pass(void* ptr) {
 #endif
-#if defined(__HAIKU__) || defined(__MINGW32__) || defined(_PSP) || defined(__PPU__) || defined(_MSC_VER)
+#if defined(__HAIKU__) || defined(__MINGW32__) || defined(_PSP) || defined(__PPU__) || defined(_MSC_VER) || defined(__BORLANDC__)
 #define FREE_PTR
 	int sock = ((struct pass_entry*)ptr)->sock;
@@ -549,5 +551,5 @@
 					struct tm* btm;
 					strptime(req.headers[i + 1], "%a, %d %b %Y %H:%M:%S GMT", &tm);
-#if defined(__MINGW32__) || defined(_PSP) || defined(__PPU__) || defined(__ps2sdk__) || defined(_MSC_VER)
+#if defined(__MINGW32__) || defined(_PSP) || defined(__PPU__) || defined(__ps2sdk__) || defined(_MSC_VER) || defined(__BORLANDC__)
 					t = 0;
 					btm = localtime(&t);
@@ -612,8 +614,18 @@
 			char* rpath;
 			struct stat st;
+			char* slash;
 			cm_log("Server", "Document root is %s", vhost_entry->root == NULL ? "not set" : vhost_entry->root);
 			path = cm_strcat(vhost_entry->root == NULL ? "" : vhost_entry->root, req.path);
 			cm_log("Server", "Filesystem path is %s", path);
-#if defined(__MINGW32__) || defined(_MSC_VER)
+#if defined(_MSC_VER) || defined(__BORLANDC__)
+			for(i = strlen(path) - 1; i >= 0; i--){
+				if(path[i] == '/'){
+					path[i] = 0;
+				}else{
+					break;
+				}
+			}
+#endif
+#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__)
 			rpath = cm_strdup(path);
 			for(i = strlen(rpath) - 1; i >= 0; i--) {
@@ -647,5 +659,6 @@
 				} else if(S_ISDIR(st.st_mode)) {
 					if(req.path[strlen(req.path) - 1] != '/') {
-						char* headers[3] = {"Location", cm_strcat(req.path, "/"), NULL};
+						char* headers[3] = {"Location", NULL, NULL};
+						headers[1] = cm_strcat(req.path, "/");
 						cm_log("Server", "Accessing directory without the slash at the end");
 						_tw_process_page(s, sock, tw_http_status(301), NULL, NULL, NULL, 0, headers, 0, 0);
@@ -885,10 +898,16 @@
 #endif
 	close_socket(sock);
-#if defined(__MINGW32__) || defined(_MSC_VER)
-	_endthread(0);
+#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__)
+	_endthread(
+#ifndef __BORLANDC__
+		0
+#endif
+	);
 #elif defined(__HAIKU__)
 		exit_thread(0);
 #endif
+#ifndef __BORLANDC__
 	return 0;
+#endif
 }
 
@@ -898,5 +917,5 @@
 #endif
 
-#if defined(__MINGW32__) || defined(__HAIKU__) || defined(_MSC_VER)
+#if defined(__MINGW32__) || defined(__HAIKU__) || defined(_MSC_VER) || defined(__BORLANDC__)
 struct thread_entry {
 #ifdef __HAIKU__
@@ -917,5 +936,5 @@
 	struct timeval tv;
 #endif
-#if defined(__MINGW32__) || defined(__HAIKU__) || defined(_MSC_VER)
+#if defined(__MINGW32__) || defined(__HAIKU__) || defined(_MSC_VER) || defined(__BORLANDC__)
 	struct thread_entry threads[2048];
 	for(i = 0; i < sizeof(threads) / sizeof(threads[0]); i++) {
@@ -948,5 +967,5 @@
 #endif
 		if(ret == -1) {
-#if !defined(__MINGW32__) && !defined(_MSC_VER)
+#if !defined(__MINGW32__) && !defined(_MSC_VER) && !defined(__BORLANDC__)
 			cm_log("Server", "Select failure: %s", strerror(errno));
 #endif
@@ -972,10 +991,10 @@
 					socklen_t clen = sizeof(claddr);
 					int sock = accept(sockets[i], (struct sockaddr*)&claddr, &clen);
-#if defined(__MINGW32__) || defined(__HAIKU__) || defined(_PSP) || defined(__PPU__) || defined(_MSC_VER)
+#if defined(__MINGW32__) || defined(__HAIKU__) || defined(_PSP) || defined(__PPU__) || defined(_MSC_VER) || defined(__BORLANDC__)
 					int j;
 					struct pass_entry* e = malloc(sizeof(*e));
 					cm_log("Server", "New connection accepted");
 					e->sock = sock;
-#ifdef _MSC_VER
+#if defined(_MSC_VER) || defined(__BORLANDC__)
 					e->ssl = config.ports[i] & (1UL << 31);
 #else
@@ -985,5 +1004,5 @@
 					e->addr = claddr;
 #endif
-#if defined(__MINGW32__) || defined(_MSC_VER)
+#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__)
 					_beginthread(tw_server_pass, 0, e);
 #elif defined(_PSP) || defined(__PPU__)
