Revision: 14616
Author: adrian.chadd
Date: Sun Apr 18 00:01:22 2010
Log: Issue #109 - include some basic support for parsing non-NUL terminated
numerical strings.
http://code.google.com/p/lusca-cache/source/detail?r=14616
Modified:
/branches/LUSCA_HEAD/include/util.h
/branches/LUSCA_HEAD/lib/util.c
=======================================
--- /branches/LUSCA_HEAD/include/util.h Sun Apr 11 17:10:41 2010
+++ /branches/LUSCA_HEAD/include/util.h Sun Apr 18 00:01:22 2010
@@ -164,4 +164,6 @@
extern void setbuffer(FILE *, char *, size_t);
#endif
+extern long strtol_n(const char *nptr, int nlen, char **endptr, int base);
+
#endif /* SQUID_UTIL_H */
=======================================
--- /branches/LUSCA_HEAD/lib/util.c Sun Apr 11 17:32:53 2010
+++ /branches/LUSCA_HEAD/lib/util.c Sun Apr 18 00:01:22 2010
@@ -762,3 +762,29 @@
write(2, "\n", 1);
abort();
}
+
+/*
+ * Similar to strtol, but it takes a length parameter.
+ */
+long
+strtol_n(const char *nptr, int nlen, char **endptr, int base)
+{
+ char buf[64];
+ long r;
+ char *np = NULL;
+ size_t i;
+
+ /* take a copy of the string, NUL terminate it just in case */
+ memcpy(buf, nptr, XMIN(nlen, sizeof(buf) - 1));
+ buf[sizeof(buf) - 1] = '\0';
+
+ /* Now do the parsing */
+ r = strtol(buf, &np, base);
+
+ /* The endptr is relative to buf, so convert back if required */
+ if (np != NULL) {
+ np = (char *) nptr + (np - buf);
+ }
+
+ return r;
+}
--
You received this message because you are subscribed to the Google Groups
"lusca-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/lusca-commit?hl=en.