[syslog-ng]src/io.c patch for libol 0.2.23

syslog-ng@lists.thewrittenword.com syslog-ng@lists.thewrittenword.com
Wed, 28 Nov 2001 08:37:24 -0600


1. alloca patch below needed for HP-UX and AIX.
2. The following is not legal C89 code:
     struct fd_read r =
     { { STACK_HEADER, do_read, do_recv }, fd->fd };
   You cannot assign a non-const value at initialization time. I think
   C99 allows this. The Sun and HP vendor compilers complain (though
   the Sun version allows it because they have started to incorporate
   C99 features).

-- 
albert chin (china@thewrittenword.com)

-- snip snip
--- src/io.c.orig	Tue Nov 27 13:04:16 2001
+++ src/io.c	Tue Nov 27 13:42:26 2001
@@ -21,11 +21,28 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#if defined _AIX && !defined __GNUC__
+ #pragma alloca
+#endif
+
 #include "io.h"
 #include "werror.h"
 #include "xalloc.h"
 #include "format.h"
 
+/* Make alloca work the best possible way.  */
+#ifdef __GNUC__
+#define alloca __builtin_alloca
+#else /* not __GNUC__ */
+#if HAVE_ALLOCA_H
+#include <alloca.h>
+#else /* not __GNUC__ or HAVE_ALLOCA_H */
+#ifndef _AIX /* Already did AIX, up at the top.  */
+char *alloca ();
+#endif /* not _AIX */
+#endif /* not HAVE_ALLOCA_H */
+#endif /* not __GNUC__ */
+
 #include <assert.h>
 #include <string.h>
 
@@ -327,7 +344,6 @@
 	{
 	  debug("Read EOF on fd %i.\n", closure->fd);
 	  return A_EOF;
-	  return 0;
 	}
       if (res > 0)
 	return res;
@@ -400,7 +416,9 @@
 	int res;
 
 	struct fd_read r =
-	{ { STACK_HEADER, do_read, do_recv }, fd->fd };
+	{ { STACK_HEADER, do_read, do_recv }, 0 };
+
+        r.fd = fd->fd;
 
 	/* The handler function may install a new handler */
 	res = READ_HANDLER(self->handler,
@@ -482,7 +500,9 @@
 	int res;
 
 	struct fd_write w =
-	{ { STACK_HEADER, do_write }, fd->fd };
+	{ { STACK_HEADER, do_write }, 0 };
+
+	w.fd = fd->fd;
 
 	assert(self->buffer);
 
@@ -652,7 +672,9 @@
 int blocking_read(int fd, struct read_handler *handler)
 {
 	struct fd_read r =
-	{ { STACK_HEADER, do_read }, fd };
+	{ { STACK_HEADER, do_read }, 0 };
+
+	r.fd = fd;
 
 	for (;;)
 	{