[flang] Fix length handling in character kind implicit conversion (#74586)
[llvm-project.git] / libc / test / integration / src / unistd / getcwd_test.cpp
blob3d8f5821a69efcb58eb077d67ff287dc71e4eac9
1 //===-- Unittests for getcwd ----------------------------------------------===//
2 //
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
6 //
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) {
21 char buffer[1024];
22 ASSERT_TRUE(string_view(LIBC_NAMESPACE::getenv("PWD")) ==
23 LIBC_NAMESPACE::getcwd(buffer, 1024));
25 // nullptr buffer
26 char *cwd = LIBC_NAMESPACE::getcwd(nullptr, 0);
27 ASSERT_TRUE(string_view(LIBC_NAMESPACE::getenv("PWD")) == cwd);
28 free(cwd);
30 // Bad size
31 cwd = LIBC_NAMESPACE::getcwd(buffer, 0);
32 ASSERT_TRUE(cwd == nullptr);
33 ASSERT_EQ(libc_errno, EINVAL);
34 libc_errno = 0;
36 // Insufficient size
37 cwd = LIBC_NAMESPACE::getcwd(buffer, 2);
38 ASSERT_TRUE(cwd == nullptr);
39 int err = libc_errno;
40 ASSERT_EQ(err, ERANGE);
42 return 0;