From: Eric Blake Date: Thu, 8 Oct 2009 16:09:05 +0000 (-0600) Subject: areadlink: use SIZE_MAX consistently X-Git-Tag: v0.1~5346 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=2ee3ac7fd334d0fe044d8f3aa49636a86b01e026;p=gnulib.git 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. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index 3af4f5120..3f191977a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2009-10-08 Eric Blake + + 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 areadlinkat: avoid compilation failure diff --git a/lib/areadlink-with-size.c b/lib/areadlink-with-size.c index d0bcb70ad..625ddb795 100644 --- a/lib/areadlink-with-size.c +++ b/lib/areadlink-with-size.c @@ -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 @@ -22,16 +22,12 @@ #include "areadlink.h" -#include #include #include -#include +#include #include #include -#ifndef SIZE_MAX -# define SIZE_MAX ((size_t) -1) -#endif #ifndef SSIZE_MAX # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2)) #endif diff --git a/lib/areadlink.c b/lib/areadlink.c index 4e770eb41..f6871c572 100644 --- a/lib/areadlink.c +++ b/lib/areadlink.c @@ -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 @@ -24,20 +24,23 @@ /* Specification. */ #include "areadlink.h" -#include #include #include -#include +#include #include +#include #include -#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. @@ -47,17 +50,13 @@ 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) { diff --git a/lib/areadlinkat-with-size.c b/lib/areadlinkat-with-size.c index d1abb5b01..4ad76b77c 100644 --- a/lib/areadlinkat-with-size.c +++ b/lib/areadlinkat-with-size.c @@ -23,10 +23,9 @@ #include "areadlink.h" -#include #include #include -#include +#include #include #include diff --git a/lib/areadlinkat.c b/lib/areadlinkat.c index 07714d0a9..f9a3dafbb 100644 --- a/lib/areadlinkat.c +++ b/lib/areadlinkat.c @@ -25,12 +25,11 @@ /* Specification. */ #include "areadlink.h" -#include #include #include -#include #include #include +#include #include #ifndef SSIZE_MAX @@ -39,6 +38,12 @@ #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 @@ -49,17 +54,13 @@ 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) { diff --git a/modules/areadlink b/modules/areadlink index 2acc4a90a..dc7cfe49a 100644 --- a/modules/areadlink +++ b/modules/areadlink @@ -6,10 +6,11 @@ lib/areadlink.h lib/areadlink.c Depends-on: +malloc-posix readlink ssize_t +stdint unistd -malloc-posix configure.ac: diff --git a/modules/areadlink-with-size b/modules/areadlink-with-size index df6db33b0..212f8ab77 100644 --- a/modules/areadlink-with-size +++ b/modules/areadlink-with-size @@ -8,6 +8,7 @@ lib/areadlink-with-size.c Depends-on: readlink ssize_t +stdint unistd configure.ac: