1 /* Check for corner case: readlink of too-long name.
2 #notarget: cris*-*-elf
3 */
4
5 #include <unistd.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <errno.h>
10 #include <stdarg.h>
11
bye(const char * s,int i)12 void bye (const char *s, int i)
13 {
14 fprintf (stderr, "%s: %d\n", s, i);
15 fflush (NULL);
16 abort ();
17 }
18
main(int argc,char * argv[])19 int main (int argc, char *argv[])
20 {
21 char *buf;
22 char buf2[1024];
23 int max, i;
24
25 /* We assume this limit is what we see in the simulator as well. */
26 #ifdef PATH_MAX
27 max = PATH_MAX;
28 #else
29 max = pathconf (argv[0], _PC_PATH_MAX);
30 #endif
31
32 max *= 10;
33
34 if (max <= 0)
35 bye ("path_max", max);
36
37 if ((buf = malloc (max + 1)) == NULL)
38 bye ("malloc", 0);
39
40 strcat (buf, argv[0]);
41
42 if (rindex (buf, '/') == NULL)
43 strcat (buf, "./");
44
45 for (i = rindex (buf, '/') - buf + 1; i < max; i++)
46 buf[i] = 'a';
47
48 buf [i] = 0;
49
50 i = readlink (buf, buf2, sizeof (buf2) - 1);
51 if (i != -1)
52 bye ("i", i);
53
54 if (errno != ENAMETOOLONG)
55 {
56 perror (buf);
57 bye ("errno", errno);
58 }
59
60 printf ("pass\n");
61 exit (0);
62 }
63