[PATCH 1/9] stop using sys/cdefs.h, is not portable

Michael Haubenwallner michael.haubenwallner at ssi-schaefer.com
Mon Apr 10 11:10:38 UTC 2017


For portability, we should not rely on the __BEGIN_DECLS, __END_DECLS
and __P to be predefined somewhere.
---
 include/md2.h    | 9 ++++++---
 include/md4.h    | 9 ++++++---
 include/md5.h    | 9 ++++++---
 include/rmd160.h | 9 ++++++---
 include/sha1.h   | 9 ++++++---
 include/sha2.h   | 9 ++++++---
 src/md2.c        | 3 +--
 7 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/include/md2.h b/include/md2.h
index 7832905..b5ed05a 100644
--- a/include/md2.h
+++ b/include/md2.h
@@ -3,7 +3,6 @@
 #ifndef _MD2_H_
 #define _MD2_H_
 
-#include <sys/cdefs.h>
 #include <sys/types.h>
 
 #include <stdint.h>
@@ -18,7 +17,9 @@ typedef struct MD2Context {
 	unsigned char X[48];		/* input buffer */
 } MD2_CTX;
 
-__BEGIN_DECLS
+#ifdef __cplusplus
+extern "C" {
+#endif
 void	MD2Init(MD2_CTX *);
 void	MD2Update(MD2_CTX *, const unsigned char *, unsigned int);
 void	MD2Final(unsigned char[16], MD2_CTX *);
@@ -26,6 +27,8 @@ char	*MD2End(MD2_CTX *, char *);
 char	*MD2File(const char *, char *);
 char	*MD2FileChunk(const char *, char *, off_t, off_t);
 char	*MD2Data(const unsigned char *, size_t, char *);
-__END_DECLS
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* _MD2_H_ */
diff --git a/include/md4.h b/include/md4.h
index ccd524f..9e70c69 100644
--- a/include/md4.h
+++ b/include/md4.h
@@ -16,7 +16,6 @@
 #ifndef _MD4_H_
 #define _MD4_H_
 
-#include <sys/cdefs.h>
 #include <sys/types.h>
 
 #include <stdint.h>
@@ -31,7 +30,9 @@ typedef struct MD4Context {
 	uint8_t buffer[MD4_BLOCK_LENGTH];	/* input buffer */
 } MD4_CTX;
 
-__BEGIN_DECLS
+#ifdef __cplusplus
+extern "C" {
+#endif
 void	 MD4Init(MD4_CTX *);
 void	 MD4Update(MD4_CTX *, const uint8_t *, size_t);
 void	 MD4Pad(MD4_CTX *);
@@ -41,6 +42,8 @@ char	*MD4End(MD4_CTX *, char *);
 char	*MD4File(const char *, char *);
 char	*MD4FileChunk(const char *, char *, off_t, off_t);
 char	*MD4Data(const uint8_t *, size_t, char *);
-__END_DECLS
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* _MD4_H_ */
diff --git a/include/md5.h b/include/md5.h
index 0a0a4ff..e9a027e 100644
--- a/include/md5.h
+++ b/include/md5.h
@@ -15,7 +15,6 @@
 #ifndef _MD5_H_
 #define _MD5_H_
 
-#include <sys/cdefs.h>
 #include <sys/types.h>
 
 #include <stdint.h>
@@ -30,7 +29,9 @@ typedef struct MD5Context {
 	uint8_t buffer[MD5_BLOCK_LENGTH];	/* input buffer */
 } MD5_CTX;
 
-__BEGIN_DECLS
+#ifdef __cplusplus
+extern "C" {
+#endif
 void	 MD5Init(MD5_CTX *);
 void	 MD5Update(MD5_CTX *, const uint8_t *, size_t);
 void	 MD5Pad(MD5_CTX *);
@@ -40,6 +41,8 @@ char	*MD5End(MD5_CTX *, char *);
 char	*MD5File(const char *, char *);
 char	*MD5FileChunk(const char *, char *, off_t, off_t);
 char	*MD5Data(const uint8_t *, size_t, char *);
-__END_DECLS
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* _MD5_H_ */
diff --git a/include/rmd160.h b/include/rmd160.h
index b9fef11..b6353e2 100644
--- a/include/rmd160.h
+++ b/include/rmd160.h
@@ -25,7 +25,6 @@
 #ifndef  _RMD160_H
 #define  _RMD160_H
 
-#include <sys/cdefs.h>
 #include <sys/types.h>
 
 #include <stdint.h>
@@ -41,7 +40,9 @@ typedef struct RMD160Context {
 	uint8_t buffer[RMD160_BLOCK_LENGTH];	/* input buffer */
 } RMD160_CTX;
 
-__BEGIN_DECLS
+#ifdef __cplusplus
+extern "C" {
+#endif
 void	 RMD160Init(RMD160_CTX *);
 void	 RMD160Transform(uint32_t [5], const uint8_t [RMD160_BLOCK_LENGTH]);
 void	 RMD160Update(RMD160_CTX *, const uint8_t *, size_t);
@@ -51,6 +52,8 @@ char	*RMD160End(RMD160_CTX *, char *);
 char	*RMD160File(const char *, char *);
 char	*RMD160FileChunk(const char *, char *, off_t, off_t);
 char	*RMD160Data(const uint8_t *, size_t, char *);
-__END_DECLS
+#ifdef __cplusplus
+}
+#endif
 
 #endif  /* _RMD160_H */
diff --git a/include/sha1.h b/include/sha1.h
index bf21e58..e921ee1 100644
--- a/include/sha1.h
+++ b/include/sha1.h
@@ -9,7 +9,6 @@
 #ifndef _SHA1_H
 #define _SHA1_H
 
-#include <sys/cdefs.h>
 #include <sys/types.h>
 
 #include <stdint.h>
@@ -24,7 +23,9 @@ typedef struct {
     uint8_t buffer[SHA1_BLOCK_LENGTH];
 } SHA1_CTX;
 
-__BEGIN_DECLS
+#ifdef __cplusplus
+extern "C" {
+#endif
 void SHA1Init(SHA1_CTX *);
 void SHA1Pad(SHA1_CTX *);
 void SHA1Transform(uint32_t [5], const uint8_t [SHA1_BLOCK_LENGTH]);
@@ -34,7 +35,9 @@ char *SHA1End(SHA1_CTX *, char *);
 char *SHA1File(const char *, char *);
 char *SHA1FileChunk(const char *, char *, off_t, off_t);
 char *SHA1Data(const uint8_t *, size_t, char *);
-__END_DECLS
+#ifdef __cplusplus
+}
+#endif
 
 #define HTONDIGEST(x) do {                                              \
         x[0] = htonl(x[0]);                                             \
diff --git a/include/sha2.h b/include/sha2.h
index 9cfd273..025a392 100644
--- a/include/sha2.h
+++ b/include/sha2.h
@@ -37,7 +37,6 @@
 #ifndef _SHA2_H
 #define _SHA2_H
 
-#include <sys/cdefs.h>
 #include <sys/types.h>
 
 #include <stdint.h>
@@ -64,7 +63,9 @@ typedef struct _SHA2_CTX {
 	uint8_t		buffer[SHA512_BLOCK_LENGTH];
 } SHA2_CTX;
 
-__BEGIN_DECLS
+#ifdef __cplusplus
+extern "C" {
+#endif
 void SHA256Init(SHA2_CTX *);
 void SHA256Transform(uint32_t state[8], const uint8_t [SHA256_BLOCK_LENGTH]);
 void SHA256Update(SHA2_CTX *, const uint8_t *, size_t);
@@ -94,6 +95,8 @@ char *SHA512End(SHA2_CTX *, char *);
 char *SHA512File(const char *, char *);
 char *SHA512FileChunk(const char *, char *, off_t, off_t);
 char *SHA512Data(const uint8_t *, size_t, char *);
-__END_DECLS
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* _SHA2_H */
diff --git a/src/md2.c b/src/md2.c
index b01fe60..4516326 100644
--- a/src/md2.c
+++ b/src/md2.c
@@ -29,7 +29,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
 __RCSID("$NetBSD: md2.c,v 1.7 2012/06/25 22:32:44 abs Exp $");
 #endif /* LIBC_SCCS and not lint */
@@ -96,7 +95,7 @@ static const unsigned char *pad[] = {
  * XXX This should not be visible, but due to an accident, it is
  * XXX so it must remain so.
  */
-/*static*/ void MD2Transform __P((MD2_CTX *));
+/*static*/ void MD2Transform (MD2_CTX *);
 
 #ifdef __weak_alias
 __weak_alias(MD2Init,_MD2Init)
-- 
2.10.2



More information about the libbsd mailing list