bug-coreutils
[Top][All Lists]
Advanced

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

coreutils md5, sha1, memchr etc port to Solaris 8 + Forte 6U2 cc


From: Paul Eggert
Subject: coreutils md5, sha1, memchr etc port to Solaris 8 + Forte 6U2 cc
Date: Sun, 01 Aug 2004 22:40:11 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

My recent changes to coreutils ran afoul of Sun Forte 6 Update 2 on
Solaris 8.  This implementation predates C99, but it has some C99
features, but not quite defined right, and perhaps not in the correct
include files (e.g., inttypes.h rather than stdint.h).  Among other
things, UINTPTR_MAX and INTPTR_MAX are defined to be empty (!).

I installed the following patch to work around this portability
problem, and to migrate more of the portability hacks out of the C
source code and into the Autoconf macros.  This lets the source code
itself assume more C99 features.

2004-08-01  Paul Eggert  <address@hidden>

        * lib/md5.c (UNALIGNED_P): Use size_t; in practice, this is just as
        good as uintptr_t in checking for alignments, and has fewer
        configuration hassles.
        * lib/sha1.c (UNALIGNED_P): Likewise.
        * lib/md5.h: Don't include <limits.h>.  Include <inttypes.h> if
        available, as it defines symbols like UINT32_MAX on Solaris 8.
        (md5_uint32): Assume uint32_t exists; Autoconf will define it
        otherwise (if the host has a 32-bit unsigned type, anyway).
        * lib/memchr.c: Don't include inttypes.h or stdint.h.
        (UNALIGNED_P): Remove.
        (__memchr): Use size_t, not uintptr_t, to test alignment.
        * lib/memrchr.c: Likewise, for __memrchr.

        * m4/jm-macros.m4 (gl_CHECK_ALL_TYPES):
        Require gl_AC_TYPE_UINTPTR_T instead of using AC_CHECK_TYPE
        on uintptr_t.  Require gl_AC_TYPE_UINT32_T.
        * m4/md5.m4 (gl_MD5): Require gl_AC_TYPE_UINT32_T.
        * m4/uint32_t.m4, m4/uintptr_t.m4: New files.

        * src/cut.c (hash_int) [!defined UINTPTR_MAX]: Use size_t
        instead of uintptr_t.
        * src/shred.c (UINT_MAX_32_BITS): Remove.
        (word32): Remove.  All uses changed to uint32_t.
        (isaac_seed_data): Remove unnecessary cast.
        * src/system.h (ptr_align): Use size_t; in practice, this is just as
        good as uintptr_t in checking for alignments, and has fewer
        configuration hassles.

Index: lib/md5.c
===================================================================
RCS file: /home/eggert/coreutils/cu/lib/md5.c,v
retrieving revision 1.19
diff -p -u -r1.19 md5.c
--- lib/md5.c   28 Jul 2004 20:09:39 -0000      1.19
+++ lib/md5.c   2 Aug 2004 03:43:54 -0000
@@ -245,11 +245,7 @@ md5_process_bytes (const void *buffer, s
     {
 #if !_STRING_ARCH_unaligned
 # define alignof(type) offsetof (struct { char c; type x; }, x)
-# ifdef UINTPTR_MAX
-#  define UNALIGNED_P(p) (((uintptr_t) p) % alignof (md5_uint32) != 0)
-# else
-#  define UNALIGNED_P(p) 1
-# endif
+# define UNALIGNED_P(p) (((size_t) p) % alignof (md5_uint32) != 0)
       if (UNALIGNED_P (buffer))
        while (len > 64)
          {
Index: lib/md5.h
===================================================================
RCS file: /home/eggert/coreutils/cu/lib/md5.h,v
retrieving revision 1.16
diff -p -u -r1.16 md5.h
--- lib/md5.h   28 Jul 2004 20:09:09 -0000      1.16
+++ lib/md5.h   2 Aug 2004 04:41:38 -0000
@@ -25,31 +25,15 @@
 #define _MD5_H 1
 
 #include <stdio.h>
-#include <limits.h>
-
-/* The following contortions are an attempt to use the C preprocessor
-   to determine an unsigned integral type that is exactly 32 bits wide.  */
 
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
 #if HAVE_STDINT_H || _LIBC
 # include <stdint.h>
 #endif
 
-#ifdef UINT32_MAX
 typedef uint32_t md5_uint32;
-#else
-# define UINT_MAX_32_BITS 4294967295U
-# if UINT_MAX == UINT_MAX_32_BITS
-   typedef unsigned int md5_uint32;
-# elif USHRT_MAX == UINT_MAX_32_BITS
-   typedef unsigned short int md5_uint32;
-# elif ULONG_MAX == UINT_MAX_32_BITS
-   typedef unsigned long md5_uint32;
-# else
-   /* The following line is intended to evoke an error.
-      Using #error is not portable enough.  */
-   "Cannot determine unsigned 32-bit data type."
-# endif
-#endif
 
 /* Structure to save state of computation between the single steps.  */
 struct md5_ctx
Index: lib/memchr.c
===================================================================
RCS file: /home/eggert/coreutils/cu/lib/memchr.c,v
retrieving revision 1.19
diff -p -u -r1.19 memchr.c
--- lib/memchr.c        30 Jul 2004 00:40:40 -0000      1.19
+++ lib/memchr.c        2 Aug 2004 03:50:42 -0000
@@ -41,22 +41,6 @@ USA.  */
 
 #include <limits.h>
 
-#if HAVE_INTTYPES_H
-# include <inttypes.h>
-#endif
-#if defined _LIBC || HAVE_STDINT_H
-# include <stdint.h>
-#endif
-
-/* Use sizeof, not alignof, for better performance on some hosts.  For
-   example, on m68k-linux alignof (type) will always be at most 2, but
-   you get better performance with a 4-byte aligned pointer.  */
-#ifdef UINTPTR_MAX
-# define UNALIGNED_P(p) (((uintptr_t) p) % sizeof (unsigned long int) != 0)
-#else
-# define UNALIGNED_P(p) 1
-#endif
-
 #if HAVE_BP_SYM_H || defined _LIBC
 # include <bp-sym.h>
 #else
@@ -81,7 +65,7 @@ __memchr (void const *s, int c_in, size_
   /* Handle the first few characters by reading one character at a time.
      Do this until CHAR_PTR is aligned on a longword boundary.  */
   for (char_ptr = (const unsigned char *) s;
-       n > 0 && UNALIGNED_P (char_ptr);
+       n > 0 && (size_t) char_ptr % sizeof longword != 0;
        --n, ++char_ptr)
     if (*char_ptr == c)
       return (void *) char_ptr;
Index: lib/memrchr.c
===================================================================
RCS file: /home/eggert/coreutils/cu/lib/memrchr.c,v
retrieving revision 1.6
diff -p -u -r1.6 memrchr.c
--- lib/memrchr.c       29 Jul 2004 17:34:20 -0000      1.6
+++ lib/memrchr.c       2 Aug 2004 03:50:26 -0000
@@ -39,22 +39,6 @@
 
 #include <limits.h>
 
-#if HAVE_INTTYPES_H
-# include <inttypes.h>
-#endif
-#if defined _LIBC || HAVE_STDINT_H
-# include <stdint.h>
-#endif
-
-/* Use sizeof, not alignof, for better performance on some hosts.  For
-   example, on m68k-linux alignof (type) will always be at most 2, but
-   you get better performance with a 4-byte aligned pointer.  */
-#ifdef UINTPTR_MAX
-# define UNALIGNED_P(p) (((uintptr_t) p) % sizeof (unsigned long int) != 0)
-#else
-# define UNALIGNED_P(p) 1
-#endif
-
 #undef __memrchr
 #undef memrchr
 
@@ -77,7 +61,7 @@ __memrchr (void const *s, int c_in, size
   /* Handle the last few characters by reading one character at a time.
      Do this until CHAR_PTR is aligned on a longword boundary.  */
   for (char_ptr = (const unsigned char *) s + n;
-       n > 0 && UNALIGNED_P (char_ptr);
+       n > 0 && (size_t) char_ptr % sizeof longword != 0;
        --n)
     if (*--char_ptr == c)
       return (void *) char_ptr;
Index: lib/sha1.c
===================================================================
RCS file: /home/eggert/coreutils/cu/lib/sha1.c,v
retrieving revision 1.2
diff -p -u -r1.2 sha1.c
--- lib/sha1.c  28 Jul 2004 20:09:57 -0000      1.2
+++ lib/sha1.c  2 Aug 2004 03:43:32 -0000
@@ -243,11 +243,7 @@ sha_process_bytes (const void *buffer, s
     {
 #if !_STRING_ARCH_unaligned
 # define alignof(type) offsetof (struct { char c; type x; }, x)
-# ifdef UINTPTR_MAX
-#  define UNALIGNED_P(p) (((uintptr_t) p) % alignof (md5_uint32) != 0)
-# else
-#  define UNALIGNED_P(p) 1
-# endif
+# define UNALIGNED_P(p) (((size_t) p) % alignof (md5_uint32) != 0)
       if (UNALIGNED_P (buffer))
        while (len > 64)
          {
Index: m4/jm-macros.m4
===================================================================
RCS file: /home/eggert/coreutils/cu/m4/jm-macros.m4,v
retrieving revision 1.196
diff -p -u -r1.196 jm-macros.m4
--- m4/jm-macros.m4     25 Jul 2004 23:00:47 -0000      1.196
+++ m4/jm-macros.m4     2 Aug 2004 03:44:31 -0000
@@ -1,4 +1,4 @@
-#serial 73   -*- autoconf -*-
+#serial 74   -*- autoconf -*-
 
 dnl Misc type-related macros for fileutils, sh-utils, textutils.
 
@@ -248,7 +248,6 @@ AC_DEFUN([gl_CHECK_ALL_TYPES],
   AC_REQUIRE([AC_TYPE_SIZE_T])
   AC_REQUIRE([AC_TYPE_UID_T])
   AC_CHECK_TYPE(ino_t, unsigned long int)
-  AC_CHECK_TYPE(uintptr_t, size_t)
 
   gt_TYPE_SSIZE_T
 
@@ -257,7 +256,9 @@ AC_DEFUN([gl_CHECK_ALL_TYPES],
   AC_CHECK_TYPE(major_t, unsigned int)
   AC_CHECK_TYPE(minor_t, unsigned int)
 
+  AC_REQUIRE([gl_AC_TYPE_UINT32_T])
   AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])
+  AC_REQUIRE([gl_AC_TYPE_UINTPTR_T])
   AC_REQUIRE([gl_AC_TYPE_UNSIGNED_LONG_LONG])
 
   AC_REQUIRE([AC_HEADER_MAJOR])
Index: m4/md5.m4
===================================================================
RCS file: /home/eggert/coreutils/cu/m4/md5.m4,v
retrieving revision 1.2
diff -p -u -r1.2 md5.m4
--- m4/md5.m4   28 Jul 2004 20:10:18 -0000      1.2
+++ m4/md5.m4   2 Aug 2004 03:44:59 -0000
@@ -1,4 +1,4 @@
-# md5.m4 serial 4
+# md5.m4 serial 5
 dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
@@ -8,7 +8,8 @@ dnl the same distribution terms as the r
 
 AC_DEFUN([gl_MD5],
 [
-  dnl No prerequisites of lib/md5.h.
+  dnl Prerequisites of lib/md5.h.
+  AC_REQUIRE([gl_AC_TYPE_UINT32_T])
 
   dnl Prerequisites of lib/md5.c.
   AC_REQUIRE([AC_C_BIGENDIAN])
Index: src/cut.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/cut.c,v
retrieving revision 1.112
diff -p -u -r1.112 cut.c
--- src/cut.c   2 Jun 2004 21:20:41 -0000       1.112
+++ src/cut.c   2 Aug 2004 03:42:23 -0000
@@ -242,7 +242,11 @@ is_printable_field (size_t i)
 static size_t
 hash_int (const void *x, size_t tablesize)
 {
+#ifdef UINTPTR_MAX
   uintptr_t y = (uintptr_t) x;
+#else
+  size_t y = (size_t) x;
+#endif
   return y % tablesize;
 }
 
Index: src/shred.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/shred.c,v
retrieving revision 1.99
diff -p -u -r1.99 shred.c
--- src/shred.c 30 Jun 2004 22:31:43 -0000      1.99
+++ src/shred.c 2 Aug 2004 03:54:27 -0000
@@ -235,46 +235,23 @@ to be recovered later.\n\
  * --------------------------------------------------------------------
  */
 
-#if defined __STDC__ && __STDC__
-# define UINT_MAX_32_BITS 4294967295U
-#else
-# define UINT_MAX_32_BITS 0xFFFFFFFF
-#endif
-
-#if ULONG_MAX == UINT_MAX_32_BITS
-typedef unsigned long word32;
-#else
-# if UINT_MAX == UINT_MAX_32_BITS
-typedef unsigned word32;
-# else
-#  if USHRT_MAX == UINT_MAX_32_BITS
-typedef unsigned short word32;
-#  else
-#   if UCHAR_MAX == UINT_MAX_32_BITS
-typedef unsigned char word32;
-#   else
-     "No 32-bit type available!"
-#   endif
-#  endif
-# endif
-#endif
-
 /* Size of the state tables to use.  (You may change ISAAC_LOG) */
 #define ISAAC_LOG 8
 #define ISAAC_WORDS (1 << ISAAC_LOG)
-#define ISAAC_BYTES (ISAAC_WORDS * sizeof (word32))
+#define ISAAC_BYTES (ISAAC_WORDS * sizeof (uint32_t))
 
 /* RNG state variables */
 struct isaac_state
   {
-    word32 mm[ISAAC_WORDS];    /* Main state array */
-    word32 iv[8];              /* Seeding initial vector */
-    word32 a, b, c;            /* Extra index variables */
+    uint32_t mm[ISAAC_WORDS];  /* Main state array */
+    uint32_t iv[8];            /* Seeding initial vector */
+    uint32_t a, b, c;          /* Extra index variables */
   };
 
 /* This index operation is more efficient on many processors */
 #define ind(mm, x) \
-  (* (word32 *) ((char *) (mm) + ((x) & (ISAAC_WORDS - 1) * sizeof (word32))))
+  (* (uint32_t *) ((char *) (mm) \
+                  + ((x) & (ISAAC_WORDS - 1) * sizeof (uint32_t))))
 
 /*
  * The central step.  This uses two temporaries, x and y.  mm is the
@@ -294,11 +271,11 @@ struct isaac_state
  * Refill the entire R array, and update S.
  */
 static void
-isaac_refill (struct isaac_state *s, word32 r[/* ISAAC_WORDS */])
+isaac_refill (struct isaac_state *s, uint32_t r[/* ISAAC_WORDS */])
 {
-  register word32 a, b;                /* Caches of a and b */
-  register word32 x, y;                /* Temps needed by isaac_step macro */
-  register word32 *m = s->mm;  /* Pointer into state array */
+  register uint32_t a, b;              /* Caches of a and b */
+  register uint32_t x, y;              /* Temps needed by isaac_step macro */
+  register uint32_t *m = s->mm;        /* Pointer into state array */
 
   a = s->a;
   b = s->b + (++s->c);
@@ -342,17 +319,17 @@ isaac_refill (struct isaac_state *s, wor
 
 /* The basic ISAAC initialization pass.  */
 static void
-isaac_mix (struct isaac_state *s, word32 const seed[/* ISAAC_WORDS */])
+isaac_mix (struct isaac_state *s, uint32_t const seed[/* ISAAC_WORDS */])
 {
   int i;
-  word32 a = s->iv[0];
-  word32 b = s->iv[1];
-  word32 c = s->iv[2];
-  word32 d = s->iv[3];
-  word32 e = s->iv[4];
-  word32 f = s->iv[5];
-  word32 g = s->iv[6];
-  word32 h = s->iv[7];
+  uint32_t a = s->iv[0];
+  uint32_t b = s->iv[1];
+  uint32_t c = s->iv[2];
+  uint32_t d = s->iv[3];
+  uint32_t e = s->iv[4];
+  uint32_t f = s->iv[5];
+  uint32_t g = s->iv[6];
+  uint32_t h = s->iv[7];
 
   for (i = 0; i < ISAAC_WORDS; i += 8)
     {
@@ -398,9 +375,9 @@ isaac_mix (struct isaac_state *s, word32
  * it is identical.
  */
 static void
-isaac_init (struct isaac_state *s, word32 const *seed, size_t seedsize)
+isaac_init (struct isaac_state *s, uint32_t const *seed, size_t seedsize)
 {
-  static word32 const iv[8] =
+  static uint32_t const iv[8] =
   {
     0x1367df5a, 0x95d90059, 0xc3163e4b, 0x0f421ad8,
     0xd92a4a78, 0xa51a3c49, 0xc4efea1b, 0x30609119};
@@ -447,7 +424,7 @@ isaac_init (struct isaac_state *s, word3
 static void
 isaac_seed_start (struct isaac_state *s)
 {
-  static word32 const iv[8] =
+  static uint32_t const iv[8] =
     {
       0x1367df5a, 0x95d90059, 0xc3163e4b, 0x0f421ad8,
       0xd92a4a78, 0xa51a3c49, 0xc4efea1b, 0x30609119
@@ -503,7 +480,7 @@ isaac_seed_data (struct isaac_state *s, 
   p = (unsigned char *) s->mm + s->c;
   for (i = 0; i < size; i++)
     p[i] ^= ((unsigned char const *) buf)[i];
-  s->c = (word32) size;
+  s->c = size;
 }
 
 
@@ -556,7 +533,7 @@ isaac_seed_machdep (struct isaac_state *
   else
     {
 # if __i386__
-      word32 t[2];
+      uint32_t t[2];
       __asm__ __volatile__ ("rdtsc" : "=a" (t[0]), "=d" (t[1]));
 # endif
 # if __alpha__
@@ -566,12 +543,12 @@ isaac_seed_machdep (struct isaac_state *
 # if _ARCH_PPC
       /* Code not used because this instruction is available only on first-
         generation PPCs and evokes a SIGBUS on some Linux 2.4 kernels.  */
-      word32 t;
+      uint32_t t;
       __asm__ __volatile__ ("mfspr %0,22" : "=r" (t));
 # endif
 # if __mips
       /* Code not used because this is not accessible from userland */
-      word32 t;
+      uint32_t t;
       __asm__ __volatile__ ("mfc0\t%0,$9" : "=r" (t));
 # endif
 # if __sparc__
@@ -658,7 +635,7 @@ isaac_seed (struct isaac_state *s)
 /* Single-word RNG built on top of ISAAC */
 struct irand_state
 {
-  word32 r[ISAAC_WORDS];
+  uint32_t r[ISAAC_WORDS];
   unsigned numleft;
   struct isaac_state *s;
 };
@@ -675,7 +652,7 @@ irand_init (struct irand_state *r, struc
  * only a small number of values, we choose the final ones which are
  * marginally better mixed than the initial ones.
  */
-static word32
+static uint32_t
 irand32 (struct irand_state *r)
 {
   if (!r->numleft)
@@ -697,11 +674,11 @@ irand32 (struct irand_state *r)
  * than 2^32 % n are disallowed, and if the RNG produces one, we ask
  * for a new value.
  */
-static word32
-irand_mod (struct irand_state *r, word32 n)
+static uint32_t
+irand_mod (struct irand_state *r, uint32_t n)
 {
-  word32 x;
-  word32 lim;
+  uint32_t x;
+  uint32_t lim;
 
   if (!++n)
     return irand32 (r);
@@ -747,7 +724,7 @@ fillpattern (int type, unsigned char *r,
  * SIZE is rounded UP to a multiple of ISAAC_BYTES.
  */
 static void
-fillrand (struct isaac_state *s, word32 *r, size_t size_max, size_t size)
+fillrand (struct isaac_state *s, uint32_t *r, size_t size_max, size_t size)
 {
   size = (size + ISAAC_BYTES - 1) / ISAAC_BYTES;
   assert (size <= size_max);
@@ -856,7 +833,7 @@ dopass (int fd, char const *qname, off_t
   size_t lim;                  /* Amount of data to try writing */
   size_t soff;                 /* Offset into buffer for next write */
   ssize_t ssize;               /* Return value from write */
-  word32 *r;                   /* Fill pattern.  */
+  uint32_t *r;                 /* Fill pattern.  */
   size_t rsize = 3 * MAX (ISAAC_WORDS, 1024) * sizeof *r; /* Fill size.  */
   size_t ralign = lcm (getpagesize (), sizeof *r); /* Fill alignment.  */
   char pass_string[PASS_NAME_SIZE];    /* Name of current pass */
@@ -1632,7 +1609,7 @@ main (int argc, char **argv)
          {
            uintmax_t tmp;
            if (xstrtoumax (optarg, NULL, 10, &tmp, NULL) != LONGINT_OK
-               || (word32) tmp != tmp
+               || (uint32_t) tmp != tmp
                || ((size_t) (tmp * sizeof (int)) / sizeof (int) != tmp))
              {
                error (EXIT_FAILURE, 0, _("%s: invalid number of passes"),
Index: src/system.h
===================================================================
RCS file: /home/eggert/coreutils/cu/src/system.h,v
retrieving revision 1.91
diff -p -u -r1.91 system.h
--- src/system.h        30 Jul 2004 21:08:25 -0000      1.91
+++ src/system.h        2 Aug 2004 03:52:07 -0000
@@ -810,5 +810,5 @@ ptr_align (void *ptr, size_t alignment)
 {
   char *p0 = ptr;
   char *p1 = p0 + alignment - 1;
-  return p1 - (uintptr_t) p1 % alignment;
+  return p1 - (size_t) p1 % alignment;
 }
--- /dev/null   2003-03-18 13:55:57 -0800
+++ m4/uint32_t.m4      2004-08-01 21:27:30 -0700
@@ -0,0 +1,60 @@
+# uint32_t.m4 serial 1
+
+# Copyright (C) 2004 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+# Written by Paul Eggert.
+
+AC_DEFUN([gl_AC_TYPE_UINT32_T],
+[
+  AC_CACHE_CHECK([for uint32_t], gl_cv_c_uint32_t,
+    [gl_cv_c_uint32_t=no
+     for ac_type in "uint32_t" "unsigned int" \
+        "unsigned long int" "unsigned short int"; do
+       AC_COMPILE_IFELSE(
+        [AC_LANG_BOOL_COMPILE_TRY(
+           [AC_INCLUDES_DEFAULT],
+           [[(uint32_t) -1 == 4294967295U]])],
+        [gl_cv_c_uint32_t=$ac_type])
+       test $gl_cv_c_uint32_t != no && break
+     done])
+  case $gl_cv_c_uint32_t in
+  no|uint32_t) ;;
+  *)
+    AC_DEFINE_UNQUOTED(uint32_t, $gl_cv_c_uint32_t,
+      [Define to the type of a unsigned integer type of width exactly 32 bits
+       if such a type exists and the standard includes do not define it.])
+    ;;
+  esac
+
+  AC_CACHE_CHECK([for UINT32_MAX], gl_cv_c_uint32_max,
+    [AC_COMPILE_IFELSE(
+       [AC_LANG_BOOL_COMPILE_TRY(
+         [AC_INCLUDES_DEFAULT],
+         [[UINT32_MAX == 4294967295U]])],
+       [gl_cv_c_uint32_max=yes],
+       [gl_cv_c_uint32_max=no])])
+  case $gl_cv_c_uint32_max,$gl_cv_c_uint32_t in
+  yes,*) ;;
+  *,no) ;;
+  *)
+    AC_DEFINE(UINT32_MAX, 4294967295U,
+      [Define to its maximum value if an unsigned integer type of width
+       exactly 32 bits exists and the standard includes do not define
+       UINT32_MAX.])
+    ;;
+  esac
+])
--- /dev/null   2003-03-18 13:55:57 -0800
+++ m4/uintptr_t.m4     2004-08-01 22:01:30 -0700
@@ -0,0 +1,65 @@
+# uintptr_t.m4 serial 1
+
+# Copyright (C) 2004 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+# Written by Paul Eggert.
+
+AC_DEFUN([gl_AC_TYPE_UINTPTR_T],
+[
+  AC_CACHE_CHECK([for uintptr_t], gl_cv_c_uintptr_t,
+    [gl_cv_c_uintptr_t=no
+     for ac_type in "uintptr_t" "unsigned int" \
+        "unsigned long int" "unsigned long long int"; do
+       AC_COMPILE_IFELSE(
+        [AC_LANG_BOOL_COMPILE_TRY(
+           [AC_INCLUDES_DEFAULT],
+           [[sizeof (void *) <= sizeof (uintptr_t)]])],
+        [gl_cv_c_uintptr_t=$ac_type])
+       test $gl_cv_c_uintptr_t != no && break
+     done])
+  case $gl_cv_c_uintptr_t in
+  no|uintptr_t) ;;
+  *)
+    AC_DEFINE_UNQUOTED(uintptr_t, $gl_cv_c_uintptr_t,
+      [Define to the type of a unsigned integer type wide enough to
+       hold a pointer, if such a type exists.])
+    ;;
+  esac
+
+  dnl Check whether UINTPTR_MAX is defined, not whether it has the
+  dnl right value.  Alas, Solaris 8 defines it to empty!
+  dnl Applications should use (uintptr_t) -1 rather than UINTPTR_MAX.
+  AC_CACHE_CHECK([for UINTPTR_MAX], gl_cv_c_uintptr_max,
+    [AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM(
+         [AC_INCLUDES_DEFAULT],
+         [[#ifndef UINTPTR_MAX
+            error: UINTPTR_MAX is not defined.
+           #endif]])],
+       [gl_cv_c_uintptr_max=yes],
+       [gl_cv_c_uintptr_max=no])])
+  case $gl_cv_c_uintptr_max,$gl_cv_c_uintptr_t in
+  yes,*) ;;
+  *,no) ;;
+  *)
+    AC_DEFINE(UINTPTR_MAX, ((uintptr_t) -1),
+      [Define to its maximum value if an unsigned integer type wide enough
+       to hold a pointer exists and the standard includes do not define
+       UINTPTR_MAX.])
+    ;;
+  esac
+])





reply via email to

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