Changeset 0b00646d20a3401348b8673b7ec896cd7203a05b
- Timestamp:
- 21/05/08 21:12:24
(5 months ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1211397144 +0300
- git-parent:
[a2c338bb861ca781457ae23c8a36215a6ce82ea6]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1211397131 +0300
- Message:
us_strtod: do not make any kludgy assumptions about number formats
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r71f0e10 |
r0b00646 |
|
| 379 | 379 | |
|---|
| 380 | 380 | /** |
|---|
| 381 | | * us_strtod() has the same prototype as ANSI C strtod() but it expects |
|---|
| 382 | | * a dot as decimal separator regardless of the system locale. |
|---|
| | 381 | * us_strtod() has the same prototype as ANSI C strtod() but it uses the |
|---|
| | 382 | * POSIX/C decimal format, regardless of the current numeric locale. |
|---|
| 383 | 383 | */ |
|---|
| 384 | 384 | double us_strtod( const char *str, char **end ) |
|---|
| 385 | 385 | { |
|---|
| 386 | | char dup[strlen( str ) + 1], *ptr; |
|---|
| 387 | | double d; |
|---|
| 388 | | strcpy( dup, str ); |
|---|
| 389 | | |
|---|
| 390 | | ptr = strchr( dup, ',' ); |
|---|
| 391 | | if( ptr != NULL ) |
|---|
| 392 | | *ptr = '\0'; |
|---|
| 393 | | |
|---|
| 394 | | d = strtod( dup, &ptr ); |
|---|
| 395 | | if( end != NULL ) |
|---|
| 396 | | *end = (char *)&str[ptr - dup]; |
|---|
| 397 | | |
|---|
| 398 | | return d; |
|---|
| | 386 | locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL); |
|---|
| | 387 | locale_t oldloc = uselocale (loc); |
|---|
| | 388 | double res = strtod (str, end); |
|---|
| | 389 | |
|---|
| | 390 | if (loc != (locale_t)0) |
|---|
| | 391 | { |
|---|
| | 392 | uselocale (oldloc); |
|---|
| | 393 | freelocale (loc); |
|---|
| | 394 | } |
|---|
| | 395 | return res; |
|---|
| 399 | 396 | } |
|---|
| 400 | 397 | |
|---|