5a0d8785caf27045eda07b21a7aa468bbf392f7f
[deliverable/binutils-gdb.git] / sim / testsuite / sim / cris / c / readlink2.c
1 /*
2 #notarget: cris*-*-elf
3 */
4
5 #include <unistd.h>
6 #include <errno.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11 int main (int argc, char *argv[])
12 {
13 char buf[1024];
14 char buf2[1024];
15
16 /* This is a special feature handled in the simulator. The "42"
17 should be formed from getpid () if this was a real program. */
18 if (readlink ("/proc/42/exe", buf, sizeof (buf)) < 0)
19 abort ();
20
21 /* Don't use an abort in the following; it might cause the printf to
22 not make it all the way to output and make debugging more
23 difficult. */
24
25 /* We assume the program is called with no path, so we might need to
26 prepend it. */
27 if (getcwd (buf2, sizeof (buf2)) != buf2)
28 {
29 perror ("getcwd");
30 exit (1);
31 }
32
33 if (argv[0][0] == '/')
34 {
35 #ifdef SYSROOTED
36 if (strchr (argv[0] + 1, '/') != NULL)
37 {
38 printf ("%s != %s\n", argv[0], strrchr (argv[0] + 1, '/'));
39 exit (1);
40 }
41 #endif
42 if (strcmp (argv[0], buf) != 0)
43 {
44 printf ("%s != %s\n", buf, argv[0]);
45 exit (1);
46 }
47 }
48 else if (argv[0][0] != '.')
49 {
50 if (buf2[strlen (buf2) - 1] != '/')
51 strcat (buf2, "/");
52 strcat (buf2, argv[0]);
53 if (strcmp (buf2, buf) != 0)
54 {
55 printf ("%s != %s\n", buf, buf2);
56 exit (1);
57 }
58 }
59 else
60 {
61 strcat (buf2, argv[0] + 1);
62 if (strcmp (buf, buf2) != 0)
63 {
64 printf ("%s != %s\n", buf, buf2);
65 exit (1);
66 }
67 }
68
69 printf ("pass\n");
70 exit (0);
71 }
72
73
This page took 0.032054 seconds and 3 git commands to generate.