Mercurial > octave-nkf
diff liboctave/oct-md5.cc @ 6383:65e9cf5c7718
[project @ 2007-03-05 22:03:31 by dbateman]
author | dbateman |
---|---|
date | Mon, 05 Mar 2007 22:03:31 +0000 |
parents | 5fced7a5eee8 |
children | 93c65f2a5668 |
line wrap: on
line diff
--- a/liboctave/oct-md5.cc Mon Mar 05 21:29:40 2007 +0000 +++ b/liboctave/oct-md5.cc Mon Mar 05 22:03:31 2007 +0000 @@ -28,6 +28,7 @@ #include "config.h" #endif +#include "lo-error.h" #include "oct-md5.h" #include "md5.h" @@ -49,6 +50,42 @@ return std::string (tmp); } +std::string +oct_md5_file (const std::string file) +{ + FILE *ifile = fopen (file.c_str (), "rb"); + + if (! ifile) + { + (*current_liboctave_error_handler) ("unable to open file `%s' for writing", + file.c_str()); + return std::string(); + } + else + { + md5_state_t state; + size_t nel; + + OCTAVE_LOCAL_BUFFER (md5_byte_t, digest, 16); + OCTAVE_LOCAL_BUFFER (md5_byte_t, buf, 1024); + + md5_init (&state); + + while ((nel = fread (buf, 1, 1024, ifile))) + md5_append (&state, buf, nel); + + fclose (ifile); + + md5_finish (&state, digest); + + OCTAVE_LOCAL_BUFFER (char, tmp, 33); + for (octave_idx_type i = 0; i < 16; i++) + sprintf (&tmp[2*i], "%02x", digest[i]); + tmp[32] = 0; + return std::string (tmp); + } +} + /* ;;; Local Variables: *** ;;; mode: C++ ***