◄Up► ◄Contents► ◄Index► ◄Back► ─────Run-Time Library─────────────────────────────────────────────────────── /* IOTEST.C compares low-level and stream I/O using function: * _fdopen */ #include <io.h> #include <fcntl.h> /* _O_ constant definitions */ #include <sys\types.h> #include <sys\stat.h> /* _S_ constant definitions */ #include <stdio.h> #include <stdlib.h> #include <time.h> void main( int argc, char *argv[] ) { int handle; FILE *stream; clock_t start; char tmp[16]; /* Open for low-level I/O and read file in 16-byte chunks. */ if( (handle = _open( argv[1], _O_BINARY | _O_RDONLY )) == - 1 ) exit( 1 ); start = clock(); while( !_eof( handle ) ) _read( handle, tmp, 16 ); printf( "I/O Type: Low level\tTime: %5.1f\n", ((float)clock() - start) / CLOCKS_PER_SEC ); /* Change to stream I/O and read file in 16-byte chunks. */ if( (stream = _fdopen( handle, "rb" )) == NULL ) exit( 1 ); while( !feof( stream ) ) fread( tmp, sizeof( char ), 16, stream ); printf( "I/O Type: Stream\tTime: %5.1f\n", ((float)clock() - start) / CLOCKS_PER_SEC ); _close( handle ); exit( 0 ); } -♦-