summaryrefslogtreecommitdiff
path: root/pjlib
diff options
context:
space:
mode:
authorRiza Sulistyo <riza@teluu.com>2013-03-14 07:18:13 +0000
committerRiza Sulistyo <riza@teluu.com>2013-03-14 07:18:13 +0000
commit458b2a58d18f7e548cfed653dc6f18c318790232 (patch)
tree4186906e357c444e88b365dd16222d8a54b17877 /pjlib
parent041b868c2e4109432c177a801ed1a9366bfb7c6b (diff)
Re #1643: add initial support for CLI
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4440 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib')
-rw-r--r--pjlib/include/pj/string.h11
-rw-r--r--pjlib/src/pj/string.c13
2 files changed, 24 insertions, 0 deletions
diff --git a/pjlib/include/pj/string.h b/pjlib/include/pj/string.h
index 6df22f12..525b4c05 100644
--- a/pjlib/include/pj/string.h
+++ b/pjlib/include/pj/string.h
@@ -536,6 +536,17 @@ PJ_IDECL(pj_str_t*) pj_strtrim( pj_str_t *str );
PJ_DECL(char*) pj_create_random_string(char *str, pj_size_t length);
/**
+ * Convert string to signed integer. The conversion will stop as
+ * soon as non-digit character is found or all the characters have
+ * been processed.
+ *
+ * @param str the string.
+ *
+ * @return the integer.
+ */
+PJ_DECL(long) pj_strtol(const pj_str_t *str);
+
+/**
* Convert string to unsigned integer. The conversion will stop as
* soon as non-digit character is found or all the characters have
* been processed.
diff --git a/pjlib/src/pj/string.c b/pjlib/src/pj/string.c
index 52e7c794..ca3a4605 100644
--- a/pjlib/src/pj/string.c
+++ b/pjlib/src/pj/string.c
@@ -109,6 +109,19 @@ PJ_DEF(char*) pj_create_random_string(char *str, pj_size_t len)
return str;
}
+PJ_DEF(long) pj_strtol(const pj_str_t *str)
+{
+ PJ_CHECK_STACK();
+
+ if (str->slen > 0 && (str->ptr[0] == '+' || str->ptr[0] == '-')) {
+ pj_str_t s;
+
+ s.ptr = str->ptr + 1;
+ s.slen = str->slen - 1;
+ return (str->ptr[0] == '-'? -(long)pj_strtoul(&s) : pj_strtoul(&s));
+ } else
+ return pj_strtoul(str);
+}
PJ_DEF(unsigned long) pj_strtoul(const pj_str_t *str)
{