Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
IOTEST.C
◄Up► ◄Contents► ◄Index► ◄Back►
────────────────────────────────────────────────────────────────────────────
/* 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) / CLK_TCK );
/* 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) / CLK_TCK );
close( handle );
exit( 0 );
}