areadlink: use SIZE_MAX consistently
authorEric Blake <ebb9@byu.net>
Thu, 8 Oct 2009 16:09:05 +0000 (10:09 -0600)
committerEric Blake <ebb9@byu.net>
Fri, 9 Oct 2009 03:02:32 +0000 (21:02 -0600)
* modules/areadlink (Depends-on): Add stdint.
* modules/areadlink-with-size (Depends-on): Likewise.
* lib/areadlink-with-size.c (includes): Drop stdio, since stdlib
gives NULL; drop sys/types, since unistd gives size_t; and add
stdint for SIZE_MAX.
(SIZE_MAX): Rely on headers.
* lib/areadlinkat-with-size.c (includes): Drop stdio, sys/types,
and add stdint.
* lib/areadlink.c (includes): Drop sys/types, and add stdint.
(SIZE_MAX): Likewise.
(INITIAL_BUF_SIZE): Turn into enum.
* lib/areadlinkat.c (INITIAL_BUF_SIZE): Likewise.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
lib/areadlink-with-size.c
lib/areadlink.c
lib/areadlinkat-with-size.c
lib/areadlinkat.c
modules/areadlink
modules/areadlink-with-size

index 3af4f51..3f19197 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2009-10-08  Eric Blake  <ebb9@byu.net>
+
+       areadlink: use SIZE_MAX consistently
+       * modules/areadlink (Depends-on): Add stdint.
+       * modules/areadlink-with-size (Depends-on): Likewise.
+       * lib/areadlink-with-size.c (includes): Drop stdio, since stdlib
+       gives NULL; drop sys/types, since unistd gives size_t; and add
+       stdint for SIZE_MAX.
+       (SIZE_MAX): Rely on headers.
+       * lib/areadlinkat-with-size.c (includes): Drop stdio, sys/types,
+       and add stdint.
+       * lib/areadlink.c (includes): Drop sys/types, and add stdint.
+       (SIZE_MAX): Likewise.
+       (INITIAL_BUF_SIZE): Turn into enum.
+       * lib/areadlinkat.c (INITIAL_BUF_SIZE): Likewise.
+
 2009-10-08  Jim Meyering  <meyering@redhat.com>
 
        areadlinkat: avoid compilation failure
index d0bcb70..625ddb7 100644 (file)
@@ -1,7 +1,7 @@
 /* readlink wrapper to return the link name in malloc'd storage.
    Unlike xreadlink and xreadlink_with_size, don't ever call exit.
 
-   Copyright (C) 2001, 2003-2007 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2003-2007, 2009 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
 
 #include "areadlink.h"
 
-#include <stdio.h>
 #include <errno.h>
 #include <limits.h>
-#include <sys/types.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <unistd.h>
 
-#ifndef SIZE_MAX
-# define SIZE_MAX ((size_t) -1)
-#endif
 #ifndef SSIZE_MAX
 # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
 #endif
index 4e770eb..f6871c5 100644 (file)
@@ -1,7 +1,7 @@
 /* areadlink.c -- readlink wrapper to return the link name in malloc'd storage
    Unlike xreadlink and xreadlink_with_size, don't ever call exit.
 
-   Copyright (C) 2001, 2003-2007 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2003-2007, 2009 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
 /* Specification.  */
 #include "areadlink.h"
 
-#include <string.h>
 #include <errno.h>
 #include <limits.h>
-#include <sys/types.h>
+#include <stdint.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
-#ifndef SIZE_MAX
-# define SIZE_MAX ((size_t) -1)
-#endif
 #ifndef SSIZE_MAX
 # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
 #endif
 
+/* The initial buffer size for the link value.  A power of 2
+   detects arithmetic overflow earlier, but is not required.  */
+enum {
+  INITIAL_BUF_SIZE = 1024
+};
+
 /* Call readlink to get the symbolic link value of FILENAME.
    Return a pointer to that NUL-terminated string in malloc'd storage.
    If readlink fails, return NULL and set errno.
 char *
 areadlink (char const *filename)
 {
-  /* The initial buffer size for the link value.  A power of 2
-     detects arithmetic overflow earlier, but is not required.  */
-#define INITIAL_BUF_SIZE 1024
-
   /* Allocate the initial buffer on the stack.  This way, in the common
      case of a symlink of small size, we get away with a single small malloc()
      instead of a big malloc() followed by a shrinking realloc().  */
   char initial_buf[INITIAL_BUF_SIZE];
 
   char *buffer = initial_buf;
-  size_t buf_size = sizeof (initial_buf);
+  size_t buf_size = sizeof initial_buf;
 
   while (1)
     {
index d1abb5b..4ad76b7 100644 (file)
 
 #include "areadlink.h"
 
-#include <stdio.h>
 #include <errno.h>
 #include <limits.h>
-#include <sys/types.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <unistd.h>
 
index 07714d0..f9a3daf 100644 (file)
 /* Specification.  */
 #include "areadlink.h"
 
-#include <string.h>
 #include <errno.h>
 #include <limits.h>
-#include <sys/types.h>
 #include <stdint.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #ifndef SSIZE_MAX
 
 #if HAVE_READLINKAT
 
+/* The initial buffer size for the link value.  A power of 2
+   detects arithmetic overflow earlier, but is not required.  */
+enum {
+  INITIAL_BUF_SIZE = 1024
+};
+
 /* Call readlinkat to get the symbolic link value of FILENAME relative to FD.
    Return a pointer to that NUL-terminated string in malloc'd storage.
    If readlinkat fails, return NULL and set errno (although failure to
 char *
 areadlinkat (int fd, char const *filename)
 {
-  /* The initial buffer size for the link value.  A power of 2
-     detects arithmetic overflow earlier, but is not required.  */
-# define INITIAL_BUF_SIZE 1024
-
   /* Allocate the initial buffer on the stack.  This way, in the common
      case of a symlink of small size, we get away with a single small malloc()
      instead of a big malloc() followed by a shrinking realloc().  */
   char initial_buf[INITIAL_BUF_SIZE];
 
   char *buffer = initial_buf;
-  size_t buf_size = sizeof (initial_buf);
+  size_t buf_size = sizeof initial_buf;
 
   while (1)
     {
index 2acc4a9..dc7cfe4 100644 (file)
@@ -6,10 +6,11 @@ lib/areadlink.h
 lib/areadlink.c
 
 Depends-on:
+malloc-posix
 readlink
 ssize_t
+stdint
 unistd
-malloc-posix
 
 configure.ac:
 
index df6db33..212f8ab 100644 (file)
@@ -8,6 +8,7 @@ lib/areadlink-with-size.c
 Depends-on:
 readlink
 ssize_t
+stdint
 unistd
 
 configure.ac: