1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Test of getcwd() function.
4 Copyright (C) 2009-2011 Free Software Foundation, Inc.
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "signature.h"
24 SIGNATURE_CHECK (getcwd, char *, (char *, size_t));
34 main (int argc, char **argv)
38 /* If the user provides an argument, attempt to chdir there first. */
41 if (chdir (argv[1]) == 0)
42 printf ("changed to directory %s\n", argv[1]);
45 pwd1 = getcwd (NULL, 0);
46 ASSERT (pwd1 && *pwd1);
48 printf ("cwd=%s\n", pwd1);
50 /* Make sure the result is usable. */
51 ASSERT (chdir (pwd1) == 0);
52 ASSERT (chdir (".//./.") == 0);
54 /* Make sure that result is normalized. */
55 pwd2 = getcwd (NULL, 0);
57 ASSERT (strcmp (pwd1, pwd2) == 0);
60 size_t len = strlen (pwd1);
64 pwd2 = getcwd (NULL, len + 1);
67 pwd2 = malloc (len + 2);
68 for ( ; i <= len; i++)
72 ASSERT (getcwd (pwd2, i) == NULL);
73 ASSERT (errno == ERANGE);
74 /* Allow either glibc or BSD behavior, since POSIX allows both. */
76 tmp = getcwd (NULL, i);
79 ASSERT (strcmp (pwd1, tmp) == 0);
84 ASSERT (errno == ERANGE);
87 ASSERT (getcwd (pwd2, len + 1) == pwd2);
91 ASSERT (strstr (pwd2, "/./") == NULL);
92 ASSERT (strstr (pwd2, "/../") == NULL);
93 ASSERT (strstr (pwd2 + 1 + (pwd2[1] == '/'), "//") == NULL);
95 /* Validate a POSIX requirement on size. */
97 ASSERT (getcwd(pwd2, 0) == NULL);
98 ASSERT (errno == EINVAL);