mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:07:35 +00:00
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.
This commit is contained in:
parent
3526fbbc5f
commit
c81b3e1ee3
4 changed files with 40 additions and 0 deletions
18
Tests/LibC/TestLibCString.cpp
Normal file
18
Tests/LibC/TestLibCString.cpp
Normal file
|
@ -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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue