summaryrefslogtreecommitdiffstats
path: root/contrib/csup
diff options
context:
space:
mode:
authorlulf <lulf@FreeBSD.org>2008-10-25 10:52:22 +0000
committerlulf <lulf@FreeBSD.org>2008-10-25 10:52:22 +0000
commit819cd9f881e7454b3f7fd0a565a156ba2fe54ca1 (patch)
tree56b10be85fae6b9372e3c715400a113ff1f7be44 /contrib/csup
parent0f6475d2a0903e6307caf16cfc3361448a4a4f95 (diff)
downloadFreeBSD-src-819cd9f881e7454b3f7fd0a565a156ba2fe54ca1.zip
FreeBSD-src-819cd9f881e7454b3f7fd0a565a156ba2fe54ca1.tar.gz
- Implement support for retrieving a size_t type from the protocol stream.
Diffstat (limited to 'contrib/csup')
-rw-r--r--contrib/csup/proto.c20
-rw-r--r--contrib/csup/proto.h1
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_ */
OpenPOWER on IntegriCloud