From 8fe40dcd7d3b46193f74032361efb674112ee9e5 Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Sat, 2 Feb 2013 12:43:08 +0100
Subject: [PATCH] Allow enabling of dummy error_strerror() to support some
use-cases
Enable a dummy error function to make use of error_strerror() in
third party libraries easier.
Disable if you run into name conflicts and want to really remove the
error_strerror()
---
ChangeLog | 4 ++++
include/polarssl/config.h | 11 +++++++++++
library/error.c | 18 ++++++++++++++++++
programs/util/strerror.c | 4 ++--
4 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 633938333..2689dd0c7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
PolarSSL ChangeLog
+= Development
+Changes
+ * Allow enabling of dummy error_strerror() to support some use-cases
+
= Version 1.2.4 released 2013-01-25
Changes
* Added ssl_handshake_step() to allow single stepping the handshake process
diff --git a/include/polarssl/config.h b/include/polarssl/config.h
index dac70e715..2ecb065e5 100644
--- a/include/polarssl/config.h
+++ b/include/polarssl/config.h
@@ -160,6 +160,17 @@
#define POLARSSL_ENABLE_WEAK_CIPHERSUITES
*/
+/**
+ * \def POLARSSL_ERROR_STRERROR_DUMMY
+ *
+ * Enable a dummy error function to make use of error_strerror() in
+ * third party libraries easier.
+ *
+ * Disable if you run into name conflicts and want to really remove the
+ * error_strerror()
+ */
+#define POLARSSL_ERROR_STRERROR_DUMMY
+
/**
* \def POLARSSL_GENPRIME
*
diff --git a/library/error.c b/library/error.c
index 03abc3265..d4bc27762 100644
--- a/library/error.c
+++ b/library/error.c
@@ -553,4 +553,22 @@ void error_strerror( int ret, char *buf, size_t buflen )
snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
}
+#else /* POLARSSL_ERROR_C */
+
+#if defined(POLARSSL_ERROR_STRERROR_DUMMY)
+
+#include
+
+/*
+ * Provide an non-function in case POLARSSL_ERROR_C is not defined
+ */
+void error_strerror( int ret, char *buf, size_t buflen )
+{
+ ((void) ret);
+
+ if( buflen > 0 )
+ buf[0] = '\0';
+}
+
+#endif /* POLARSSL_ERROR_STRERROR_DUMMY */
#endif /* POLARSSL_ERROR_C */
diff --git a/programs/util/strerror.c b/programs/util/strerror.c
index bb31b3d35..e248201b9 100644
--- a/programs/util/strerror.c
+++ b/programs/util/strerror.c
@@ -38,13 +38,13 @@
#define USAGE \
"\n usage: strerror \n"
-#if !defined(POLARSSL_ERROR_C)
+#if !defined(POLARSSL_ERROR_C) && !defined(POLARSSL_ERROR_STRERROR_DUMMY)
int main( int argc, char *argv[] )
{
((void) argc);
((void) argv);
- printf("POLARSSL_ERROR_C not defined.\n");
+ printf("POLARSSL_ERROR_C and/or POLARSSL_ERROR_STRERRO_DUMMY not defined.\n");
return( 0 );
}
#else