diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-05-24 16:43:12 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-25 17:36:02 +0200 |
commit | c81b3e1ee3c005f1703f8a9e47b53b3ed836fc32 (patch) | |
tree | 1aa0cbd7edf718bfcf9dbf4c7eada0f67a0f48bc /Tests/LibC/TestLibCString.cpp | |
parent | 3526fbbc5f548935efc79bad3ce5d396a6d58e3b (diff) | |
download | serenity-c81b3e1ee3c005f1703f8a9e47b53b3ed836fc32.zip |
LibC: Implement strerror_r()
This implements the XSI-compliant version of strerror_r() - as opposed
to the GNU-specific variant.
The function explicitly saves errno so as to not accidentally change it
with one of the calls to other functions.
Diffstat (limited to 'Tests/LibC/TestLibCString.cpp')
-rw-r--r-- | Tests/LibC/TestLibCString.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Tests/LibC/TestLibCString.cpp b/Tests/LibC/TestLibCString.cpp new file mode 100644 index 0000000000..57ff705657 --- /dev/null +++ b/Tests/LibC/TestLibCString.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2021, Gunnar Beutner <gbeutner@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibTest/TestCase.h> +#include <errno.h> +#include <string.h> + +TEST_CASE(strerror_r_basic) +{ + EXPECT_EQ(strerror_r(1000, nullptr, 0), EINVAL); + EXPECT_EQ(strerror_r(EFAULT, nullptr, 0), ERANGE); + char buf[64]; + EXPECT_EQ(strerror_r(EFAULT, buf, sizeof(buf)), 0); + EXPECT_EQ(strcmp(buf, "Bad address"), 0); +} |