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
00024 unsigned int CountFreeBits( const int byte )
00025 {
00026 unsigned int count = 0;
00027 int i, mask = 0x80;
00028 for( i = 0; i < 8; i++ )
00029 {
00030 if( ( mask & byte ) == mask )
00031 count++;
00032 mask = mask >> 1;
00033 }
00034 return count;
00035 }
00036
00037 unsigned int CountnFree( char m_BitMap )
00038 {
00039
00040 unsigned int count;
00041
00042 count = CountFreeBits( m_BitMap );
00043 return count;
00044 }
00045
00046 int main( int argc, char *argv[] )
00047 {
00048 int file, i;
00049 char c;
00050 unsigned int sum;
00051
00052 for( i = 1; i < argc; i++ )
00053 {
00054 file = open( argv[ i ], O_RDONLY );
00055 if( file > 0 )
00056 {
00057 sum = 0;
00058 while( read( file, (char *)&c, 1 ) == 1 )
00059 {
00060 sum += CountnFree( c );
00061 }
00062 close( file );
00063 fprintf( stderr, "sum = %u\n", sum );
00064 }
00065 else
00066 fprintf( stderr, "Nao consegui abrir o arquivo\n" );
00067 }
00068
00069 return( 0 );
00070 }