Stdin, stdout, stderr...

[green]Need some help, I'm trying to import the c function fgets() to assembly and I am having problems passing the 3rd parameter '[b]FILE[/b] [italic]stream[/italic]'. I want to pass [b]'stdin'[/b] so I can get input from the keyboard. I looked at the stdio.h and [b]FILE[/b] is defined as a structure of [b]_iob[/b] and [b]_iob[/b] is defined as an array of structures somewhere in some dll of which I don't know. [b]stdin[/b] is predefined as [b]_iob[0][/b] of that structure array. Any ideas how I would pass [b]stdin[/b] to my third parameter via assembly? Anyone privy to the inards of the c language that can help? Thanks[/green]

Comments

  • : [green]Need some help, I'm trying to import the c function fgets() to assembly and I am having problems passing the 3rd parameter '[b]FILE[/b] [italic]stream[/italic]'. I want to pass [b]'stdin'[/b] so I can get input from the keyboard. I looked at the stdio.h and [b]FILE[/b] is defined as a structure of [b]_iob[/b] and [b]_iob[/b] is defined as an array of structures somewhere in some dll of which I don't know. [b]stdin[/b] is predefined as [b]_iob[0][/b] of that structure array. Any ideas how I would pass [b]stdin[/b] to my third parameter via assembly? Anyone privy to the inards of the c language that can help? Thanks[/green]
    :
    :

    file handles for stdin, stdout and stderr are always 0, 1 and 2 respectively.

    [code]
    /* FILENO.C: This program uses _fileno to obtain
    * the file handle for some standard C streams.
    */

    #include

    void main( void )
    {
    printf( "The file handle for stdin is %d
    ", _fileno( stdin ) );
    printf( "The file handle for stdout is %d
    ", _fileno( stdout ) );
    printf( "The file handle for stderr is %d
    ", _fileno( stderr ) );
    }


    Output

    The file handle for stdin is 0
    The file handle for stdout is 1
    The file handle for stderr is 2
    [/code]

    The method used to initialize _iob will be different for each compiler, but this is from VC++ 6.0 _file.c startup code
    [code]
    /*
    * Buffer for stdin.
    */

    char _bufin[BUFSIZ];


    /*
    * FILE descriptors; preset for stdin/out/err (note that the __tmpnum field
    * is not initialized)
    */

    FILE _iob[ _NSTREAM_ ] = {

    /* _ptr, _cnt, _base, _flag, _file, _charbuf, _bufsiz */

    /* stdin (_iob[0]) */

    { _bufin, 0, _bufin, _IOREAD | _IOYOURBUF, 0, 0, BUFSIZ },

    /* stdout (_iob[1]) */

    { NULL, 0, NULL, _IOWRT, 1, 0, 0 },

    /* stderr (_iob[3]) */

    { NULL, 0, NULL, _IOWRT, 2, 0, 0 },

    };

    [/code]


  • : : [green]Need some help, I'm trying to import the c function fgets() to assembly and I am having problems passing the 3rd parameter '[b]FILE[/b] [italic]stream[/italic]'. I want to pass [b]'stdin'[/b] so I can get input from the keyboard. I looked at the stdio.h and [b]FILE[/b] is defined as a structure of [b]_iob[/b] and [b]_iob[/b] is defined as an array of structures somewhere in some dll of which I don't know. [b]stdin[/b] is predefined as [b]_iob[0][/b] of that structure array. Any ideas how I would pass [b]stdin[/b] to my third parameter via assembly? Anyone privy to the inards of the c language that can help? Thanks[/green]
    : :
    : :
    :
    : file handles for stdin, stdout and stderr are always 0, 1 and 2 respectively.
    :
    : [code]
    : /* FILENO.C: This program uses _fileno to obtain
    : * the file handle for some standard C streams.
    : */
    :
    : #include
    :
    : void main( void )
    : {
    : printf( "The file handle for stdin is %d
    ", _fileno( stdin ) );
    : printf( "The file handle for stdout is %d
    ", _fileno( stdout ) );
    : printf( "The file handle for stderr is %d
    ", _fileno( stderr ) );
    : }
    :
    :
    : Output
    :
    : The file handle for stdin is 0
    : The file handle for stdout is 1
    : The file handle for stderr is 2
    : [/code]
    :
    : The method used to initialize _iob will be different for each compiler, but this is from VC++ 6.0 _file.c startup code
    : [code]
    : /*
    : * Buffer for stdin.
    : */
    :
    : char _bufin[BUFSIZ];
    :
    :
    : /*
    : * FILE descriptors; preset for stdin/out/err (note that the __tmpnum field
    : * is not initialized)
    : */
    :
    : FILE _iob[ _NSTREAM_ ] = {
    :
    : /* _ptr, _cnt, _base, _flag, _file, _charbuf, _bufsiz */
    :
    : /* stdin (_iob[0]) */
    :
    : { _bufin, 0, _bufin, _IOREAD | _IOYOURBUF, 0, 0, BUFSIZ },
    :
    : /* stdout (_iob[1]) */
    :
    : { NULL, 0, NULL, _IOWRT, 1, 0, 0 },
    :
    : /* stderr (_iob[3]) */
    :
    : { NULL, 0, NULL, _IOWRT, 2, 0, 0 },
    :
    : };
    :
    : [/code]


    [green]
    Thanks man but I'm still stuck and the program keeps crashing at that point. I'll have to look into it further I guess. :-(
    [/green]




Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories