diff options
-rw-r--r-- | contrib/csup/proto.c | 20 | ||||
-rw-r--r-- | contrib/csup/proto.h | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/contrib/csup/proto.c b/contrib/csup/proto.c index 6c387fb..fd574b0 100644 --- a/contrib/csup/proto.c +++ b/contrib/csup/proto.c @@ -950,6 +950,26 @@ proto_get_int(char **s, int *val, int base) } /* + * 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. * * Ideally, we would use an intmax_t and strtoimax() here, but strtoll() diff --git a/contrib/csup/proto.h b/contrib/csup/proto.h index ea9c012..0c4a782 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_ */ |