The rollup was updated to include both -ansi and -std=c90.

Nearly all the pieces were available to support it. The patch simply
needed better integration with existing library facilities. For
example, there's an OPENSSL_strdup() for strdup(), there's workarounds
for strncmpcase() that performs the to_lower() conversion, etc.

Some of the OpenSSL utilities needed things relaxed, so it follows
ssltest.c lead and performs "#define _DEFAULT_SOURCE 1" when needed.

There's no need for the dodgy "-D_DEFAULT_SOURCE=__STRICT_ANSI__".

Tested OK under OS X, Linux and NetBSD.

Jeff

On Fri, Mar 25, 2016 at 11:39 AM, Jeffrey Walton <noloa...@gmail.com> wrote:
> Here's the rollup patch that makes -ansi work. Most of it was "inline"
> -> "ossl_inline". Some hoops were jumped through to get SSIZE_MAX
> defined correctly.
>
> To configure:
>
>     ./config shared no-asm -ansi -D_DEFAULT_SOURCE=__STRICT_ANSI__
>
> I'm not sure if Configure should set
> _DEFAULT_SOURCE=__STRICT_ANSI__automatically.
>
> ****
>
> $ git diff > ansi.patch
> $ cat ansi.patch
> diff --git a/crypto/async/arch/async_posix.h b/crypto/async/arch/async_posix.h
> index de80f95..968358f 100644
> --- a/crypto/async/arch/async_posix.h
> +++ b/crypto/async/arch/async_posix.h
> @@ -74,7 +74,7 @@ typedef struct async_fibre_st {
>      int env_init;
>  } async_fibre;
>
> -static inline int async_fibre_swapcontext(async_fibre *o, async_fibre
> *n, int r)
> +static ossl_inline int async_fibre_swapcontext(async_fibre *o,
> async_fibre *n, int r)
>  {
>      o->env_init = 1;
>
> diff --git a/engines/afalg/e_afalg.c b/engines/afalg/e_afalg.c
> index 3ccf9d5..1914be5 100644
> --- a/engines/afalg/e_afalg.c
> +++ b/engines/afalg/e_afalg.c
> @@ -136,27 +136,27 @@ static int afalg_cipher_nids[] = {
>
>  static EVP_CIPHER *_hidden_aes_128_cbc = NULL;
>
> -static inline int io_setup(unsigned n, aio_context_t *ctx)
> +static ossl_inline int io_setup(unsigned n, aio_context_t *ctx)
>  {
>      return syscall(__NR_io_setup, n, ctx);
>  }
>
> -static inline int eventfd(int n)
> +static ossl_inline int eventfd(int n)
>  {
>      return syscall(__NR_eventfd, n);
>  }
>
> -static inline int io_destroy(aio_context_t ctx)
> +static ossl_inline int io_destroy(aio_context_t ctx)
>  {
>      return syscall(__NR_io_destroy, ctx);
>  }
>
> -static inline int io_read(aio_context_t ctx, long n, struct iocb **iocb)
> +static ossl_inline int io_read(aio_context_t ctx, long n, struct iocb **iocb)
>  {
>      return syscall(__NR_io_submit, ctx, n, iocb);
>  }
>
> -static inline int io_getevents(aio_context_t ctx, long min, long max,
> +static ossl_inline int io_getevents(aio_context_t ctx, long min, long max,
>                                 struct io_event *events,
>                                 struct timespec *timeout)
>  {
> @@ -272,7 +272,7 @@ int afalg_fin_cipher_aio(afalg_aio *aio, int sfd,
> unsigned char *buf,
>      memset(cb, '\0', sizeof(*cb));
>      cb->aio_fildes = sfd;
>      cb->aio_lio_opcode = IOCB_CMD_PREAD;
> -    cb->aio_buf = (unsigned long)buf;
> +    cb->aio_buf = (uint64_t)buf;
>      cb->aio_offset = 0;
>      cb->aio_data = 0;
>      cb->aio_nbytes = len;
> @@ -352,7 +352,7 @@ int afalg_fin_cipher_aio(afalg_aio *aio, int sfd,
> unsigned char *buf,
>      return 1;
>  }
>
> -static inline void afalg_set_op_sk(struct cmsghdr *cmsg,
> +static ossl_inline void afalg_set_op_sk(struct cmsghdr *cmsg,
>                                     const unsigned int op)
>  {
>      cmsg->cmsg_level = SOL_ALG;
> @@ -374,7 +374,7 @@ static void afalg_set_iv_sk(struct cmsghdr *cmsg,
> const unsigned char *iv,
>      memcpy(aiv->iv, iv, len);
>  }
>
> -static inline int afalg_set_key(afalg_ctx *actx, const unsigned char *key,
> +static ossl_inline int afalg_set_key(afalg_ctx *actx, const unsigned char 
> *key,
>                                  const int klen)
>  {
>      int ret;
> diff --git a/include/openssl/e_os2.h b/include/openssl/e_os2.h
> index bbd6116..73058c0 100644
> --- a/include/openssl/e_os2.h
> +++ b/include/openssl/e_os2.h
> @@ -264,7 +264,15 @@ extern "C" {
>
>  # ifndef ossl_ssize_t
>  #  define ossl_ssize_t ssize_t
> -#  define OSSL_SSIZE_MAX SSIZE_MAX
> +#  if defined(SSIZE_MAX)
> +#   define OSSL_SSIZE_MAX SSIZE_MAX
> +#  elif defined(_POSIX_SSIZE_MAX)
> +#   define OSSL_SSIZE_MAX _POSIX_SSIZE_MAX
> +#  elif (__WORDSIZE == 64)
> +#   define OSSL_SSIZE_MAX LONG_MAX
> +#  elif(__WORDSIZE == 32)
> +#   define OSSL_SSIZE_MAX INT_MAX
> +#  endif
>  # endif
>
>  # ifdef DEBUG_UNUSED
> diff --git a/test/ssltest.c b/test/ssltest.c
> index a2dd445..6c1575c 100644
> --- a/test/ssltest.c
> +++ b/test/ssltest.c
> @@ -140,8 +140,12 @@
>   */
>
>  /* Or gethostname won't be declared properly on Linux and GNU platforms. */
> -#define _BSD_SOURCE 1
> -#define _DEFAULT_SOURCE 1
> +#ifndef _BSD_SOURCE
> +# define _BSD_SOURCE 1
> +#endif
> +#ifndef _DEFAULT_SOURCE
> +# define _DEFAULT_SOURCE 1
> +#endif
>
>  #include <assert.h>
>  #include <errno.h>
diff --git a/apps/apps.c b/apps/apps.c
index 128f387..111a6f0 100644
--- a/apps/apps.c
+++ b/apps/apps.c
@@ -108,6 +108,13 @@
  *
  */
 
+/* ANSI C is too restrictive for this utility */
+#if defined(__STRICT_ANSI__)
+# ifndef _DEFAULT_SOURCE
+#  define _DEFAULT_SOURCE 1
+# endif
+#endif
+
 #if !defined(_POSIX_C_SOURCE) && defined(OPENSSL_SYS_VMS)
 /*
  * On VMS, you need to define this to get the declaration of fileno().  The
diff --git a/apps/rehash.c b/apps/rehash.c
index 38084a2..ec62ac8 100644
--- a/apps/rehash.c
+++ b/apps/rehash.c
@@ -57,6 +57,13 @@
  *
  */
 
+/* ANSI C is too restrictive for this utility */
+#if defined(__STRICT_ANSI__)
+# ifndef _DEFAULT_SOURCE
+#  define _DEFAULT_SOURCE 1
+# endif
+#endif
+
 #include "apps.h"
 
 #if defined(OPENSSL_SYS_UNIX) || defined(__APPLE__)
diff --git a/apps/s_client.c b/apps/s_client.c
index 5b4cd48..3f931da 100644
--- a/apps/s_client.c
+++ b/apps/s_client.c
@@ -134,6 +134,13 @@
  * OTHERWISE.
  */
 
+/* ANSI C is too restrictive for this utility */
+#if defined(__STRICT_ANSI__)
+# ifndef _DEFAULT_SOURCE
+#  define _DEFAULT_SOURCE 1
+# endif
+#endif
+
 #include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/apps/s_server.c b/apps/s_server.c
index 08acc47..d8d0779 100644
--- a/apps/s_server.c
+++ b/apps/s_server.c
@@ -139,6 +139,13 @@
  * OTHERWISE.
  */
 
+/* ANSI C is too restrictive for this utility */
+#if defined(__STRICT_ANSI__)
+# ifndef _DEFAULT_SOURCE
+#  define _DEFAULT_SOURCE 1
+# endif
+#endif
+
 #include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/apps/speed.c b/apps/speed.c
index 409f3a9..6e2826b 100644
--- a/apps/speed.c
+++ b/apps/speed.c
@@ -68,6 +68,13 @@
  *
  */
 
+/* ANSI C is too restrictive for this utility */
+#if defined(__STRICT_ANSI__)
+# ifndef _DEFAULT_SOURCE
+#  define _DEFAULT_SOURCE 1
+# endif
+#endif
+
 #undef SECONDS
 #define SECONDS                 3
 #define PRIME_SECONDS   10
diff --git a/crypto/async/arch/async_posix.h b/crypto/async/arch/async_posix.h
index de80f95..968358f 100644
--- a/crypto/async/arch/async_posix.h
+++ b/crypto/async/arch/async_posix.h
@@ -74,7 +74,7 @@ typedef struct async_fibre_st {
     int env_init;
 } async_fibre;
 
-static inline int async_fibre_swapcontext(async_fibre *o, async_fibre *n, int r)
+static ossl_inline int async_fibre_swapcontext(async_fibre *o, async_fibre *n, int r)
 {
     o->env_init = 1;
 
diff --git a/crypto/bio/b_addr.c b/crypto/bio/b_addr.c
index 0a6c5e9..e8b13d3 100644
--- a/crypto/bio/b_addr.c
+++ b/crypto/bio/b_addr.c
@@ -767,7 +767,9 @@ int BIO_lookup(const char *host, const char *service,
             if (he == NULL) {
 #ifndef OPENSSL_SYS_WINDOWS
                 BIOerr(BIO_F_BIO_LOOKUP, ERR_R_SYS_LIB);
+# ifndef __STRICT_ANSI__ 
                 ERR_add_error_data(1, hstrerror(h_errno));
+# endif
 #else
                 SYSerr(SYS_F_GETHOSTBYNAME, WSAGetLastError());
 #endif
@@ -803,7 +805,9 @@ int BIO_lookup(const char *host, const char *service,
                 if (se == NULL) {
 #ifndef OPENSSL_SYS_WINDOWS
                     BIOerr(BIO_F_BIO_LOOKUP, ERR_R_SYS_LIB);
+# ifndef __STRICT_ANSI__ 
                     ERR_add_error_data(1, hstrerror(h_errno));
+# endif
 #else
                     SYSerr(SYS_F_GETSERVBYNAME, WSAGetLastError());
 #endif
diff --git a/crypto/bio/bss_dgram.c b/crypto/bio/bss_dgram.c
index cf2f9f6..6b0a36d 100644
--- a/crypto/bio/bss_dgram.c
+++ b/crypto/bio/bss_dgram.c
@@ -424,7 +424,7 @@ static long dgram_get_mtu_overhead(bio_dgram_data *data)
          */
         ret = 28;
         break;
-# ifdef AF_INET6
+# if defined(OPENSSL_USE_IPV6) && !defined(__STRICT_ANSI__)
     case AF_INET6:
         {
 #  ifdef IN6_IS_ADDR_V4MAPPED
@@ -595,7 +595,7 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
         case AF_INET:
             ret += 576;
             break;
-# if OPENSSL_USE_IPV6
+# if OPENSSL_USE_IPV6 && !defined(__STRICT_ANSI__)
         case AF_INET6:
             {
 #  ifdef IN6_IS_ADDR_V4MAPPED
diff --git a/crypto/conf/conf_lib.c b/crypto/conf/conf_lib.c
index f197714..7bc3ac0 100644
--- a/crypto/conf/conf_lib.c
+++ b/crypto/conf/conf_lib.c
@@ -392,7 +392,7 @@ void OPENSSL_INIT_set_config_filename(OPENSSL_INIT_SETTINGS *settings,
                                       const char *config_file)
 {
     free(settings->config_name);
-    settings->config_name = config_file == NULL ? NULL : strdup(config_file);
+    settings->config_name = config_file == NULL ? NULL : OPENSSL_strdup(config_file);
 }
 #endif
 
diff --git a/crypto/conf/conf_sap.c b/crypto/conf/conf_sap.c
index 2198c2f..cef7978 100644
--- a/crypto/conf/conf_sap.c
+++ b/crypto/conf/conf_sap.c
@@ -79,7 +79,7 @@ void OPENSSL_config(const char *config_name)
 
     memset(&settings, 0, sizeof(settings));
     if (config_name != NULL)
-        settings.config_name = strdup(config_name);
+        settings.config_name = OPENSSL_strdup(config_name);
     OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, &settings);
 }
 #endif
diff --git a/crypto/o_time.c b/crypto/o_time.c
index 75aa2e5..7aace72 100644
--- a/crypto/o_time.c
+++ b/crypto/o_time.c
@@ -83,7 +83,7 @@ struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result)
 {
     struct tm *ts = NULL;
 
-#if defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32) && (!defined(OPENSSL_SYS_VMS) || defined(gmtime_r)) && !defined(OPENSSL_SYS_MACOSX)
+#if defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32) && (!defined(OPENSSL_SYS_VMS) || defined(gmtime_r)) && !defined(OPENSSL_SYS_MACOSX) && !defined(__STRICT_ANSI__)
     /*
      * should return &data, but doesn't on some systems, so we don't even
      * look at the return value
diff --git a/crypto/rand/randfile.c b/crypto/rand/randfile.c
index a5b2b7f..a425dca 100644
--- a/crypto/rand/randfile.c
+++ b/crypto/rand/randfile.c
@@ -77,7 +77,7 @@
 #ifndef NO_SYS_TYPES_H
 # include <sys/types.h>
 #endif
-#ifndef OPENSSL_NO_POSIX_IO
+#if !defined(OPENSSL_NO_POSIX_IO) || defined(__STRICT_ANSI__)
 # include <sys/stat.h>
 # include <fcntl.h>
 #endif
@@ -188,7 +188,7 @@ int RAND_write_file(const char *file)
     unsigned char buf[BUFSIZE];
     int i, ret = 0, rand_err = 0;
     FILE *out = NULL;
-    int n;
+    int fd, n;
 #ifndef OPENSSL_NO_POSIX_IO
     struct stat sb;
 
@@ -213,13 +213,20 @@ int RAND_write_file(const char *file)
 # ifndef O_BINARY
 #  define O_BINARY 0
 # endif
+
         /*
-         * chmod(..., 0600) is too late to protect the file, permissions
-         * should be restrictive from the start
-         */
-        int fd = open(file, O_WRONLY | O_CREAT | O_BINARY, 0600);
+         * chmod(..., 0600) is too late to protect the file, permissions should
+         * be restrictive from the start. However, ANSI C lacks fdopen.
+         */	
+# if defined(__STRICT_ANSI__)
+        out = fopen(file, "wb");
+        chmod(file, 0600);
+        (void)fd;
+# else
+        fd = open(file, O_WRONLY | O_CREAT | O_BINARY, 0600);
         if (fd != -1)
             out = fdopen(fd, "wb");
+# endif
     }
 #endif
 
diff --git a/crypto/threads_pthread.c b/crypto/threads_pthread.c
index edca77c..306b8c9 100644
--- a/crypto/threads_pthread.c
+++ b/crypto/threads_pthread.c
@@ -47,6 +47,13 @@
  * ====================================================================
  */
 
+/* ANSI C is too restrictive for this source file */
+#if defined(__STRICT_ANSI__)
+# ifndef _DEFAULT_SOURCE
+#  define _DEFAULT_SOURCE 1
+# endif
+#endif
+
 #include <openssl/crypto.h>
 #include "internal/threads.h"
 
diff --git a/crypto/ui/ui_openssl.c b/crypto/ui/ui_openssl.c
index 7fc3e17..b301988 100644
--- a/crypto/ui/ui_openssl.c
+++ b/crypto/ui/ui_openssl.c
@@ -115,6 +115,13 @@
  * [including the GNU Public Licence.]
  */
 
+/* ANSI C is too restrictive for this utility */
+#if defined(__STRICT_ANSI__)
+# ifndef _DEFAULT_SOURCE
+#  define _DEFAULT_SOURCE 1
+# endif
+#endif
+
 #include <openssl/e_os2.h>
 
 /*
@@ -147,7 +154,7 @@
  * If unistd.h defines _POSIX_VERSION, we conclude that we are on a POSIX
  * system and have sigaction and termios.
  */
-# if defined(_POSIX_VERSION)
+# if defined(_POSIX_VERSION) && !defined(__STRICT_ANSI__) 
 
 #  define SIGACTION
 #  if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
diff --git a/e_os.h b/e_os.h
index f0a441e..120d26a 100644
--- a/e_os.h
+++ b/e_os.h
@@ -328,6 +328,13 @@ extern FILE *_imp___iob;
 
 # else                          /* The non-microsoft world */
 
+# include <stdio.h>
+# include <stdlib.h>
+# include <limits.h>
+# include <unistd.h>
+# include <sys/select.h>
+# include <sys/time.h>
+
 #  ifdef OPENSSL_SYS_VMS
 #   define VMS 1
   /*
@@ -520,7 +527,7 @@ struct servent *PASCAL getservbyname(const char *, const char *);
 # if defined(OPENSSL_SYS_WINDOWS)
 #  define strcasecmp _stricmp
 #  define strncasecmp _strnicmp
-# elif defined(OPENSSL_SYS_VMS)
+# elif defined(OPENSSL_SYS_VMS) || defined(__STRICT_ANSI__)
 /* VMS below version 7.0 doesn't have strcasecmp() */
 #  include "internal/o_str.h"
 #  define strcasecmp OPENSSL_strcasecmp
diff --git a/engines/afalg/e_afalg.c b/engines/afalg/e_afalg.c
index 3ccf9d5..1914be5 100644
--- a/engines/afalg/e_afalg.c
+++ b/engines/afalg/e_afalg.c
@@ -136,27 +136,27 @@ static int afalg_cipher_nids[] = {
 
 static EVP_CIPHER *_hidden_aes_128_cbc = NULL;
 
-static inline int io_setup(unsigned n, aio_context_t *ctx)
+static ossl_inline int io_setup(unsigned n, aio_context_t *ctx)
 {
     return syscall(__NR_io_setup, n, ctx);
 }
 
-static inline int eventfd(int n)
+static ossl_inline int eventfd(int n)
 {
     return syscall(__NR_eventfd, n);
 }
 
-static inline int io_destroy(aio_context_t ctx)
+static ossl_inline int io_destroy(aio_context_t ctx)
 {
     return syscall(__NR_io_destroy, ctx);
 }
 
-static inline int io_read(aio_context_t ctx, long n, struct iocb **iocb)
+static ossl_inline int io_read(aio_context_t ctx, long n, struct iocb **iocb)
 {
     return syscall(__NR_io_submit, ctx, n, iocb);
 }
 
-static inline int io_getevents(aio_context_t ctx, long min, long max,
+static ossl_inline int io_getevents(aio_context_t ctx, long min, long max,
                                struct io_event *events,
                                struct timespec *timeout)
 {
@@ -272,7 +272,7 @@ int afalg_fin_cipher_aio(afalg_aio *aio, int sfd, unsigned char *buf,
     memset(cb, '\0', sizeof(*cb));
     cb->aio_fildes = sfd;
     cb->aio_lio_opcode = IOCB_CMD_PREAD;
-    cb->aio_buf = (unsigned long)buf;
+    cb->aio_buf = (uint64_t)buf;
     cb->aio_offset = 0;
     cb->aio_data = 0;
     cb->aio_nbytes = len;
@@ -352,7 +352,7 @@ int afalg_fin_cipher_aio(afalg_aio *aio, int sfd, unsigned char *buf,
     return 1;
 }
 
-static inline void afalg_set_op_sk(struct cmsghdr *cmsg,
+static ossl_inline void afalg_set_op_sk(struct cmsghdr *cmsg,
                                    const unsigned int op)
 {
     cmsg->cmsg_level = SOL_ALG;
@@ -374,7 +374,7 @@ static void afalg_set_iv_sk(struct cmsghdr *cmsg, const unsigned char *iv,
     memcpy(aiv->iv, iv, len);
 }
 
-static inline int afalg_set_key(afalg_ctx *actx, const unsigned char *key,
+static ossl_inline int afalg_set_key(afalg_ctx *actx, const unsigned char *key,
                                 const int klen)
 {
     int ret;
diff --git a/include/openssl/e_os2.h b/include/openssl/e_os2.h
index bbd6116..216aebf 100644
--- a/include/openssl/e_os2.h
+++ b/include/openssl/e_os2.h
@@ -257,14 +257,20 @@ extern "C" {
 #  endif
 # endif
 
-# if defined(OPENSSL_SYS_UEFI) && !defined(ssize_t)
-#  define ossl_ssize_t int
-#  define OSSL_SSIZE_MAX INT_MAX
-# endif
-
-# ifndef ossl_ssize_t
+# if defined(SSIZE_MAX)
 #  define ossl_ssize_t ssize_t
 #  define OSSL_SSIZE_MAX SSIZE_MAX
+# else /* not SSIZE_MAX */
+#  if (__WORDSIZE == 64) || (__SIZEOF_PTRDIFF_T__ == 8) || (__LP64__ == 1)
+#   define ossl_ssize_t long
+#   define OSSL_SSIZE_MAX LONG_MAX
+#  elif (__WORDSIZE == 32) || (__SIZEOF_PTRDIFF_T__ == 4)
+#   define ossl_ssize_t int
+#   define OSSL_SSIZE_MAX INT_MAX
+#  else
+#   define ossl_ssize_t ssize_t
+#   define OSSL_SSIZE_MAX SSIZE_MAX
+#  endif
 # endif
 
 # ifdef DEBUG_UNUSED
diff --git a/test/ssltest.c b/test/ssltest.c
index a2dd445..6c1575c 100644
--- a/test/ssltest.c
+++ b/test/ssltest.c
@@ -140,8 +140,12 @@
  */
 
 /* Or gethostname won't be declared properly on Linux and GNU platforms. */
-#define _BSD_SOURCE 1
-#define _DEFAULT_SOURCE 1
+#ifndef _BSD_SOURCE
+# define _BSD_SOURCE 1
+#endif
+#ifndef _DEFAULT_SOURCE
+# define _DEFAULT_SOURCE 1
+#endif
 
 #include <assert.h>
 #include <errno.h>
-- 
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev

Reply via email to