From 763db4b13875d56f6030e0b52248aec12a8ea1b8 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Sat, 25 Oct 2008 10:52:22 +0000 Subject: [PATCH] - Implement support for retrieving a size_t type from the protocol stream. --- contrib/csup/proto.c | 20 ++++++++++++++++++++ contrib/csup/proto.h | 1 + 2 files changed, 21 insertions(+) diff --git a/contrib/csup/proto.c b/contrib/csup/proto.c index 6c387fb53628..fd574b0fb790 100644 --- a/contrib/csup/proto.c +++ b/contrib/csup/proto.c @@ -949,6 +949,26 @@ proto_get_int(char **s, int *val, int base) return (error); } +/* + * Get a size_t token. + */ +int +proto_get_sizet(char **s, size_t *val, int base) +{ + unsigned long long tmp; + char *cp, *end; + + cp = proto_get_ascii(s); + if (cp == NULL) + return (-1); + errno = 0; + tmp = strtoll(cp, &end, base); + if (errno || *end != '\0') + return (-1); + *val = (size_t)tmp; + return (0); +} + /* * Get a time_t token. * diff --git a/contrib/csup/proto.h b/contrib/csup/proto.h index ea9c01230232..0c4a78299f11 100644 --- a/contrib/csup/proto.h +++ b/contrib/csup/proto.h @@ -44,6 +44,7 @@ int proto_printf(struct stream *, const char *, ...); char *proto_get_ascii(char **); char *proto_get_rest(char **); int proto_get_int(char **, int *, int); +int proto_get_sizet(char **, size_t *, int); int proto_get_time(char **, time_t *); #endif /* !_PROTO_H_ */