diff --git a/include/keystone/keystone.h b/include/keystone/keystone.h
index 28ce0ce19df8f656905370f3bb7f1e60006f4f61..cc31d98604d2385bb51f733a8cc00f833b186f2c 100644
--- a/include/keystone/keystone.h
+++ b/include/keystone/keystone.h
@@ -224,7 +224,7 @@ ks_err ks_close(ks_engine *ks);
  @return: error code of ks_err enum type (KS_ERR_*, see above)
 */
 KEYSTONE_EXPORT
-unsigned int ks_errno(ks_engine *ks);
+ks_err ks_errno(ks_engine *ks);
 
 
 /*
diff --git a/llvm/keystone/ks.cpp b/llvm/keystone/ks.cpp
index eab3b1045aac1cb83f4cc4009cca16b80886e2b5..eabd4e10bda137858db7fb6c2312d98b8395a9c7 100644
--- a/llvm/keystone/ks.cpp
+++ b/llvm/keystone/ks.cpp
@@ -33,9 +33,9 @@ unsigned int ks_version(unsigned int *major, unsigned int *minor)
 
 
 KEYSTONE_EXPORT
-unsigned int ks_errno(ks_engine *ks)
+ks_err ks_errno(ks_engine *ks)
 {
-    return ks->errnum;
+    return (ks_err)ks->errnum;
 }