summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-23 22:58:11 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-23 22:58:11 +0000
commit3446537f1a8f6a0dbc2b27a0f25af13c7f61abf8 (patch)
tree11f34a0ed86032b2eaa519f6a3420faf8e5a1308 /win32
parentcc622e2ac5f72f229daa29fc5e24ae7f92dae150 (diff)
* win32/win32.c (_filbuf): msvc14 doesn't have it, use _fgetc_nolock.
* win32/win32.c (_flsbuf): msvc14 doesn't have it, use _fputc_nolock. * win32/win32.c (vcruntime_file): define vcruntime_file on msvc14 because it doesn't export FILE's internal structure. * win32/win32.c (FILE_COUNT): added to abstract FILE->_cnt. * win32/win32.c (FILE_READPTR): added to abstract FILE->_ptr. * win32/win32.c (FILE_FILENO): added to abstract FILE->_file. * win32/win32.c (init_stdhandle): use FILE_FILENO. * win32/win32.c (rb_w32_getc): use FILE_COUNT and FILE_READPTR. * win32/win32.c (rb_w32_putc): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50378 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c48
1 files changed, 37 insertions, 11 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 8a19ca0c27..5443e63b2a 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -95,6 +95,10 @@ static char *w32_getenv(const char *name, UINT cp);
# define enough_to_get(n) (--(n) >= 0)
# define enough_to_put(n) (++(n) < 0)
#else
+# if RUBY_MSVCRT_VERSION >= 140
+# define _filbuf _fgetc_nolock
+# define _flsbuf _fputc_nolock
+# endif
# define enough_to_get(n) (--(n) >= 0)
# define enough_to_put(n) (--(n) >= 0)
#endif
@@ -2255,6 +2259,32 @@ rb_w32_closedir(DIR *dirp)
# define STHREAD_ONLY(x) x
#endif
+#if RUBY_MSVCRT_VERSION >= 140
+typedef struct {
+ union
+ {
+ FILE _public_file;
+ char* _ptr;
+ };
+
+ char* _base;
+ int _cnt;
+ long _flags;
+ long _file;
+ int _charbuf;
+ int _bufsiz;
+ char* _tmpfname;
+ CRITICAL_SECTION _lock;
+} vcruntime_file;
+#define FILE_COUNT(stream) ((vcruntime_file*)stream)->_cnt
+#define FILE_READPTR(stream) ((vcruntime_file*)stream)->_ptr
+#define FILE_FILENO(stream) ((vcruntime_file*)stream)->_file
+#else
+#define FILE_COUNT(stream) stream->_cnt
+#define FILE_READPTR(stream) stream->_ptr
+#define FILE_FILENO(stream) stream->_file
+#endif
+
/* License: Ruby's */
typedef struct {
intptr_t osfhnd; /* underlying OS file HANDLE */
@@ -2395,16 +2425,16 @@ init_stdhandle(void)
(fd))
if (fileno(stdin) < 0) {
- stdin->_file = open_null(0);
+ FILE_FILENO(stdin) = open_null(0);
}
else {
setmode(fileno(stdin), O_BINARY);
}
if (fileno(stdout) < 0) {
- stdout->_file = open_null(1);
+ FILE_FILENO(stdout) = open_null(1);
}
if (fileno(stderr) < 0) {
- stderr->_file = open_null(2);
+ FILE_FILENO(stderr) = open_null(2);
}
if (nullfd >= 0 && !keep) close(nullfd);
setvbuf(stderr, NULL, _IONBF, 0);
@@ -5629,18 +5659,14 @@ read(int fd, void *buf, size_t size)
}
#endif
-
-#define FILE_COUNT _cnt
-#define FILE_READPTR _ptr
-
#undef fgetc
/* License: Ruby's */
int
rb_w32_getc(FILE* stream)
{
int c;
- if (enough_to_get(stream->FILE_COUNT)) {
- c = (unsigned char)*stream->FILE_READPTR++;
+ if (enough_to_get(FILE_COUNT(stream))) {
+ c = (unsigned char)*FILE_READPTR(stream)++;
}
else {
c = _filbuf(stream);
@@ -5659,8 +5685,8 @@ rb_w32_getc(FILE* stream)
int
rb_w32_putc(int c, FILE* stream)
{
- if (enough_to_put(stream->FILE_COUNT)) {
- c = (unsigned char)(*stream->FILE_READPTR++ = (char)c);
+ if (enough_to_put(FILE_COUNT(stream))) {
+ c = (unsigned char)(*FILE_READPTR(stream)++ = (char)c);
}
else {
c = _flsbuf(c, stream);