1 /* Test of wgetcwd() function.
2 Copyright (C) 2009-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
21 #include "signature.h"
22 #if defined _WIN32 && !defined __CYGWIN__
23 SIGNATURE_CHECK (wgetcwd
, wchar_t *, (wchar_t *, size_t));
35 #if defined _WIN32 && !defined __CYGWIN__
39 pwd1
= wgetcwd (NULL
, 0);
40 ASSERT (pwd1
&& *pwd1
);
42 /* Make sure the result is usable. */
43 ASSERT (_wchdir (pwd1
) == 0);
44 ASSERT (_wchdir (L
".//./.") == 0);
46 /* Make sure that result is normalized. */
47 pwd2
= wgetcwd (NULL
, 0);
49 ASSERT (wcscmp (pwd1
, pwd2
) == 0);
52 size_t len
= wcslen (pwd1
);
56 pwd2
= wgetcwd (NULL
, len
+ 1);
59 pwd2
= malloc ((len
+ 3) * sizeof (wchar_t));
60 for ( ; i
<= len
; i
++)
64 ASSERT (wgetcwd (pwd2
, i
) == NULL
);
65 ASSERT (errno
== ERANGE
);
66 /* Allow either glibc or BSD behavior, since POSIX allows both. */
68 tmp
= wgetcwd (NULL
, i
);
71 ASSERT (wcscmp (pwd1
, tmp
) == 0);
76 ASSERT (errno
== ERANGE
);
79 /* The SIZE argument here needs to be len + 3, not len + 1. */
80 ASSERT (wgetcwd (pwd2
, len
+ 3) == pwd2
);
82 pwd2
[len
+ 1] = L
'\0';
84 ASSERT (wcsstr (pwd2
, L
"/./") == NULL
);
85 ASSERT (wcsstr (pwd2
, L
"/../") == NULL
);
86 ASSERT (wcsstr (pwd2
+ 1 + (pwd2
[1] == L
'/'), L
"//") == NULL
);
88 /* Validate a POSIX requirement on size. */
90 ASSERT (wgetcwd (pwd2
, 0) == NULL
);
91 ASSERT (errno
== EINVAL
);
97 return test_exit_status
;