On 64bits platforms, ssize_t is an int64_t.
Given the average string length pfixtools will handle, a 32bits integer is
enough, let's use int everywhere.
Also a pointer difference is an ptrdiff_t which is also a 64bits integer, so
when used as the width specifier of a %.*s format, it must be cast into an
int.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
#include "mem.h"
#include "buffer.h"
-ssize_t buffer_addvf(buffer_t *buf, const char *fmt, va_list ap)
+int buffer_addvf(buffer_t *buf, const char *fmt, va_list ap)
{
- ssize_t len, avail = buf->size - buf->len;
+ int len, avail = buf->size - buf->len;
va_list ap2;
va_copy(ap2, ap);
return len;
}
-void buffer_consume(buffer_t *buf, ssize_t len)
+void buffer_consume(buffer_t *buf, int len)
{
if (len <= 0)
return;
- if (len >= (ssize_t)buf->len) {
+ if (len >= (int)buf->len) {
buffer_reset(buf);
return;
}
buf->len -= len;
}
-ssize_t buffer_read(buffer_t *buf, int fd, ssize_t count)
+int buffer_read(buffer_t *buf, int fd, int count)
{
- ssize_t res;
+ int res;
if (count < 0)
count = BUFSIZ;
return res;
}
-ssize_t buffer_write(buffer_t *buf, int fd)
+int buffer_write(buffer_t *buf, int fd)
{
- ssize_t res = write(fd, buf->data, buf->len);
+ int res = write(fd, buf->data, buf->len);
if (res < 0) {
return errno == EINTR || errno == EAGAIN ? 0 : -1;
}
#define buffer_resize(buffer, newsize) \
array_ensure_exact_capacity(*(buffer), (newsize) + 1)
-static inline void buffer_ensure(buffer_t *buf, ssize_t extra) {
+static inline void buffer_ensure(buffer_t *buf, int extra) {
assert (extra >= 0);
if (buf->len + extra >= buf->size) {
buffer_resize(buf, buf->len + extra);
}
}
-static inline void buffer_extend(buffer_t *buf, ssize_t extra) {
+static inline void buffer_extend(buffer_t *buf, int extra) {
buffer_ensure(buf, extra);
buf->len += extra;
buf->data[buf->len] = '\0';
}
-static inline void buffer_extendch(buffer_t *buf, ssize_t extra, int c) {
+static inline void buffer_extendch(buffer_t *buf, int extra, int c) {
buffer_ensure(buf, extra);
memset(buf->data + buf->len, c, extra);
buf->len += extra;
}
-static inline void buffer_add(buffer_t *buf, const void *data, ssize_t len) {
+static inline void buffer_add(buffer_t *buf, const void *data, int len) {
buffer_ensure(buf, len);
memcpy(buf->data + buf->len, data, len);
buf->len += len;
}
__attribute__((format(printf,2,0)))
-ssize_t buffer_addvf(buffer_t *, const char *fmt, va_list);
+int buffer_addvf(buffer_t *, const char *fmt, va_list);
static inline __attribute__((format(printf,2,3)))
-ssize_t buffer_addf(buffer_t *buf, const char *fmt, ...)
+int buffer_addf(buffer_t *buf, const char *fmt, ...)
{
- ssize_t res;
+ int res;
va_list args;
va_start(args, fmt);
res = buffer_addvf(buf, fmt, args);
return res;
}
-void buffer_consume(buffer_t *buf, ssize_t len);
+void buffer_consume(buffer_t *buf, int len);
-ssize_t buffer_read(buffer_t *buf, int fd, ssize_t count);
-ssize_t buffer_write(buffer_t *buf, int fd);
+int buffer_read(buffer_t *buf, int fd, int count);
+int buffer_write(buffer_t *buf, int fd);
#endif /* PFIXTOOLS_BUFFER_H */
printf("Number of leaves: %d\n", leaves);
printf("Max depth: %d\n", max_depth);
printf("Average leaf depth: %d\n", depth_sum / leaves);
- printf("Memory used: %d\n", (trie->entries.size * sizeof(trie_entry_t))
+ printf("Memory used: %zd\n", (trie->entries.size * sizeof(trie_entry_t))
+ (trie->c.size) + sizeof(trie_t));
}
}
char key[BUFSIZ];
char value[BUFSIZ];
- ssize_t key_len, value_len;
+ int key_len, value_len;
if (!file_map_open(&map, config->filename, false)) {
return false;
#define READ_LOG(Lev, Fmt, ...) \
__log(LOG_ ## Lev, "config file %s:%d:%d: " Fmt, config->filename, \
- line + 1, p - linep + 1, ##__VA_ARGS__)
+ line + 1, (int)(p - linep + 1), ##__VA_ARGS__)
#define READ_ERROR(Fmt, ...) \
do { \
READ_LOG(ERR, Fmt, ##__VA_ARGS__); \
return !!(runners[filter->type](filter, query) == result);
}
-void filter_set_name(filter_t *filter, const char *name, ssize_t len)
+void filter_set_name(filter_t *filter, const char *name, int len)
{
filter->name = p_dupstr(name, len);
}
-bool filter_set_type(filter_t *filter, const char *type, ssize_t len)
+bool filter_set_type(filter_t *filter, const char *type, int len)
{
filter->type = filter_tokenize(type, len);
return filter->type != FTK_UNKNOWN;
}
-bool filter_add_param(filter_t *filter, const char *name, ssize_t name_len,
- const char *value, ssize_t value_len)
+bool filter_add_param(filter_t *filter, const char *name, int name_len,
+ const char *value, int value_len)
{
filter_param_t param;
param.type = param_tokenize(name, name_len);
return true;
}
-bool filter_add_hook(filter_t *filter, const char *name, ssize_t name_len,
- const char *value, ssize_t value_len)
+bool filter_add_hook(filter_t *filter, const char *name, int name_len,
+ const char *value, int value_len)
{
filter_hook_t hook;
hook.type = hook_tokenize(name, name_len);
typedef struct filter_param_t {
filter_param_id_t type;
- char *value;
- ssize_t value_len;
+ char *value;
+ int value_len;
} filter_param_t;
ARRAY(filter_param_t)
}
__attribute__((nonnull(1,2)))
-void filter_set_name(filter_t *filter, const char *name, ssize_t len);
+void filter_set_name(filter_t *filter, const char *name, int len);
__attribute__((nonnull(1,2)))
-bool filter_set_type(filter_t *filter, const char *type, ssize_t len);
+bool filter_set_type(filter_t *filter, const char *type, int len);
__attribute__((nonnull(1,2,4)))
-bool filter_add_param(filter_t *filter, const char *name, ssize_t name_len,
- const char *value, ssize_t value_len);
+bool filter_add_param(filter_t *filter, const char *name, int name_len,
+ const char *value, int value_len);
__attribute__((nonnull(1,2,4)))
-bool filter_add_hook(filter_t *filter, const char *name, ssize_t name_len,
- const char *value, ssize_t value_len);
+bool filter_add_hook(filter_t *filter, const char *name, int name_len,
+ const char *value, int value_len);
__attribute__((nonnull(1)))
bool filter_build(filter_t *filter);
lock = false;
} else {
PARSE_CHECK(false, "illegal locking state %.*s",
- p - current, current);
+ (int)(p - current), current);
}
break;
weight = strtol(current, &next, 10);
PARSE_CHECK(next == p && weight >= 0 && weight <= 1024,
"illegal weight value %.*s",
- (p - current), current);
+ (int)(p - current), current);
break;
case 2:
weight = strtol(current, &next, 10);
PARSE_CHECK(next == p && weight >= 0 && weight <= 1024,
"illegal weight value %.*s",
- (p - current), current);
+ (int)(p - current), current);
break;
case 1:
static int policy_run(server_t *pcy, void* vconfig)
{
- ssize_t search_offs = MAX(0, (ssize_t)(pcy->ibuf.len - 1));
+ int search_offs = MAX(0, (int)(pcy->ibuf.len - 1));
int nb = buffer_read(&pcy->ibuf, pcy->fd, -1);
const char *eoq;
query_t *query = pcy->data;
condition.field = policy_tokenize(p, n - p);
PARSE_CHECK(condition.field >= PTK_HELO_NAME
&& condition.field < PTK_SMTPD_ACCESS_POLICY,
- "invalid field name %.*s", n - p, p);
+ "invalid field name %.*s", (int)(n - p), p);
p = skipspaces(n);
n = p + 1;
PARSE_CHECK(IS_OP_START(*p) && IS_OP_END(*n),
lock = false;
} else {
PARSE_CHECK(false, "illegal locking state %.*s",
- p - current, current);
+ (int)(p - current), current);
}
break;
reverse = false;
} else {
PARSE_CHECK(false, "illegal character order value %.*s",
- p - current, current);
+ (int)(p - current), current);
}
break;
weight = strtol(current, &next, 10);
PARSE_CHECK(next == p && weight >= 0 && weight <= 1024,
"illegal weight value %.*s",
- (p - current), current);
+ (int)(p - current), current);
break;
case 3:
lock = false;
} else {
PARSE_CHECK(false, "illegal locking state %.*s",
- p - current, current);
+ (int)(p - current), current);
}
break;
weight = strtol(current, &next, 10);
PARSE_CHECK(next == p && weight >= 0 && weight <= 1024,
"illegal weight value %.*s",
- (p - current), current);
+ (int)(p - current), current);
break;
case 2:
weight = strtol(current, &next, 10);
PARSE_CHECK(next == p && weight >= 0 && weight <= 1024,
"illegal weight value %.*s",
- (p - current), current);
+ (int)(p - current), current);
break;
case 1:
CASE(RECIPIENT, recipient, email);
#undef CASE
default:
- PARSE_CHECK(false, "unknown field %.*s", p - current, current);
+ PARSE_CHECK(false, "unknown field %.*s", (int)(p - current), current);
break;
}
if (!*p) {