[pulseaudio-commits] r1846 - in /branches/lennart: configure.ac src/pulsecore/core-util.c src/pulsecore/core-util.h

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Mon Sep 17 15:39:52 PDT 2007


Author: lennart
Date: Tue Sep 18 00:39:51 2007
New Revision: 1846

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1846&root=pulseaudio&view=rev
Log:
add a locale-independant pa_atof() implementation

Modified:
    branches/lennart/configure.ac
    branches/lennart/src/pulsecore/core-util.c
    branches/lennart/src/pulsecore/core-util.h

Modified: branches/lennart/configure.ac
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/configure.ac?rev=1846&root=pulseaudio&r1=1845&r2=1846&view=diff
==============================================================================
--- branches/lennart/configure.ac (original)
+++ branches/lennart/configure.ac Tue Sep 18 00:39:51 2007
@@ -291,7 +291,7 @@
 
 # Non-standard
 
-AC_CHECK_FUNCS([setresuid setresgid setreuid setregid seteuid setegid ppoll strsignal sig2str])
+AC_CHECK_FUNCS([setresuid setresgid setreuid setregid seteuid setegid ppoll strsignal sig2str strtof_l])
 
 #### POSIX threads ####
 

Modified: branches/lennart/src/pulsecore/core-util.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/core-util.c?rev=1846&root=pulseaudio&r1=1845&r2=1846&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/core-util.c (original)
+++ branches/lennart/src/pulsecore/core-util.c Tue Sep 18 00:39:51 2007
@@ -42,6 +42,10 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 
+#ifdef HAVE_STRTOF_L
+#include <locale.h>
+#endif
+
 #ifdef HAVE_SCHED_H
 #include <sched.h>
 #endif
@@ -1221,11 +1225,15 @@
     pa_assert(s);
     pa_assert(ret_i);
 
+    errno = 0;
     l = strtol(s, &x, 0);
 
-    if (!x || *x)
+    if (!x || *x || errno != 0)
         return -1;
 
+    if ((int32_t) l != l)
+        return -1;
+    
     *ret_i = (int32_t) l;
 
     return 0;
@@ -1239,14 +1247,63 @@
     pa_assert(s);
     pa_assert(ret_u);
 
+    errno = 0;
     l = strtoul(s, &x, 0);
 
-    if (!x || *x)
+    if (!x || *x || errno != 0)
         return -1;
 
+    if ((uint32_t) l != l)
+        return -1;
+
     *ret_u = (uint32_t) l;
 
     return 0;
+}
+
+#ifdef HAVE_STRTOF_L
+static locale_t c_locale = NULL;
+
+static void c_locale_destroy(void) {
+    freelocale(c_locale);
+}
+#endif
+
+int pa_atof(const char *s, float *ret_f) {
+    char *x = NULL;
+    float f;
+    int r = 0;
+    
+    pa_assert(s);
+    pa_assert(ret_f);
+
+    /* This should be locale independent */
+    
+#ifdef HAVE_STRTOF_L
+    
+    PA_ONCE_BEGIN {
+        
+        if ((c_locale = newlocale(LC_ALL_MASK, "C", NULL)))
+            atexit(c_locale_destroy);
+        
+    } PA_ONCE_END;
+    
+    if (c_locale) {
+        errno = 0;
+        f = strtof_l(s, &x, c_locale);
+    } else
+#endif
+    {
+        errno = 0;
+        f = strtof(s, &x);
+    }
+
+    if (!x || *x || errno != 0)
+        r =  -1;
+    else
+        *ret_f = f;
+    
+    return r;
 }
 
 /* Same as snprintf, but guarantees NUL-termination on every platform */

Modified: branches/lennart/src/pulsecore/core-util.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/core-util.h?rev=1846&root=pulseaudio&r1=1845&r2=1846&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/core-util.h (original)
+++ branches/lennart/src/pulsecore/core-util.h Tue Sep 18 00:39:51 2007
@@ -92,6 +92,7 @@
 
 int pa_atoi(const char *s, int32_t *ret_i);
 int pa_atou(const char *s, uint32_t *ret_u);
+int pa_atof(const char *s, float *ret_f);
 
 int pa_snprintf(char *str, size_t size, const char *format, ...);
 




More information about the pulseaudio-commits mailing list