summaryrefslogtreecommitdiffstats
path: root/win32
diff options
context:
space:
mode:
authorocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-25 02:08:12 +0000
committerocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-25 02:08:12 +0000
commit773ff87f71aa3a429c5ed8b28c86a224cc99aa9e (patch)
tree46163874368ca6cf443e7286774156243efaf8e7 /win32
parent808cacf459e22e3e09dbaece4ad3b7ac6a457e63 (diff)
downloadruby-773ff87f71aa3a429c5ed8b28c86a224cc99aa9e.tar.gz
ruby-773ff87f71aa3a429c5ed8b28c86a224cc99aa9e.tar.xz
ruby-773ff87f71aa3a429c5ed8b28c86a224cc99aa9e.zip
* 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] git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@6696 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c52
-rw-r--r--win32/win32.h12
2 files changed, 64 insertions, 0 deletions
diff --git a/win32/win32.c b/win32/win32.c
index ac97b201e..df16c8dbc 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -3277,3 +3277,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
diff --git a/win32/win32.h b/win32/win32.h
index 92dd59c16..60f9e3ddb 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -113,6 +113,12 @@ extern "C++" {
#define write(h, b, l) _write(h, b, l)
#define _open _sopen
#define sopen _sopen
+#undef fopen
+#define fopen(p, m) rb_w32_fopen(p, m)
+#undef fdopen
+#define fdopen(h, m) rb_w32_fdopen(h, m)
+#undef fsopen
+#define fsopen(p, m, sh) rb_w32_fsopen(p, m, sh)
#endif
#define fsync(h) _commit(h)
#undef stat
@@ -178,6 +184,12 @@ extern int do_aspawn(int, char *, char **);
extern int kill(int, int);
extern pid_t rb_w32_getpid(void);
+#ifdef __BORLANDC__
+extern FILE *rb_w32_fopen(const char *, const char *);
+extern FILE *rb_w32_fdopen(int, char *);
+extern FILE *rb_w32_fsopen(const char *, const char *, int);
+#endif
+
#include <float.h>
#if !defined __MINGW32__ || defined __NO_ISOCEXT
#ifndef isnan