mirror of
				https://github.com/alsa-project/alsa-lib.git
				synced 2025-11-03 09:01:52 -05:00 
			
		
		
		
	use "C" locale when parsing floating point numbers
Floating point numbers in configuration files always use "." as separator, so set the locale temporarily to "C" when calling strtod().
This commit is contained in:
		
							parent
							
								
									f9b9015245
								
							
						
					
					
						commit
						49c9eba8e4
					
				
					 1 changed files with 10 additions and 2 deletions
				
			
		
							
								
								
									
										12
									
								
								src/conf.c
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								src/conf.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -420,6 +420,7 @@ beginning:</P>
 | 
			
		|||
#include <limits.h>
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#include <pthread.h>
 | 
			
		||||
#include <locale.h>
 | 
			
		||||
#include "local.h"
 | 
			
		||||
 | 
			
		||||
#ifndef DOC_HIDDEN
 | 
			
		||||
| 
						 | 
				
			
			@ -497,12 +498,19 @@ static int safe_strtod(const char *str, double *val)
 | 
			
		|||
{
 | 
			
		||||
	char *end;
 | 
			
		||||
	double v;
 | 
			
		||||
	char *saved_locale;
 | 
			
		||||
	int err;
 | 
			
		||||
 | 
			
		||||
	if (!*str)
 | 
			
		||||
		return -EINVAL;
 | 
			
		||||
	saved_locale = setlocale(LC_NUMERIC, NULL);
 | 
			
		||||
	setlocale(LC_NUMERIC, "C");
 | 
			
		||||
	errno = 0;
 | 
			
		||||
	v = strtod(str, &end);
 | 
			
		||||
	if (errno)
 | 
			
		||||
		return -errno;
 | 
			
		||||
	err = -errno;
 | 
			
		||||
	setlocale(LC_NUMERIC, saved_locale);
 | 
			
		||||
	if (err)
 | 
			
		||||
		return err;
 | 
			
		||||
	if (*end)
 | 
			
		||||
		return -EINVAL;
 | 
			
		||||
	*val = v;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue