1 //===-- Unittests for getcwd ----------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/__support/CPP/string_view.h"
10 #include "src/errno/libc_errno.h"
11 #include "src/stdlib/getenv.h"
12 #include "src/unistd/getcwd.h"
14 #include "test/IntegrationTest/test.h"
16 #include <stdlib.h> // For malloc and free
18 using LIBC_NAMESPACE::cpp::string_view
;
20 TEST_MAIN(int argc
, char **argv
, char **envp
) {
22 ASSERT_TRUE(string_view(LIBC_NAMESPACE::getenv("PWD")) ==
23 LIBC_NAMESPACE::getcwd(buffer
, 1024));
26 char *cwd
= LIBC_NAMESPACE::getcwd(nullptr, 0);
27 ASSERT_TRUE(string_view(LIBC_NAMESPACE::getenv("PWD")) == cwd
);
31 cwd
= LIBC_NAMESPACE::getcwd(buffer
, 0);
32 ASSERT_TRUE(cwd
== nullptr);
33 ASSERT_EQ(libc_errno
, EINVAL
);
37 cwd
= LIBC_NAMESPACE::getcwd(buffer
, 2);
38 ASSERT_TRUE(cwd
== nullptr);
40 ASSERT_EQ(err
, ERANGE
);