SBuf sbuf; /* stream buffer, must be last */
};
-#define PG_SOCKET_SIZE (sizeof(PgSocket) + cf_sbuf_len + SBUF_MAX_REWRITE)
+#define RAW_SOCKET_SIZE offsetof(struct PgSocket, sbuf.buf)
+#define PG_SOCKET_SIZE (RAW_SOCKET_SIZE + cf_sbuf_len + SBUF_MAX_REWRITE)
/* where to store old fd info during SHOW FDS result processing */
#define tmp_sk_oldfd request_time
SBuf *dst; /* target SBuf for current packet */
- uint8_t buf[0]; /* data buffer follows (cf_sbuf_len + SBUF_MAX_REWRITE) */
+ uint8_t buf[FLEX_ARRAY];/* data buffer follows (cf_sbuf_len + SBUF_MAX_REWRITE) */
};
+#define RAW_SBUF_SIZE offsetof(struct SBuf, buf)
+
#define sbuf_socket(sbuf) ((sbuf)->sock)
void sbuf_init(SBuf *sbuf, sbuf_cb_t proto_fn, void *arg);
#include <crypt.h>
#endif
+/* how to specify array with unknown length */
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
+#define FLEX_ARRAY
+#elif defined(__GNUC__)
+#define FLEX_ARRAY
+#else
+#define FLEX_ARRAY 1
+#endif
+
/* gcc has hew positive aspects too */
#ifdef __GNUC__
List *item;
PgDatabase *db;
- log_noise("event: %lu, SBuf: %lu, PgSocket: %lu, Full PgSocket: %lu, buf ofs: %lu",
- sizeof(struct event), sizeof(SBuf), sizeof(PgSocket),
- PG_SOCKET_SIZE, offsetof(SBuf, buf));
+ log_noise("event: %lu, SBuf: %lu, PgSocket: %lu, Full PgSocket: %lu",
+ sizeof(struct event), RAW_SBUF_SIZE, RAW_SOCKET_SIZE, PG_SOCKET_SIZE);
/* load limits */
err = getrlimit(RLIMIT_NOFILE, &lim);
/* initialize SBuf with proto handler */
void sbuf_init(SBuf *sbuf, sbuf_cb_t proto_fn, void *arg)
{
- memset(sbuf, 0, sizeof(*sbuf));
+ memset(sbuf, 0, RAW_SBUF_SIZE);
sbuf->proto_cb_arg = arg;
sbuf->proto_cb = proto_fn;
}