1 /* Test of getcwd() function.
2 Copyright (C) 2009 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 2 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 <http://www.gnu.org/licenses/>. */
21 #include "signature.h"
22 SIGNATURE_CHECK (getcwd, char *, (char *, size_t));
28 #define ASSERT(expr) \
33 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
41 main (int argc, char **argv)
45 /* If the user provides an argument, attempt to chdir there first. */
48 if (chdir (argv[1]) == 0)
49 printf ("changed to directory %s\n", argv[1]);
52 pwd1 = getcwd (NULL, 0);
53 ASSERT (pwd1 && *pwd1);
55 printf ("cwd=%s\n", pwd1);
57 /* Make sure the result is usable. */
58 ASSERT (chdir (pwd1) == 0);
59 ASSERT (chdir ("././.") == 0);
61 /* Make sure that result is normalized. */
62 pwd2 = getcwd (NULL, 0);
64 ASSERT (strcmp (pwd1, pwd2) == 0);
67 size_t len = strlen (pwd1);
71 pwd2 = malloc (len + 2);
73 ASSERT (getcwd (pwd2, i) == NULL);
74 pwd2 = getcwd (pwd2, len + 1);
79 ASSERT (strstr (pwd2, "/./") == NULL);
80 ASSERT (strstr (pwd2, "/../") == NULL);