INN commit: trunk (3 files)
INN Commit
rra at isc.org
Wed Sep 3 17:40:31 UTC 2014
Date: Wednesday, September 3, 2014 @ 10:40:31
Author: iulius
Revision: 9671
sync with latest rra-c-util
Add GCC attributes to util/buffer.h functions, mostly nonnull.
Clarify the documentation of some of the functions, particularly
around error reporting.
Fix visibility for util/buffer.c functions and for inet_aton and
inet_ntoa replacements to match the default hidden visiblity of other
portability and util functions.
Modified:
trunk/include/inn/buffer.h
trunk/include/portable/socket.h
trunk/lib/fdflag.c
---------------------------+
include/inn/buffer.h | 59 ++++++++++++++++++++++++++++++--------------
include/portable/socket.h | 14 +++++++++-
lib/fdflag.c | 2 -
3 files changed, 55 insertions(+), 20 deletions(-)
Modified: include/inn/buffer.h
===================================================================
--- include/inn/buffer.h 2014-09-03 17:27:01 UTC (rev 9670)
+++ include/inn/buffer.h 2014-09-03 17:40:31 UTC (rev 9671)
@@ -17,6 +17,7 @@
* which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle at eyrie.org>
+ * Copyright 2014 Russ Allbery <eagle at eyrie.org>
* Copyright 2011, 2012
* The Board of Trustees of the Leland Stanford Junior University
* Copyright (c) 2004, 2005, 2006
@@ -57,7 +58,8 @@
BEGIN_DECLS
/* Allocate a new buffer and initialize its contents. */
-struct buffer *buffer_new(void);
+struct buffer *buffer_new(void)
+ __attribute__((__warn_unused_result__, __malloc__));
/* Free an allocated buffer. */
void buffer_free(struct buffer *);
@@ -66,35 +68,45 @@
* Resize a buffer to be at least as large as the provided size. Invalidates
* pointers into the buffer.
*/
-void buffer_resize(struct buffer *, size_t);
+void buffer_resize(struct buffer *, size_t)
+ __attribute__((__nonnull__));
/*
* Compact a buffer, removing all used data and moving unused data to the
* beginning of the buffer. Invalidates pointers into the buffer.
*/
-void buffer_compact(struct buffer *);
+void buffer_compact(struct buffer *)
+ __attribute__((__nonnull__));
-/* Set the buffer contents, ignoring anything currently there. */
-void buffer_set(struct buffer *, const char *data, size_t length);
+/*
+ * Set the buffer contents, ignoring anything currently there. If length is
+ * 0, empties the buffer, in which case data may be NULL.
+ */
+void buffer_set(struct buffer *, const char *data, size_t length)
+ __attribute__((__nonnull__(1)));
/*
* Set the buffer contents via a sprintf-style format string. No trailing
* nul is added.
*/
void buffer_sprintf(struct buffer *, const char *, ...)
- __attribute__((__format__(printf, 2, 3)));
-void buffer_vsprintf(struct buffer *, const char *, va_list);
+ __attribute__((__format__(printf, 2, 3), __nonnull__));
+void buffer_vsprintf(struct buffer *, const char *, va_list)
+ __attribute__((__nonnull__));
/* Append data to the buffer. */
-void buffer_append(struct buffer *, const char *data, size_t length);
+void buffer_append(struct buffer *, const char *data, size_t length)
+ __attribute__((__nonnull__(1)));
/* Append via an sprintf-style format string. No trailing nul is added. */
void buffer_append_sprintf(struct buffer *, const char *, ...)
- __attribute__((__format__(printf, 2, 3)));
-void buffer_append_vsprintf(struct buffer *, const char *, va_list);
+ __attribute__((__format__(printf, 2, 3), __nonnull__));
+void buffer_append_vsprintf(struct buffer *, const char *, va_list)
+ __attribute__((__nonnull__));
/* Swap the contents of two buffers. */
-void buffer_swap(struct buffer *, struct buffer *);
+void buffer_swap(struct buffer *, struct buffer *)
+ __attribute__((__nonnull__));
/*
* Find the given string in the unconsumed data in a buffer. start is an
@@ -105,22 +117,33 @@
* the fourth argument. Returns false if the terminator isn't found.
*/
bool buffer_find_string(struct buffer *, const char *, size_t start,
- size_t *offset);
+ size_t *offset)
+ __attribute__((__nonnull__));
/*
* Read from a file descriptor into a buffer, up to the available space in the
- * buffer. Return the number of characters read.
+ * buffer. Return the number of characters read. Retries the read if
+ * interrupted by a signal or if it returns EAGAIN, but stops on any other
+ * error or after any successful read. Returns -1 on an error reading from
+ * the file descriptor and sets errno.
*/
-ssize_t buffer_read(struct buffer *, int fd);
+ssize_t buffer_read(struct buffer *, int fd)
+ __attribute__((__nonnull__));
-/* Read from a file descriptor into a buffer until end of file is reached. */
-bool buffer_read_all(struct buffer *, int fd);
+/*
+ * Read from a file descriptor into a buffer until end of file is reached.
+ * Returns true on success and false (setting errno) on error.
+ */
+bool buffer_read_all(struct buffer *, int fd)
+ __attribute__((__nonnull__));
/*
* Read the contents of a file into a buffer. This should be used instead of
- * buffer_read_all when fstat can be called on the file descriptor.
+ * buffer_read_all when fstat can be called on the file descriptor. Returns
+ * true on success and false (setting errno) on error.
*/
-bool buffer_read_file(struct buffer *, int fd);
+bool buffer_read_file(struct buffer *, int fd)
+ __attribute__((__nonnull__));
END_DECLS
Modified: include/portable/socket.h
===================================================================
--- include/portable/socket.h 2014-09-03 17:27:01 UTC (rev 9670)
+++ include/portable/socket.h 2014-09-03 17:40:31 UTC (rev 9671)
@@ -17,6 +17,7 @@
* The canonical version of this file is maintained in the rra-c-util package,
* which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
*
+ * Copyright 2014 Russ Allbery <eagle at eyrie.org>
* Copyright 2008, 2009, 2011, 2013
* The Board of Trustees of the Leland Stanford Junior University
* Copyright (c) 2004, 2005, 2006, 2007
@@ -203,13 +204,24 @@
/*
* Provide prototypes for inet_aton and inet_ntoa if not prototyped in the
* system header files since they're occasionally available without proper
- * prototypes.
+ * prototypes. If we're providing a replacement, be sure to set visibility
+ * accordingly.
*/
#if !HAVE_DECL_INET_ATON
+# if !HAVE_INET_ATON
+extern int inet_aton(const char *, struct in_addr *)
+ __attribute__((__visibility__("hidden")));
+# else
extern int inet_aton(const char *, struct in_addr *);
+# endif
#endif
#if !HAVE_DECL_INET_NTOA
+# if !HAVE_INET_NTOA
+extern const char *inet_ntoa(const struct in_addr)
+ __attribute__((__visibility__("hidden")));
+# else
extern const char *inet_ntoa(const struct in_addr);
+# endif
#endif
#if !HAVE_INET_NTOP
Modified: lib/fdflag.c
===================================================================
--- lib/fdflag.c 2014-09-03 17:27:01 UTC (rev 9670)
+++ lib/fdflag.c 2014-09-03 17:40:31 UTC (rev 9671)
@@ -33,7 +33,6 @@
#include "config.h"
#include "clibrary.h"
-#include <errno.h>
#ifdef _WIN32
# include <winsock2.h>
@@ -50,6 +49,7 @@
#include "inn/fdflag.h"
#include "inn/libinn.h"
+
/*
* Set a file to close-on-exec (or clear that setting if the flag is false),
* returning true on success and false on failure.
More information about the inn-committers
mailing list