summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
Diffstat (limited to 'win32')
-rw-r--r--win32/dir.h7
-rw-r--r--win32/resource.rb2
-rw-r--r--win32/win32.c71
-rw-r--r--win32/win32.h79
4 files changed, 134 insertions, 25 deletions
diff --git a/win32/dir.h b/win32/dir.h
index 8665fb2d3b..3dd670bef0 100644
--- a/win32/dir.h
+++ b/win32/dir.h
@@ -1,3 +1,10 @@
+#ifdef __BORLANDC__
+# ifndef WIN32_DIR_H_
+# define WIN32_DIR_H_
+# include <sys/types.h>
+# endif
+#endif
+
struct direct
{
long d_namlen;
diff --git a/win32/resource.rb b/win32/resource.rb
index 7eca372df1..d29691ebf8 100644
--- a/win32/resource.rb
+++ b/win32/resource.rb
@@ -55,7 +55,9 @@ end
f.binmode if /mingw/ =~ RUBY_PLATFORM
f.print <<EOF
+#ifndef __BORLANDC__
#include <windows.h>
+#endif
#{icons}
VS_VERSION_INFO VERSIONINFO
diff --git a/win32/win32.c b/win32/win32.c
index cd8bcae491..81ce8b6ba0 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -45,6 +45,11 @@
# undef WIN95
#endif
+#ifdef __BORLANDC__
+# define _filbuf _fgetc
+# define _flsbuf fputc
+#endif
+
#if HAVE_WSAWAITFORMULTIPLEEVENTS
# define USE_INTERRUPT_WINSOCK
#endif
@@ -1115,7 +1120,11 @@ rb_w32_opendir(const char *filename)
//
if ((rb_w32_stat (filename, &sbuf) < 0 ||
+#ifdef __BORLANDC__
+ (unsigned short)(sbuf.st_mode) & _S_IFDIR == 0) &&
+#else
sbuf.st_mode & _S_IFDIR == 0) &&
+#endif
(!ISALPHA(filename[0]) || filename[1] != ':' || filename[2] != '\0' ||
((1 << (filename[0] & 0x5f) - 'A') & GetLogicalDrives()) == 0)) {
return NULL;
@@ -1320,6 +1329,9 @@ EXTERN_C void __cdecl _unlock(int);
#ifdef MSVCRT_THREADS
# define MTHREAD_ONLY(x) x
# define STHREAD_ONLY(x)
+#elif defined(__BORLANDC__)
+# define MTHREAD_ONLY(x)
+# define STHREAD_ONLY(x)
#else
# define MTHREAD_ONLY(x)
# define STHREAD_ONLY(x) x
@@ -1339,15 +1351,16 @@ typedef struct {
#define _CRTIMP __declspec(dllimport)
#endif
+#ifndef __BORLANDC__
EXTERN_C _CRTIMP ioinfo * __pioinfo[];
#define IOINFO_L2E 5
#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
#define _pioinfo(i) (__pioinfo[i >> IOINFO_L2E] + (i & (IOINFO_ARRAY_ELTS - 1)))
-
#define _osfhnd(i) (_pioinfo(i)->osfhnd)
#define _osfile(i) (_pioinfo(i)->osfile)
#define _pipech(i) (_pioinfo(i)->pipech)
+#endif
#define FOPEN 0x01 /* file handle open */
#define FNOINHERIT 0x10 /* file handle opened O_NOINHERIT */
@@ -1375,6 +1388,29 @@ rb_w32_open_osfhandle(long osfhandle, int flags)
if (flags & O_NOINHERIT)
fileflags |= FNOINHERIT;
+#ifdef __BORLANDC__
+ {
+ /* attempt to allocate a C Runtime file handle */
+ HANDLE hF = CreateFile("NUL", 0, 0, NULL, OPEN_ALWAYS, 0, NULL);
+ fh = _open_osfhandle((long)hF, 0);
+ CloseHandle(hF);
+ if (fh == -1) {
+ errno = EMFILE; /* too many open files */
+ _doserrno = 0L; /* not an OS error */
+ }
+ else {
+
+ MTHREAD_ONLY(EnterCriticalSection(&(_pioinfo(fh)->lock)));
+ /* the file is open. now, set the info in _osfhnd array */
+ //_set_osfhnd(fh, osfhandle);
+
+ fileflags |= FOPEN; /* mark as open */
+
+ //_osfile(fh) = fileflags; /* set osfile entry */
+ MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fh)->lock));
+ }
+ }
+#else
RUBY_CRITICAL({
/* attempt to allocate a C Runtime file handle */
HANDLE hF = CreateFile("NUL", 0, 0, NULL, OPEN_ALWAYS, 0, NULL);
@@ -1396,7 +1432,7 @@ rb_w32_open_osfhandle(long osfhandle, int flags)
MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fh)->lock));
}
});
-
+#endif
return fh; /* return handle */
}
@@ -1538,7 +1574,11 @@ setgid(int gid)
int
/* ioctl(int i, unsigned int u, char *data) */
-ioctl(int i, unsigned int u, long data)
+#ifdef __BORLANDC__
+ ioctl(int i, int u, ...)
+#else
+ ioctl(int i, unsigned int u, long data)
+#endif
{
return -1;
}
@@ -1713,10 +1753,18 @@ StartSockets ()
atexit((void (*)(void)) WSACleanup);
+#ifndef SO_SYNCHRONOUS_NONALERT
+#define SO_SYNCHRONOUS_NONALERT 0x20
+#endif
+
iSockOpt = SO_SYNCHRONOUS_NONALERT;
/*
* Enable the use of sockets as filehandles
*/
+#ifndef SO_OPENTYPE
+#define SO_OPENTYPE 0x7008
+#endif
+
setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
(char *)&iSockOpt, sizeof(iSockOpt));
@@ -1955,7 +2003,11 @@ rb_w32_socket (int af, int type, int protocol)
errno = WSAGetLastError();
//fprintf(stderr, "socket fail (%d)", WSAGetLastError());
}
+#ifdef __BORLANDC__
+ return _open_osfhandle(s, O_RDWR|O_BINARY);
+#else
return rb_w32_open_osfhandle(s, O_RDWR|O_BINARY);
+#endif
}
#undef gethostbyaddr
@@ -2211,7 +2263,12 @@ rb_w32_getcwd(buffer, size)
int length;
char *bp;
+#ifdef __BORLANDC__
+#undef getcwd
+ if (getcwd(buffer, size) == NULL) {
+#else
if (_getcwd(buffer, size) == NULL) {
+#endif
return NULL;
}
length = strlen(buffer);
@@ -2671,8 +2728,8 @@ static void catch_interrupt(void)
int rb_w32_getc(FILE* stream)
{
int c, trap_immediate = rb_trap_immediate;
- if (--stream->_cnt >= 0) {
- c = (unsigned char)*stream->_ptr++;
+ if (--stream->FILE_COUNT >= 0) {
+ c = (unsigned char)*stream->FILE_READPTR++;
rb_trap_immediate = trap_immediate;
}
else {
@@ -2687,8 +2744,8 @@ int rb_w32_getc(FILE* stream)
int rb_w32_putc(int c, FILE* stream)
{
int trap_immediate = rb_trap_immediate;
- if (--stream->_cnt >= 0) {
- c = (unsigned char)(*stream->_ptr++ = (char)c);
+ if (--stream->FILE_COUNT >= 0) {
+ c = (unsigned char)(*stream->FILE_READPTR++ = (char)c);
rb_trap_immediate = trap_immediate;
}
else {
diff --git a/win32/win32.h b/win32/win32.h
index b2be02047b..c33405110d 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -89,28 +89,16 @@ extern "C++" {
#define fgetchar(_stream) getchar()
#define fputchar(_c, _stream) putchar(_c)
+#ifndef __BORLANDC__
+
#define access _access
#define chmod _chmod
#define chsize _chsize
-#define close _close
-#define creat _creat
#define dup _dup
#define dup2 _dup2
-#define eof _eof
-#define filelength _filelength
#define isatty _isatty
-#define locking _locking
-#define lseek _lseek
-#define mktemp _mktemp
#define open _open
-#define perror _perror
-#define read _read
#define setmode _setmode
-#define sopen _sopen
-#define tell _tell
-#define umask _umask
-#define unlink _unlink
-#define write _write
#define execl _execl
#define execle _execle
#define execlp _execlp
@@ -119,8 +107,7 @@ extern "C++" {
#define execve _execve
#define execvp _execvp
#define execvpe _execvpe
-#define getpid _getpid
-#define sleep(x) rb_w32_sleep((x)*1000)
+#define lseek _lseek
#define spawnl _spawnl
#define spawnle _spawnle
#define spawnlp _spawnlp
@@ -132,13 +119,34 @@ extern "C++" {
#if _MSC_VER < 800
#define fileno _fileno
#endif
+#define strcasecmp _stricmp
+#define strncasecmp _strnicmp
+#else
+#define strcasecmp stricmp
+#define strncasecmp strnicmp
+#define _open _sopen
+#endif
+
+#define close _close
+#define creat _creat
+#define eof _eof
+#define filelength _filelength
+#define locking _locking
+#define mktemp _mktemp
+#define perror _perror
+#define read _read
+#define sopen _sopen
+#define tell _tell
+#define umask _umask
+#define unlink _unlink
+#define write _write
+#define getpid _getpid
+#define sleep(x) rb_w32_sleep((x)*1000)
#define utime _utime
#define vsnprintf _vsnprintf
#define snprintf _snprintf
#define popen _popen
#define pclose _pclose
-#define strcasecmp _stricmp
-#define strncasecmp _strnicmp
#undef stat
#define stat(path,st) rb_w32_stat(path,st)
/* these are defined in nt.c */
@@ -196,9 +204,44 @@ extern int gettimeofday(struct timeval *, struct timezone *);
extern pid_t waitpid (pid_t, int *, int);
extern int do_spawn(char *);
extern int kill(int, int);
+#ifndef __BORLANDC__
extern int isinf(double);
extern int isnan(double);
+#else
+#include <float.h>
+#ifndef isinf
+#define isinf !_finite
+#endif
+#ifndef isnan
+#define isnan _isnan
+#endif
+
+#ifdef S_ISDIR
+#undef S_ISDIR
+#endif
+#ifdef S_ISFIFO
+#undef S_ISFIFO
+#endif
+
+#ifdef S_ISBLK
+#undef S_ISBLK
+#endif
+
+#ifdef S_ISCHR
+#undef S_ISCHR
+#endif
+
+#ifdef S_ISREG
+#undef S_ISREG
+#endif
+
+#define S_ISDIR(m) (((unsigned short)(m) & S_IFMT) == S_IFDIR)
+#define S_ISFIFO(m) (((unsigned short)(m) & S_IFMT) == S_IFIFO)
+#define S_ISBLK(m) (((unsigned short)(m) & S_IFMT) == S_IFBLK)
+#define S_ISCHR(m) (((unsigned short)(m) & S_IFMT) == S_IFCHR)
+#define S_ISREG(m) (((unsigned short)(m) & S_IFMT) == S_IFREG)
+#endif
//
// define this so we can do inplace editing