diff options
author | landry <> | 2008-06-13 21:04:24 +0000 |
---|---|---|
committer | landry <> | 2008-06-13 21:04:24 +0000 |
commit | 6b7d41f8c5a19961e127bc5168f899e7da8fee47 (patch) | |
tree | fc7d9970d453f9eddc142fd9d15084c181505b45 /src/lib/libc/stdlib/strtof.c | |
parent | f8a6cc0c54595fc7b66a29e5c4423c6d2b6e9a3f (diff) | |
download | openbsd-6b7d41f8c5a19961e127bc5168f899e7da8fee47.tar.gz openbsd-6b7d41f8c5a19961e127bc5168f899e7da8fee47.tar.bz2 openbsd-6b7d41f8c5a19961e127bc5168f899e7da8fee47.zip |
Add strtof() to libc, some ports seem to like it. Currently it's a simple
call to strtod() with bounding check.
Discussed with pyr@ and otto@
ok otto@ deraadt@
Diffstat (limited to 'src/lib/libc/stdlib/strtof.c')
-rw-r--r-- | src/lib/libc/stdlib/strtof.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/lib/libc/stdlib/strtof.c b/src/lib/libc/stdlib/strtof.c new file mode 100644 index 0000000000..8c8db47ad8 --- /dev/null +++ b/src/lib/libc/stdlib/strtof.c | |||
@@ -0,0 +1,39 @@ | |||
1 | /* $OpenBSD: strtof.c,v 1.1 2008/06/13 21:04:24 landry Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Landry Breuil | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Permission to use, copy, modify, and distribute this software for any | ||
8 | * purpose with or without fee is hereby granted, provided that the above | ||
9 | * copyright notice and this permission notice appear in all copies. | ||
10 | * | ||
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
18 | */ | ||
19 | |||
20 | #include <errno.h> | ||
21 | #include <limits.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <math.h> | ||
24 | |||
25 | float | ||
26 | strtof(const char *s00, char **se) | ||
27 | { | ||
28 | double d; | ||
29 | |||
30 | d = strtod(s00, se); | ||
31 | if (d > FLT_MAX) { | ||
32 | errno = ERANGE; | ||
33 | return (FLT_MAX); | ||
34 | } else if (d < -FLT_MAX) { | ||
35 | errno = ERANGE; | ||
36 | return (-FLT_MAX); | ||
37 | } | ||
38 | return ((float) d); | ||
39 | } | ||