Fixed MSVC build by explicitly providing "ssize_t".
[mono.git] / mono / utils / mono-md5.c
index c4e0438a0310d2e21bc5bea0ec4c0bf2b3dbf073..5ded45eb9db3d8f4b8d17316df2b83573ea237fc 100644 (file)
 #include <string.h>
 #include "mono-digest.h"
 
+#if HAVE_COMMONCRYPTO_COMMONDIGEST_H
+
+void
+mono_md5_init (MonoMD5Context *ctx)
+{
+       CC_MD5_Init (ctx);
+}
+
+void
+mono_md5_update (MonoMD5Context *ctx, const guchar *buf, guint32 len)
+{
+       CC_MD5_Update (ctx, buf, len);
+}
+
+void
+mono_md5_final (MonoMD5Context *ctx, guchar digest[16])
+{
+       CC_MD5_Final (digest, ctx);
+}
+
+#else
+
 static void md5_transform (guint32 buf[4], const guint32 in[16]);
 
 static gint _ie = 0x44332211;
@@ -295,7 +317,7 @@ md5_transform (guint32 buf[4], const guint32 in[16])
        buf[3] += d;
 }
 
-
+#endif
 
 
 /**
@@ -326,6 +348,8 @@ mono_md5_get_digest (const guchar *buffer, gint buffer_size, guchar digest[16])
  * 
  * Get the md5 hash of a file. The result is put in 
  * the 16 bytes buffer @digest .
+ * 
+ * If an IO error happens the value in @digest is not updated.
  **/
 void
 mono_md5_get_digest_from_file (const gchar *filename, guchar digest[16])
@@ -347,6 +371,8 @@ mono_md5_get_digest_from_file (const gchar *filename, guchar digest[16])
        if (ferror(fp)) {
                fclose(fp);
                return;
+       } else {
+               fclose(fp);
        }
 
        mono_md5_final (&ctx, digest);