This repository was archived by the owner on Oct 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 411
Alternative support for VS2015 C runtime #1360
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| /** | ||
| * This module provides MS VC runtime helper function that | ||
| * wrap differences between different versions of the MS C runtime | ||
| * | ||
| * Copyright: Copyright Digital Mars 2015. | ||
| * License: Distributed under the | ||
| * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0). | ||
| * (See accompanying file LICENSE) | ||
| * Source: $(DRUNTIMESRC rt/_stdio_msvc.d) | ||
| * Authors: Rainer Schuetze | ||
| */ | ||
|
|
||
| struct _iobuf | ||
| { | ||
| char* _ptr; | ||
| int _cnt; // _cnt and _base exchanged for VS2015 | ||
| char* _base; | ||
| int _flag; | ||
| int _file; | ||
| int _charbuf; | ||
| int _bufsiz; | ||
| char* _tmpfname; | ||
| // additional members in VS2015 | ||
| }; | ||
|
|
||
| typedef struct _iobuf FILE; | ||
| extern FILE* stdin; | ||
| extern FILE* stdout; | ||
| extern FILE* stderr; | ||
|
|
||
| FILE* __acrt_iob_func(int hnd); // VS2015+ | ||
| FILE* __iob_func(); // VS2013- | ||
|
|
||
| int _set_output_format(int format); // VS2013- | ||
|
|
||
| //extern const char* __acrt_iob_func; | ||
| extern const char* _nullfunc = 0; | ||
|
|
||
| #pragma comment(linker, "/alternatename:__acrt_iob_func=_nullfunc") | ||
| #pragma comment(linker, "/alternatename:__iob_func=_nullfunc") | ||
| #pragma comment(linker, "/alternatename:_set_output_format=_nullfunc") | ||
|
|
||
| void init_msvc() | ||
| { | ||
| if (&__acrt_iob_func != (void*) &_nullfunc) | ||
| { | ||
| stdin = __acrt_iob_func(0); | ||
| stdout = __acrt_iob_func(1); | ||
| stderr = __acrt_iob_func(2); | ||
| } | ||
| else if (&__iob_func != (void*) &_nullfunc) | ||
| { | ||
| FILE* fp = __iob_func(); | ||
| stdin = fp; | ||
| stdout = fp + 1; | ||
| stderr = fp + 1; | ||
| } | ||
| if (&_set_output_format != (void*) &_nullfunc) | ||
| _set_output_format(1); | ||
| } | ||
|
|
||
| // VS2013- implements these functions as macros, VS2015+ provides symbols | ||
|
|
||
| #pragma comment(linker, "/alternatename:_fputc_nolock=_msvc_fputc_nolock") | ||
| #pragma comment(linker, "/alternatename:_fgetc_nolock=_msvc_fgetc_nolock") | ||
| #pragma comment(linker, "/alternatename:rewind=_msvc_rewind") | ||
| #pragma comment(linker, "/alternatename:clearerr=_msvc_clearerr") | ||
| #pragma comment(linker, "/alternatename:feof=_msvc_feof") | ||
| #pragma comment(linker, "/alternatename:ferror=_msvc_ferror") | ||
| #pragma comment(linker, "/alternatename:fileno=_msvc_fileno") | ||
|
|
||
| // VS2013- helper functions | ||
| int _filbuf(FILE *fp); | ||
| int _flsbuf(int c, FILE *fp); | ||
|
|
||
| #pragma comment(linker, "/alternatename:_filbuf=_nullfunc") | ||
| #pragma comment(linker, "/alternatename:_flsbuf=_nullfunc") | ||
|
|
||
| int _msvc_fputc_nolock(int c, FILE *fp) | ||
| { | ||
| fp->_cnt = fp->_cnt - 1; | ||
| if (fp->_cnt >= 0) | ||
| { | ||
| *(fp->_ptr) = (char)c; | ||
| fp->_ptr = fp->_ptr + 1; | ||
| return (char)c; | ||
| } | ||
| else | ||
| return _flsbuf(c, fp); | ||
| } | ||
|
|
||
| int _msvc_fgetc_nolock(FILE *fp) | ||
| { | ||
| fp->_cnt = fp->_cnt - 1; | ||
| if (fp->_cnt >= 0) | ||
| { | ||
| char c = *(fp->_ptr); | ||
| fp->_ptr = fp->_ptr + 1; | ||
| return c; | ||
| } | ||
| else | ||
| return _filbuf(fp); | ||
| } | ||
|
|
||
| enum | ||
| { | ||
| _IOFBF = 0, | ||
| _IOLBF = 0x40, | ||
| _IONBF = 4, | ||
| _IOREAD = 1, // non-standard | ||
| _IOWRT = 2, // non-standard | ||
| _IOMYBUF = 8, // non-standard | ||
| _IOEOF = 0x10, // non-standard | ||
| _IOERR = 0x20, // non-standard | ||
| _IOSTRG = 0x40, // non-standard | ||
| _IORW = 0x80, // non-standard | ||
| _IOAPP = 0x200, // non-standard | ||
| _IOAPPEND = 0x200, // non-standard | ||
| }; | ||
|
|
||
| enum | ||
| { | ||
| SEEK_SET, | ||
| SEEK_CUR, | ||
| SEEK_END | ||
| }; | ||
|
|
||
| int fseek(FILE *fp, long off, int whence); | ||
|
|
||
| void _msvc_rewind(FILE* stream) | ||
| { | ||
| fseek(stream, 0L, SEEK_SET); | ||
| stream->_flag = stream->_flag & ~_IOERR; | ||
| } | ||
| /// | ||
| void _msvc_clearerr(FILE* stream) | ||
| { | ||
| stream->_flag = stream->_flag & ~(_IOERR|_IOEOF); | ||
| } | ||
|
|
||
| int _msvc_feof(FILE* stream) | ||
| { | ||
| return stream->_flag & _IOEOF; | ||
| } | ||
|
|
||
| int _msvc_ferror(FILE* stream) | ||
| { | ||
| return stream->_flag & _IOERR; | ||
| } | ||
|
|
||
| int _msvc_fileno(FILE* stream) | ||
| { | ||
| return stream->_file; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stderr = fp + 2;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already fixed by #1361, i.e., in master too.