]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Don't include <sys/types.h> or <stdlib.h>; <stddef.h>
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 28 Jul 2004 20:09:39 +0000 (20:09 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 28 Jul 2004 20:09:39 +0000 (20:09 +0000)
suffices with C89 or better.
(alignof): New macro, portable to all C89 hosts.
(UNALIGNED): Use it.  Use uintptr_t if available, and assume
everything is unaligned otherwise; this is more portable than
assuming 'unsigned long int' will always work.

lib/md5.c
lib/sha1.c

index 2fc652cea94a930115186c85779a36b5bbbf6699..78a1e2bbc1ed1df92631232639901b29da5c5eec 100644 (file)
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -1,6 +1,6 @@
 /* md5.c - Functions to compute MD5 message digest of files or memory blocks
    according to the definition of MD5 in RFC 1321 from April 1992.
-   Copyright (C) 1995, 1996, 2001, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 2001, 2003, 2004 Free Software Foundation, Inc.
    NOTE: The canonical source of this file is maintained with the GNU C
    Library.  Bugs can be reported to bug-glibc@prep.ai.mit.edu.
 
@@ -26,9 +26,7 @@
 
 #include "md5.h"
 
-#include <sys/types.h>
-
-#include <stdlib.h>
+#include <stddef.h>
 #include <string.h>
 
 #include "unlocked-io.h"
@@ -246,12 +244,11 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
   if (len >= 64)
     {
 #if !_STRING_ARCH_unaligned
-/* To check alignment gcc has an appropriate operator.  Other
-   compilers don't.  */
-# if __GNUC__ >= 2
-#  define UNALIGNED_P(p) (((md5_uintptr) p) % __alignof__ (md5_uint32) != 0)
+# 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) (((md5_uintptr) p) % sizeof (md5_uint32) != 0)
+#  define UNALIGNED_P(p) 1
 # endif
       if (UNALIGNED_P (buffer))
        while (len > 64)
index 52766bac5b76985824a667af4dd9939b19a60f47..d2647877eb15513a71cd950412d502f060465f3b 100644 (file)
@@ -1,7 +1,7 @@
 /* sha.c - Functions to compute SHA1 message digest of files or
    memory blocks according to the NIST specification FIPS-180-1.
 
-   Copyright (C) 2000, 2001, 2003 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2003, 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
@@ -28,9 +28,7 @@
 
 #include "sha1.h"
 
-#include <sys/types.h>
-
-#include <stdlib.h>
+#include <stddef.h>
 #include <string.h>
 
 #include "unlocked-io.h"
@@ -244,12 +242,11 @@ sha_process_bytes (const void *buffer, size_t len, struct sha_ctx *ctx)
   if (len >= 64)
     {
 #if !_STRING_ARCH_unaligned
-/* To check alignment gcc has an appropriate operator.  Other
-   compilers don't.  */
-# if __GNUC__ >= 2
-#  define UNALIGNED_P(p) (((md5_uintptr) p) % __alignof__ (md5_uint32) != 0)
+# 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) (((md5_uintptr) p) % sizeof (md5_uint32) != 0)
+#  define UNALIGNED_P(p) 1
 # endif
       if (UNALIGNED_P (buffer))
        while (len > 64)