1 /* Test of getcwd function.
2 Copyright (C) 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 2000.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library 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 GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
26 #include <sys/param.h>
29 #define TEST_FUNCTION do_test ()
33 char thepath
[4096]; /* Yes, this limits the environment this test
34 can run it but I honestly don't care about
35 people which have this problem. */
42 if (getcwd (thepath
, sizeof thepath
) == NULL
)
45 /* The path is too long, skip all tests. */
48 puts ("getcwd (thepath, sizeof thepath) failed");
51 len
= strlen (thepath
);
57 for (i
= 0; i
< 4; ++i
)
60 bufs
[i
] = (char *) malloc (sbs
);
63 bufs
[i
] = getcwd (NULL
, sbs
);
67 puts ("getcwd (NULL, sbs) failed");
72 for (; i
< 10; sbs
>>= 1, ++i
)
74 bufs
[i
] = (char *) malloc (MAX (1, sbs
));
78 /* Before we test the result write something in the memory to see
79 whether the allocation went right. */
80 for (i
= 0; i
< 10; ++i
)
81 if (i
!= 4 && bufs
[i
] != NULL
)
82 memset (bufs
[i
], '\xff', lens
[i
]);
84 if (strcmp (thepath
, bufs
[4]) != 0)
87 getcwd (NULL, sbs) = \"%s\", getcwd (thepath, sizeof thepath) = \"%s\"\n",
92 /* Now overwrite all buffers to see that getcwd allocated the buffer
94 for (i
= 0; i
< 10; ++i
)
95 memset (bufs
[i
], i
, lens
[i
]);
97 for (i
= 0; i
< 10; ++i
)
100 /* Test whether the function signals success despite the buffer
102 if (getcwd (NULL
, len
) != NULL
)
104 puts ("getcwd (NULL, len) didn't failed");
108 bufs
[0] = malloc (len
);
109 bufs
[1] = malloc (len
);
110 bufs
[2] = malloc (len
);
113 if (getcwd (bufs
[1], len
) != NULL
)
115 puts ("getcwd (bufs[1], len) didn't failed");
123 memset (thepath
, '\xfe', sizeof (thepath
));
124 if (getcwd (thepath
, len
) != NULL
)
126 puts ("getcwd (thepath, len) didn't failed");
130 for (i
= len
; i
< sizeof thepath
; ++i
)
131 if (thepath
[i
] != '\xfe')
133 puts ("thepath[i] != '\xfe'");
137 /* Now test handling of correctly sized buffers. */
138 bufs
[0] = getcwd (NULL
, len
+ 1);
141 puts ("getcwd (NULL, len + 1) failed");
146 memset (thepath
, '\xff', sizeof thepath
);
147 if (getcwd (thepath
, len
+ 1) == NULL
)
149 puts ("getcwd (thepath, len + 1) failed");
153 for (i
= len
+ 1; i
< sizeof thepath
; ++i
)
154 if (thepath
[i
] != '\xff')
156 printf ("thepath[%d] != '\xff'\n", i
);
160 puts ("everything OK");
165 #include "../test-skeleton.c"