Mercurial > hg > octave-kai > gnulib-hg
changeset 12141:1fd105be1362
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 <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Thu, 08 Oct 2009 10:09:05 -0600 |
parents | 5ebefc09b542 |
children | cc3ba2052ea4 |
files | ChangeLog lib/areadlink-with-size.c lib/areadlink.c lib/areadlinkat-with-size.c lib/areadlinkat.c modules/areadlink modules/areadlink-with-size |
diffstat | 7 files changed, 40 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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 <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
--- 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 <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. @@ -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) {
--- a/lib/areadlinkat-with-size.c +++ b/lib/areadlinkat-with-size.c @@ -23,10 +23,9 @@ #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>
--- a/lib/areadlinkat.c +++ b/lib/areadlinkat.c @@ -25,12 +25,11 @@ /* 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 @@ -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) {