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