Commit 69565afa authored by Yang Tse's avatar Yang Tse
Browse files

Check for stdbool.h at configuration stage, and include it if available.

Check for lowercase 'bool' type at configuration stage. If not available
provide a suitable replacement with a type definition of 'unsigned char'
in setup_once.h

Move definitions of TRUE and FALSE to setup_once.h
parent 39aac635
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -54,10 +54,6 @@
#include "ares_dns.h"
#include "ares_private.h"

#ifndef TRUE
/* at least Solaris 7 does not have TRUE at this point */
#define TRUE 1
#endif

static int try_again(int errnum);
static void write_tcp_data(ares_channel channel, fd_set *write_fds,
@@ -532,7 +528,7 @@ static int nonblock(ares_socket_t sockfd, /* operate on this */
  int flags;

  flags = fcntl(sockfd, F_GETFL, 0);
  if (TRUE == nonblock)
  if (FALSE != nonblock)
    return fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
  else
    return fcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK));
+12 −0
Original line number Diff line number Diff line
@@ -308,6 +308,8 @@ AC_CHECK_HEADERS(
       netdb.h \
       netinet/in.h \
       net/if.h \
       errno.h \
       stdbool.h \
       arpa/nameser.h \
       arpa/nameser_compat.h \
       arpa/inet.h,
@@ -369,6 +371,16 @@ fi
AC_CHECK_TYPE(ssize_t, ,
   AC_DEFINE(ssize_t, int, [the signed version of size_t]))

# check for bool type
AC_CHECK_TYPE([bool],[
  AC_DEFINE(HAVE_BOOL_T, 1,
    [Define to 1 if bool is an available type.])
], ,[
#ifdef HAVE_STDBOOL_H
#include <stdbool.h>
#endif
])

# Check for socklen_t or equivalent
CURL_CHECK_TYPE_SOCKLEN_T

+26 −0
Original line number Diff line number Diff line
@@ -62,6 +62,10 @@
#include <fcntl.h>
#endif

#ifdef HAVE_STDBOOL_H
#include <stdbool.h>
#endif


/*
 * Definition of timeval struct for platforms that don't have it.
@@ -176,6 +180,28 @@ struct timeval {
                          (((unsigned char)x) == '\t'))


/*
 * Typedef to 'unsigned char' if bool is not an available 'typedefed' type.
 */

#ifndef HAVE_BOOL_T
typedef unsigned char bool;
#define HAVE_BOOL_T
#endif


/*
 * Default definition of uppercase TRUE and FALSE.
 */

#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif


/*
 * Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
 */
+11 −0
Original line number Diff line number Diff line
@@ -1662,6 +1662,7 @@ AC_CHECK_HEADERS(
        libgen.h \
        locale.h \
        errno.h \
        stdbool.h \
        arpa/tftp.h \
        sys/filio.h \
        setjmp.h,
@@ -1723,6 +1724,16 @@ fi
AC_CHECK_TYPE(ssize_t, ,
   AC_DEFINE(ssize_t, int, [the signed version of size_t]))

# check for bool type
AC_CHECK_TYPE([bool],[
  AC_DEFINE(HAVE_BOOL_T, 1,
    [Define to 1 if bool is an available type.])
], ,[
#ifdef HAVE_STDBOOL_H
#include <stdbool.h>
#endif
])

# Check for socklen_t or equivalent
CURL_CHECK_TYPE_SOCKLEN_T

+1 −6
Original line number Diff line number Diff line
@@ -79,11 +79,6 @@
#include <errno.h>
#include <string.h>

#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif

#include "urldata.h"
#include "sendf.h"
#include "if2ip.h"
@@ -122,7 +117,7 @@ int Curl_nonblock(curl_socket_t sockfd, /* operate on this */
  int flags;

  flags = fcntl(sockfd, F_GETFL, 0);
  if (TRUE == nonblock)
  if (FALSE != nonblock)
    return fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
  else
    return fcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK));
Loading