Ensure we always have symbols for atof, strtof, strtold.

We'll need a better implementation of strtold for LP64, but all our
long double functions are currently broken for LP64 anyway so this
isn't a regression.

Change-Id: I2bdebac11245d31521d5fa09a16331c03dc4339c
This commit is contained in:
Elliott Hughes 2014-03-12 16:12:57 -07:00
parent 56e1eebd39
commit 5a8173860d
6 changed files with 131 additions and 15 deletions

View File

@ -114,6 +114,7 @@ libc_bionic_src_files := \
bionic/abort.cpp \
bionic/access.cpp \
bionic/assert.cpp \
bionic/atof.cpp \
bionic/__bionic_name_mem.cpp \
bionic/bionic_time_conversions.cpp \
bionic/brk.cpp \
@ -188,8 +189,8 @@ libc_bionic_src_files := \
bionic/setegid.cpp \
bionic/__set_errno.cpp \
bionic/seteuid.cpp \
bionic/setpgrp.cpp \
bionic/setlocale.cpp \
bionic/setpgrp.cpp \
bionic/sigaction.cpp \
bionic/sigaddset.cpp \
bionic/sigdelset.cpp \
@ -207,12 +208,14 @@ libc_bionic_src_files := \
bionic/strerror.cpp \
bionic/strerror_r.cpp \
bionic/strsignal.cpp \
bionic/strtof.cpp \
bionic/strtold.cpp \
bionic/stubs.cpp \
bionic/symlink.cpp \
bionic/sysconf.cpp \
bionic/system_properties.cpp \
bionic/sys_siglist.c \
bionic/sys_signame.c \
bionic/system_properties.cpp \
bionic/tdestroy.cpp \
bionic/termios.cpp \
bionic/thread_atexit.cpp \

35
libc/bionic/atof.cpp Normal file
View File

@ -0,0 +1,35 @@
/*
* Copyright (C) 2014 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdlib.h>
double atof(const char* s) {
// Despite the 'f' in the name, this returns a double and is
// specified to be equivalent to strtod.
return strtod(s, NULL);
}

34
libc/bionic/strtof.cpp Normal file
View File

@ -0,0 +1,34 @@
/*
* Copyright (C) 2014 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdlib.h>
float strtof(const char* s, char** end_ptr) {
// TODO: upgrade to a non-hack implementation.
return strtod(s, end_ptr);
}

34
libc/bionic/strtold.cpp Normal file
View File

@ -0,0 +1,34 @@
/*
* Copyright (C) 2014 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdlib.h>
long double strtold(const char* s, char** end_ptr) {
// TODO: this is fine for LP32 where double == long double, but is broken on LP64.
return strtod(s, end_ptr);
}

View File

@ -60,23 +60,17 @@ extern long strtol(const char *, char **, int);
extern long long strtoll(const char *, char **, int);
extern unsigned long strtoul(const char *, char **, int);
extern unsigned long long strtoull(const char *, char **, int);
extern double strtod(const char *nptr, char **endptr);
extern int posix_memalign(void **memptr, size_t alignment, size_t size);
static __inline__ float strtof(const char *nptr, char **endptr)
{
return (float)strtod(nptr, endptr);
}
extern double atof(const char*);
extern double strtod(const char*, char**);
extern float strtof(const char*, char**);
extern long double strtold(const char*, char**);
extern int atoi(const char *) __purefunc;
extern long atol(const char *) __purefunc;
extern long long atoll(const char *) __purefunc;
static __inline__ double atof(const char *nptr)
{
return (strtod(nptr, NULL));
}
extern int atoi(const char*) __purefunc;
extern long atol(const char*) __purefunc;
extern long long atoll(const char*) __purefunc;
extern int abs(int) __pure2;
extern long labs(long) __pure2;

View File

@ -186,3 +186,19 @@ TEST(stdlib, system) {
ASSERT_TRUE(WIFEXITED(status));
ASSERT_EQ(1, WEXITSTATUS(status));
}
TEST(stdlib, atof) {
ASSERT_EQ(1.23, atof("1.23"));
}
TEST(stdlib, strtod) {
ASSERT_EQ(1.23, strtod("1.23", NULL));
}
TEST(stdlib, strtof) {
ASSERT_EQ(1.23, strtod("1.23", NULL));
}
TEST(stdlib, strtold) {
ASSERT_EQ(1.23, strtold("1.23", NULL));
}