From be089b04837352e6a987f546640aabe699173746 Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Mon, 14 Oct 2013 15:51:50 +0200
Subject: [PATCH] Introduced POLARSSL_HAVE_READDIR_R for systems without it
---
ChangeLog | 1 +
include/polarssl/config.h | 11 +++++++++++
library/x509_crt.c | 10 ++++++++--
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index f6def8cbf..9d7cce41b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@ Features
Changes
* RSA blinding locks for a smaller amount of time
* TLS compression only allocates working buffer once
+ * Introduced POLARSSL_HAVE_READDIR_R for systems without it
Bugfix
* Missing MSVC defines added
diff --git a/include/polarssl/config.h b/include/polarssl/config.h
index e4ab5e1bb..0e725d303 100644
--- a/include/polarssl/config.h
+++ b/include/polarssl/config.h
@@ -93,6 +93,17 @@
#define POLARSSL_HAVE_SSE2
*/
+/**
+ * \def POLARSSL_HAVE_READDIR_R
+ *
+ * (Non Windows) System has readdir_r().
+ *
+ * Required for x509_crt_parse_path() in non-Windows systems.
+ *
+ * Comment if your system does not have support.
+ */
+#define POLARSSL_HAVE_READDIR_R
+
/**
* \def POLARSSL_HAVE_TIME
*
diff --git a/library/x509_crt.c b/library/x509_crt.c
index d7723ac1c..0a22b8741 100644
--- a/library/x509_crt.c
+++ b/library/x509_crt.c
@@ -986,7 +986,8 @@ int x509_crt_parse_path( x509_crt *chain, const char *path )
ret = POLARSSL_ERR_X509_FILE_IO_ERROR;
FindClose( hFind );
-#else
+#else /* _WIN32 */
+#if defined(POLARSSL_HAVE_READDIR_R)
int t_ret, i;
struct stat sb;
struct dirent entry, *result = NULL;
@@ -1023,7 +1024,12 @@ int x509_crt_parse_path( x509_crt *chain, const char *path )
ret += t_ret;
}
closedir( dir );
-#endif
+#else /* POLARSSL_HAVE_READDIR_R */
+ ((void) chain);
+ ((void) path);
+ ret = POLARSSL_ERR_X509_FEATURE_UNAVAILABLE;
+#endif /* POLARSSL_HAVE_READDIR_R */
+#endif /* _WIN32 */
return( ret );
}