aboutsummaryrefslogtreecommitdiffstats
path: root/win32/win32.c
diff options
context:
space:
mode:
authorocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-25 02:25:25 +0000
committerocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-25 02:25:25 +0000
commit9d07076beffe22495ec496c60a09edd6c390e8cd (patch)
treed7de2be6005301d07694b11ab5995ea3694384a9 /win32/win32.c
parent9a983e5150dc673c38c0269dd1b4da5e18a7f88d (diff)
downloadruby-9d07076beffe22495ec496c60a09edd6c390e8cd.tar.gz
* win32/win32.{h,c} (rb_w32_{f,fd,fs}open): workaround for bcc32's
{f,fd,fs}open bug. set errno EMFILE and EBADF. [ruby-dev:23963] * test/drb/drbtest.rb: fix method duplication. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32/win32.c')
-rw-r--r--win32/win32.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 8059a1315d..95ee05566a 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -3330,3 +3330,55 @@ rb_w32_snprintf(char *buf, size_t size, const char *format, ...)
va_end(va);
return ret;
}
+
+//
+// Fix bcc32's stdio bug
+//
+
+#ifdef __BORLANDC__
+static int
+too_many_files()
+{
+ FILE *f;
+ for (f = _streams; f < _streams + _nfile; f++) {
+ if (f->fd < 0) return 0;
+ }
+ return 1;
+}
+
+#undef fopen
+FILE *
+rb_w32_fopen(const char *path, const char *mode)
+{
+ FILE *f = (errno = 0, fopen(path, mode));
+ if (f == NULL && errno == 0) {
+ if (too_many_files())
+ errno = EMFILE;
+ }
+ return f;
+}
+
+FILE *
+rb_w32_fdopen(int handle, char *type)
+{
+ FILE *f = (errno = 0, _fdopen(handle, type));
+ if (f == NULL && errno == 0) {
+ if (handle < 0)
+ errno = EBADF;
+ else if (too_many_files())
+ errno = EMFILE;
+ }
+ return f;
+}
+
+FILE *
+rb_w32_fsopen(const char *path, const char *mode, int shflags)
+{
+ FILE *f = (errno = 0, _fsopen(path, mode, shflags));
+ if (f == NULL && errno == 0) {
+ if (too_many_files())
+ errno = EMFILE;
+ }
+ return f;
+}
+#endif