Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.access
libc.src.unistd.chdir
libc.src.unistd.chown
libc.src.unistd.confstr
libc.src.unistd.close
libc.src.unistd.dup
libc.src.unistd.dup2
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.access
libc.src.unistd.chdir
libc.src.unistd.chown
libc.src.unistd.confstr
libc.src.unistd.close
libc.src.unistd.dup
libc.src.unistd.dup2
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.access
libc.src.unistd.chdir
libc.src.unistd.chown
libc.src.unistd.confstr
libc.src.unistd.close
libc.src.unistd.dup
libc.src.unistd.dup2
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.access
libc.src.unistd.chdir
libc.src.unistd.chown
libc.src.unistd.confstr
libc.src.unistd.close
libc.src.unistd.dup
libc.src.unistd.dup2
Expand Down
8 changes: 8 additions & 0 deletions libc/include/unistd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ functions:
- type: const char *
- type: uid_t
- type: gid_t
- name: confstr
standards:
- posix
return_type: size_t
arguments:
- type: int
- type: char *
- type: size_t
- name: close
standards:
- posix
Expand Down
16 changes: 16 additions & 0 deletions libc/src/unistd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ add_entrypoint_object(
.${LIBC_TARGET_OS}.chown
)

add_entrypoint_object(
confstr
SRCS
confstr.cpp
HDRS
confstr.h
DEPENDS
libc.hdr.errno_macros

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need libc.src.errno.errno dependency here to actually set it.

libc.hdr.types.size_t
libc.hdr.unistd_macros
libc.src.__support.common
libc.src.__support.libc_errno
libc.src.__support.macros.config
libc.src.errno.errno
)

add_entrypoint_object(
close
ALIAS
Expand Down
30 changes: 30 additions & 0 deletions libc/src/unistd/confstr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Implementation of confstr
///
//===----------------------------------------------------------------------===//

#include "src/unistd/confstr.h"

#include "hdr/errno_macros.h"
#include "hdr/types/size_t.h"
#include "hdr/unistd_macros.h"
#include "src/__support/common.h"
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(size_t, confstr, (int, char *, size_t)) {
libc_errno = EINVAL;
return 0;
}

} // namespace LIBC_NAMESPACE_DECL
26 changes: 26 additions & 0 deletions libc/src/unistd/confstr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Implementation header for confstr
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_UNISTD_CONFSTR_H
#define LLVM_LIBC_SRC_UNISTD_CONFSTR_H

#include "hdr/types/size_t.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

size_t confstr(int name, char *buf, size_t len);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_UNISTD_CONFSTR_H
14 changes: 14 additions & 0 deletions libc/test/src/unistd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,20 @@ add_libc_test(
)


add_libc_test(
confstr_test
SUITE
libc_unistd_unittests
SRCS
confstr_test.cpp
DEPENDS
libc.hdr.errno_macros
libc.hdr.types.size_t
libc.src.unistd.confstr
libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)

add_libc_test(
sysconf_test
SUITE
Expand Down
31 changes: 31 additions & 0 deletions libc/test/src/unistd/confstr_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Unittests for confstr
///
//===----------------------------------------------------------------------===//

#include "src/unistd/confstr.h"

#include "hdr/errno_macros.h"
#include "hdr/types/size_t.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"

using LlvmLibcConfStrTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;

TEST_F(LlvmLibcConfStrTest, InvalidName) {
char buf[64] = "initial";
EXPECT_THAT(LIBC_NAMESPACE::confstr(0, buf, sizeof(buf)),
Fails(EINVAL, size_t(0)));
EXPECT_THAT(LIBC_NAMESPACE::confstr(0, nullptr, 0), Fails(EINVAL, size_t(0)));
EXPECT_THAT(LIBC_NAMESPACE::confstr(-1, buf, sizeof(buf)),
Fails(EINVAL, size_t(0)));
}
Loading