00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <sys/types.h>
00019 #include <sys/stat.h>
00020 #include <fcntl.h>
00021 #include <unistd.h>
00022 #include <stdio.h>
00023 #include <errno.h>
00024 #include <string.h>
00025
00026 int main( int argc, char *argv[] )
00027 {
00028 int file;
00029 int num, i, j;
00030 int lidos;
00031 char header[ 64 ];
00032
00033 for( j = 1; j < argc; j++ )
00034 {
00035 i = 0;
00036 file = open( argv[ j ], O_RDONLY );
00037 if( file > 0 )
00038 {
00039 lidos = read( file, (char *)&header, 64 );
00040 if( lidos != 64 )
00041 {
00042 fprintf( stdout, "main erro ao ler o valor de header: lidos %u",
00043 lidos);
00044 fprintf( stdout, " bytes de um total de 64 bytes.\n" );
00045 }
00046 else if( lidos == -1 )
00047 {
00048 fprintf( stdout, "main erro %u (%s) ao ler o valor de header\n",
00049 errno, strerror( errno ) );
00050 }
00051 while( read( file, (char *)&num, 4 ) == 4 )
00052 {
00053 fprintf( stderr, "%4d ", num );
00054 if( ++i % 2 == 0 )
00055 fprintf( stderr, "\n" );
00056 }
00057 close( file );
00058 }
00059 else
00060 fprintf( stderr, "Nao consegui abrir o arquivo\n" );
00061 }
00062
00063 return( 0 );
00064 }