mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	spa: replace locale aware string functions with uselocale
Not all string functions have a POSIX compliant locale aware version (eg. strtof_l). Instead uselocale [1] should be used, which allows switching the locale of a thread to a welldefined one and restoring it afterwards. [1] https://man7.org/linux/man-pages/man3/uselocale.3.html
This commit is contained in:
		
							parent
							
								
									54f6f9293e
								
							
						
					
					
						commit
						f36f673b3b
					
				
					 1 changed files with 6 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -279,10 +279,9 @@ static inline float spa_strtof(const char *str, char **endptr)
 | 
			
		|||
	float v;
 | 
			
		||||
	if (SPA_UNLIKELY(locale == NULL))
 | 
			
		||||
		locale = newlocale(LC_ALL_MASK, "C", NULL);
 | 
			
		||||
	if (locale != NULL)
 | 
			
		||||
		v = strtof_l(str, endptr, locale);
 | 
			
		||||
	else
 | 
			
		||||
		v = strtof(str, endptr);
 | 
			
		||||
	locale_t prev = uselocale(locale);
 | 
			
		||||
	v = strtof(str, endptr);
 | 
			
		||||
	uselocale(prev);
 | 
			
		||||
	return v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -323,10 +322,9 @@ static inline double spa_strtod(const char *str, char **endptr)
 | 
			
		|||
	double v;
 | 
			
		||||
	if (SPA_UNLIKELY(locale == NULL))
 | 
			
		||||
		locale = newlocale(LC_ALL_MASK, "C", NULL);
 | 
			
		||||
	if (locale != NULL)
 | 
			
		||||
		v = strtod_l(str, endptr, locale);
 | 
			
		||||
	else
 | 
			
		||||
		v = strtod(str, endptr);
 | 
			
		||||
	locale_t prev = uselocale(locale);
 | 
			
		||||
	v = strtod(str, endptr);
 | 
			
		||||
	uselocale(prev);
 | 
			
		||||
	return v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue