* 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>
+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
/* 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
/* 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)
{
#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>
/* 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)
{
lib/areadlink.c
Depends-on:
+malloc-posix
readlink
ssize_t
+stdint
unistd
-malloc-posix
configure.ac:
Depends-on:
readlink
ssize_t
+stdint
unistd
configure.ac: