Logo Search packages:      
Sourcecode: u3-tool version File versions  Download package

int md5_file ( char *  path,
unsigned char *  output 
)

Output = MD5( file contents ).

Parameters:
path input file name
output MD5 checksum result
Returns:
0 if successful, 1 if fopen failed, or 2 if fread failed

Definition at line 293 of file md5.c.

{
    FILE *f;
    size_t n;
    md5_context ctx;
    unsigned char buf[1024];

    if( ( f = fopen( path, "rb" ) ) == NULL )
        return( 1 );

    md5_starts( &ctx );

    while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
        md5_update( &ctx, buf, (int) n );

    md5_finish( &ctx, output );

    memset( &ctx, 0, sizeof( md5_context ) );

    if( ferror( f ) != 0 )
    {
        fclose( f );
        return( 2 );
    }

    fclose( f );
    return( 0 );
}


Generated by  Doxygen 1.6.0   Back to index