Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.stdio File I/O is not fully complete #459

Closed
dymk opened this issue Aug 31, 2013 · 3 comments
Closed

std.stdio File I/O is not fully complete #459

dymk opened this issue Aug 31, 2013 · 3 comments

Comments

@dymk
Copy link

dymk commented Aug 31, 2013

This program:

import std.stdio;

void main() {
    auto f = File("testfile.tmp", "wb+");

    ubyte[4] buffer = [1, 2, 3, 4];
    f.rawWrite(buffer);
    f.seek(0);
    f.rawRead(buffer);
    writeln(buffer);
}

fails to build, emitting the error:

$ ldmd2 ldcio.d
G:/Programs/LDC/include/d\std\stdio.d(665): Error: undefined identifier '_fileno', did you mean 'function fileno'?
G:/Programs/LDC/include/d\std\stdio.d(666): Error: undefined identifier '_setmode'
G:/Programs/LDC/include/d\std\stdio.d(666): Error: undefined identifier _O_BINARY
G:/Programs/LDC/include/d\std\stdio.d(667): Error: undefined identifier '_setmode'
ldcio.d(7): Error: template instance std.stdio.File.rawWrite!(ubyte) error instantiating

The build succeeds and runs correctly using DMD:

$ dmd ldcio.d && ldcio.exe
[1, 2, 3, 4]

I ran into the problem with DMD when building for 64 bit (the bugreport for it is (located here)[http://d.puremagic.com/issues/show_bug.cgi?id=10227], and my hackey fix was to replace these lines (117-138) of stdio.d:

else version (MICROSOFT_STDIO)
{
    extern (C)
    {
        /* **
         * Microsoft under-the-hood C I/O functions
         */
        int _fputc_nolock(int, _iobuf*);
        int _fputwc_nolock(int, _iobuf*);
        int _fgetc_nolock(_iobuf*);
        int _fgetwc_nolock(_iobuf*);
        void _lock_file(FILE*);
        void _unlock_file(FILE*);
    }
    alias _fputc_nolock FPUTC;
    alias _fputwc_nolock FPUTWC;
    alias _fgetc_nolock FGETC;
    alias _fgetwc_nolock FGETWC;

    alias _lock_file FLOCK;
    alias _unlock_file FUNLOCK;
}

With:

else version (MICROSOFT_STDIO)
{
    extern (C)
    {
        /* **
         * Microsoft under-the-hood C I/O functions
         */
        int _fputc_nolock(int, _iobuf*);
        int _fputwc_nolock(int, _iobuf*);
        int _fgetc_nolock(_iobuf*);
        int _fgetwc_nolock(_iobuf*);
        void _lock_file(FILE*);
        void _unlock_file(FILE*);
        int _setmode(int, int);
        int _fileno(FILE*);
    }
    alias _fputc_nolock FPUTC;
    alias _fputwc_nolock FPUTWC;
    alias _fgetc_nolock FGETC;
    alias _fgetwc_nolock FGETWC;

    alias _lock_file FLOCK;
    alias _unlock_file FUNLOCK;

    enum _O_BINARY = 0x8000;

}

With this "fix" (I'm not sure how stable it is), both DMD and LDC compile and run as expected.

@dymk
Copy link
Author

dymk commented Aug 31, 2013

Created PR dlang/phobos#1538 for phobos.

@redstar
Copy link
Member

redstar commented Jan 26, 2014

Set to upstream pending as the mentioned PR is already merged.

@dnadlinger
Copy link
Member

Should have landed in LDC by now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants