Example #1
0
_WCRTLINK FILE *__F_NAME(fdopen,_wfdopen)( int handle, const CHAR_TYPE *access_mode )
{
    unsigned        flags;
    FILE *          fp;
#if !defined(__NETWARE__)
    int             extflags;
#endif

    if( handle == -1 ) {
        __set_errno( EBADF );           /* 5-dec-90 */
        return( NULL );                 /* 19-apr-90 */
    }
    #ifdef __NETWARE__
        flags = __F_NAME(__open_flags,__wopen_flags)( access_mode );
    #else
        flags = __F_NAME(__open_flags,__wopen_flags)( access_mode,
                                                      &extflags );
    #endif
    if( flags == 0 ) return( NULL );

#if !defined(__NETWARE__)
    /* make sure the handle has the same text/binary mode */
    if( __iomode( handle, flags ) == -1 ) {
        return( NULL );
    }
#endif
    fp = __allocfp( handle );               /* JBS 30-aug-91 */
    if( fp ) {
        fp->_flag &= ~(_READ | _WRITE); /* 2-dec-90 */
        fp->_flag |= flags;
        fp->_cnt = 0;
        _FP_BASE(fp) = NULL;
        fp->_bufsize = 0;                   /* was BUFSIZ JBS 91/05/31 */
        #ifndef __NETWARE__
            _FP_ORIENTATION(fp) = _NOT_ORIENTED; /* initial orientation */
            _FP_EXTFLAGS(fp) = extflags;
        #endif
        #if defined(__NT__) || defined(__OS2__)
            _FP_PIPEDATA(fp).isPipe = 0;    /* not a pipe */
        #endif
        fp->_handle = handle;               /* BJS 91-07-23 */
        if( __F_NAME(tolower,towlower)( *access_mode ) == 'a' ) {
            fseek( fp, 0L, SEEK_END );
        }
        __chktty( fp );                     /* JBS 31-may-91 */
#if !defined(__UNIX__) && !defined(__NETWARE__)
        __SetIOMode( handle, flags );
#endif
    }
    return( fp );
}
Example #2
0
_WCRTLINK FILE *__F_NAME(fdopen,_wfdopen)( int handle, const CHAR_TYPE *access_mode )
{
    int             file_flags;
    FILE            *fp;
    int             extflags;

    if( handle == -1 ) {
        _RWD_errno = EBADF;
        return( NULL );
    }
    file_flags = __F_NAME(__open_flags,__wopen_flags)( access_mode, &extflags );
    if( file_flags == 0 )
        return( NULL );

#ifndef __NETWARE__
    /* make sure the handle has the same text/binary mode */
    if( __iomode( handle, file_flags ) == -1 ) {
        return( NULL );
    }
#endif
    fp = __allocfp();
    if( fp != NULL ) {
        fp->_flag |= file_flags;
        fp->_cnt = 0;
        _FP_BASE( fp ) = NULL;
        fp->_bufsize = 0;                   /* was BUFSIZ JBS 91/05/31 */
#ifndef __NETWARE__
        _FP_ORIENTATION(fp) = _NOT_ORIENTED; /* initial orientation */
        _FP_EXTFLAGS(fp) = extflags;
#endif
#if defined( __NT__ ) || defined( __OS2__ ) || defined(__UNIX__)
        _FP_PIPEDATA(fp).isPipe = 0;    /* not a pipe */
#endif
        fp->_handle = handle;               /* BJS 91-07-23 */
        if( __F_NAME(tolower,towlower)( (UCHAR_TYPE)*access_mode ) == STRING( 'a' ) ) {
            fseek( fp, 0, SEEK_END );
        }
        __chktty( fp );                     /* JBS 31-may-91 */
#if !defined( __UNIX__ ) && !defined( __NETWARE__ )
        __SetIOMode( handle, file_flags );
#endif
    }
    return( fp );
}