autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Check types of structures


From: Jason Curl
Subject: Re: Check types of structures
Date: Mon, 26 Nov 2007 12:26:31 +0100
User-agent: Thunderbird 2.0.0.9 (Windows/20071031)

Jason Curl wrote:
On Interix, the type for "struct timeval.tv_usec" is "long", while on Linux it is "suseconds_t".
Well, I've finally come to a solution and written some macros to deal with this. It is a good start for people who want to do something equivalent, but it assumes
* gettimeofday() exists on your system
* The appropriate headers <sys/time.h> or <time.h> exist
* The structure timeval exists
* Macros AC_CHECK_SIZEOF() called for char, short, int, long and long long.
* Tested on Linux and Interix 3.5 as part of my project.

Comments are most welcome.

# _LX_TYPE_SUSECONDS_T_EQUIV
# --------------------------
# Gets the size of the element 'struct timeval.tv_usec' and compares it
# against the sizes of built in simple types. We assume this element is signed
#
# It automatically sets the variable 'time_t' to the equivalent type (like
# the macros AC_TYPE_UINT64_T does). This shouldn't be called unless we know
# that the type 'time_t' doesn't exist.
#
# See also: LX_TYPE_SUSECONDS_T
AC_DEFUN([_LX_TYPE_SUSECONDS_T_EQUIV],
 [AC_MSG_CHECKING([for suseconds_t equivalent])
  AC_COMPUTE_INT([lx_cv_sizeof_suseconds_t],
    [(long int)(sizeof(lx__var_sizeof_.tv_usec))],
    [#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
#  include <sys/time.h>
# else
#  include <time.h>
# endif
#endif
     AC_INCLUDES_DEFAULT([])
     static struct timeval lx__var_sizeof_;],
    [lx_cv_sizeof_time_t=0])

  # We've looked for the size of the type in the structure 'timeval'. Look
  # for an equivalent
  if test x$ac_cv_sizeof_char = x$lx_cv_sizeof_time_t; then
     lx_cv_type_suseconds_t=char
  elif test x$ac_cv_sizeof_short = x$lx_cv_sizeof_time_t; then
     lx_cv_type_suseconds_t=short
  elif test x$ac_cv_sizeof_int = x$lx_cv_sizeof_time_t; then
     lx_cv_type_suseconds_t=int
  elif test x$ac_cv_sizeof_long = x$lx_cv_sizeof_time_t; then
     lx_cv_type_suseconds_t=long
  elif test x$ac_cv_sizeof_long_long = x$lx_cv_sizeof_time_t; then
     lx_cv_type_suseconds_t="long long"
  else
     # We couldn't get the type
     lx_cv_type_suseconds_t=long
  fi

AC_DEFINE_UNQUOTED([suseconds_t], $lx_cv_type_suseconds_t, [Equivalent type for suseconds_t for systems that don't have suseconds_t (e.g. Interix 3.5])

  AC_MSG_RESULT([$lx_cv_type_suseconds_t])
])

# LX_TYPE_SUSECONDS_T
# -------------------
# Looks for the type 'suseconds_t' and if not found, define an equivalent type.
AC_DEFUN([LX_TYPE_SUSECONDS_T],
 [AC_CHECK_TYPE([suseconds_t],
    [],
    [_LX_TYPE_SUSECONDS_T_EQUIV],
    [#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
#  include <sys/time.h>
# else
#  include <time.h>
# endif
#endif
  ])
])





reply via email to

[Prev in Thread] Current Thread [Next in Thread]