1*4b169a6bSchristos /* Check that --sysroot is applied to open(2). 2*4b169a6bSchristos #sim: --sysroot=$pwd 3*4b169a6bSchristos 4*4b169a6bSchristos We assume, with EXE being the name of the executable: 5*4b169a6bSchristos - The simulator executes with cwd the same directory where the executable 6*4b169a6bSchristos is located (also argv[0] contains a plain filename without directory 7*4b169a6bSchristos components -or- argv[0] contains the full non-sysroot path to EXE). 8*4b169a6bSchristos - There's no /EXE on the host file system. */ 9*4b169a6bSchristos 10*4b169a6bSchristos #include <stdio.h> 11*4b169a6bSchristos #include <stdlib.h> 12*4b169a6bSchristos #include <string.h> 13*4b169a6bSchristos #include <errno.h> main(int argc,char * argv[])14*4b169a6bSchristosint main (int argc, char *argv[]) 15*4b169a6bSchristos { 16*4b169a6bSchristos char *fnam = argv[0]; 17*4b169a6bSchristos FILE *f; 18*4b169a6bSchristos if (argv[0][0] != '/') 19*4b169a6bSchristos { 20*4b169a6bSchristos fnam = malloc (strlen (argv[0]) + 2); 21*4b169a6bSchristos if (fnam == NULL) 22*4b169a6bSchristos abort (); 23*4b169a6bSchristos strcpy (fnam, "/"); 24*4b169a6bSchristos strcat (fnam, argv[0]); 25*4b169a6bSchristos } 26*4b169a6bSchristos else 27*4b169a6bSchristos fnam = strrchr (argv[0], '/'); 28*4b169a6bSchristos 29*4b169a6bSchristos f = fopen (fnam, "rb"); 30*4b169a6bSchristos if (f == NULL) 31*4b169a6bSchristos abort (); 32*4b169a6bSchristos fclose (f); 33*4b169a6bSchristos 34*4b169a6bSchristos /* Cover another execution path. */ 35*4b169a6bSchristos if (fopen ("/nonexistent", "rb") != NULL 36*4b169a6bSchristos || errno != ENOENT) 37*4b169a6bSchristos abort (); 38*4b169a6bSchristos printf ("pass\n"); 39*4b169a6bSchristos return 0; 40*4b169a6bSchristos } 41