summaryrefslogtreecommitdiff
path: root/pjlib
diff options
context:
space:
mode:
authorLiong Sauw Ming <ming@teluu.com>2014-01-16 05:30:46 +0000
committerLiong Sauw Ming <ming@teluu.com>2014-01-16 05:30:46 +0000
commite56ea14ab8531ee3cec375460577d1b89bf62e26 (patch)
treedf77c3acb961514b2022ee9e030071b691145920 /pjlib
parentbd1c47e995a3a844868f1d4dcc8f77f163ae721b (diff)
Closed #1723: Merging pjsua2 branch into trunk
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4704 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib')
-rw-r--r--pjlib/build/os-auto.mak.in3
-rw-r--r--pjlib/include/pj/compat/cc_gcc.h2
-rw-r--r--pjlib/include/pj/string.h9
-rw-r--r--pjlib/include/pj/types.h17
-rw-r--r--pjlib/src/pj/string.c38
5 files changed, 60 insertions, 9 deletions
diff --git a/pjlib/build/os-auto.mak.in b/pjlib/build/os-auto.mak.in
index 3f35dce6..1c7e330e 100644
--- a/pjlib/build/os-auto.mak.in
+++ b/pjlib/build/os-auto.mak.in
@@ -23,7 +23,8 @@ export TEST_OBJS += @ac_main_obj@
#
# Additional LDFLAGS for pjlib-test
#
-export TEST_LDFLAGS += @LDFLAGS@ @LIBS@
+# Disabled, as this causes duplicated LDFLAGS, which may raise linking errors
+#export TEST_LDFLAGS += @LDFLAGS@ @LIBS@
#
# TARGETS are make targets in the Makefile, to be executed for this given
diff --git a/pjlib/include/pj/compat/cc_gcc.h b/pjlib/include/pj/compat/cc_gcc.h
index df257029..37f361b0 100644
--- a/pjlib/include/pj/compat/cc_gcc.h
+++ b/pjlib/include/pj/compat/cc_gcc.h
@@ -63,7 +63,7 @@
#endif
#define PJ_INT64(val) val##LL
-#define PJ_UINT64(val) val##LLU
+#define PJ_UINT64(val) val##ULL
#define PJ_INT64_FMT "L"
diff --git a/pjlib/include/pj/string.h b/pjlib/include/pj/string.h
index 525b4c05..57c496f3 100644
--- a/pjlib/include/pj/string.h
+++ b/pjlib/include/pj/string.h
@@ -575,6 +575,15 @@ PJ_DECL(unsigned long) pj_strtoul2(const pj_str_t *str, pj_str_t *endptr,
unsigned base);
/**
+ * Convert string to float.
+ *
+ * @param str the string.
+ *
+ * @return the value.
+ */
+PJ_DECL(float) pj_strtof(const pj_str_t *str);
+
+/**
* Utility to convert unsigned integer to string. Note that the
* string will be NULL terminated.
*
diff --git a/pjlib/include/pj/types.h b/pjlib/include/pj/types.h
index 420ddd9b..0e0e2d9a 100644
--- a/pjlib/include/pj/types.h
+++ b/pjlib/include/pj/types.h
@@ -86,15 +86,18 @@ typedef int pj_bool_t;
# define PJ_T(literal_str) literal_str
#endif
+/** Some constants */
+enum pj_constants_
+{
+ /** Status is OK. */
+ PJ_SUCCESS=0,
-/** Status is OK. */
-#define PJ_SUCCESS 0
-
-/** True value. */
-#define PJ_TRUE 1
+ /** True value. */
+ PJ_TRUE=1,
-/** False value. */
-#define PJ_FALSE 0
+ /** False value. */
+ PJ_FALSE=0
+};
/**
* File offset type.
diff --git a/pjlib/src/pj/string.c b/pjlib/src/pj/string.c
index 5610c907..d62b674a 100644
--- a/pjlib/src/pj/string.c
+++ b/pjlib/src/pj/string.c
@@ -175,6 +175,44 @@ PJ_DEF(unsigned long) pj_strtoul2(const pj_str_t *str, pj_str_t *endptr,
return value;
}
+PJ_DEF(float) pj_strtof(const pj_str_t *str)
+{
+ pj_str_t part;
+ char *pdot;
+ float val;
+
+ if (str->slen == 0)
+ return 0;
+
+ pdot = (char*)pj_memchr(str->ptr, '.', str->slen);
+ part.ptr = str->ptr;
+ part.slen = pdot ? pdot - str->ptr : str->slen;
+
+ if (part.slen)
+ val = (float)pj_strtol(&part);
+ else
+ val = 0;
+
+ if (pdot) {
+ part.ptr = pdot + 1;
+ part.slen = (str->ptr + str->slen - pdot - 1);
+ if (part.slen) {
+ pj_str_t endptr;
+ float fpart, fdiv;
+ int i;
+ fpart = (float)pj_strtoul2(&part, &endptr, 10);
+ fdiv = 1.0;
+ for (i=0; i<(part.slen - endptr.slen); ++i)
+ fdiv = fdiv * 10;
+ if (val >= 0)
+ val += (fpart / fdiv);
+ else
+ val -= (fpart / fdiv);
+ }
+ }
+ return val;
+}
+
PJ_DEF(int) pj_utoa(unsigned long val, char *buf)
{
return pj_utoa_pad(val, buf, 0, 0);