#include #include #include #include void main( int argc, char** argv ) { int fd; /* file descriptor */ int rval; /* return value */ char buf; /* character buffer */ /* parse arguments */ if( argc < 2 ) { printf( "error: please provide filename\n" ); printf( "usage: %s filename\n", argv[0] ); return; } /* open specified file for reading */ fd = open( argv[1], O_RDONLY ); /* make sure open successful */ if( fd < 0 ) { printf( "error: unable to open %s\n", argv[1] ); return; } /* print contents to screen */ printf( "\n[start]\n\n" ); while( rval = read( fd, &buf, sizeof( buf ) ) > 0 ) { printf( "%c", buf ); } printf( "\n[end]\n" ); /* close file */ close( fd ); return; }