1*66e63ce3Schristos /* Basic file operations (rename, unlink); once without sysroot.  We
2*66e63ce3Schristos    also test that the simulator has chdir:ed to PREFIX, when defined.  */
3*66e63ce3Schristos 
4*66e63ce3Schristos #include <stdio.h>
5*66e63ce3Schristos #include <stdlib.h>
6*66e63ce3Schristos #include <errno.h>
7*66e63ce3Schristos #include <sys/types.h>
8*66e63ce3Schristos #include <sys/stat.h>
9*66e63ce3Schristos #include <unistd.h>
10*66e63ce3Schristos 
11*66e63ce3Schristos #ifndef PREFIX
12*66e63ce3Schristos #define PREFIX
13*66e63ce3Schristos #endif
14*66e63ce3Schristos 
err(const char * s)15*66e63ce3Schristos void err (const char *s)
16*66e63ce3Schristos {
17*66e63ce3Schristos   perror (s);
18*66e63ce3Schristos   abort ();
19*66e63ce3Schristos }
20*66e63ce3Schristos 
main(int argc,char * argv[])21*66e63ce3Schristos int main (int argc, char *argv[])
22*66e63ce3Schristos {
23*66e63ce3Schristos   FILE *f;
24*66e63ce3Schristos   struct stat buf;
25*66e63ce3Schristos 
26*66e63ce3Schristos   unlink (PREFIX "testfoo2.tmp");
27*66e63ce3Schristos 
28*66e63ce3Schristos   f = fopen ("testfoo1.tmp", "w");
29*66e63ce3Schristos   if (f == NULL)
30*66e63ce3Schristos     err ("open");
31*66e63ce3Schristos   fclose (f);
32*66e63ce3Schristos 
33*66e63ce3Schristos   if (rename (PREFIX "testfoo1.tmp", PREFIX "testfoo2.tmp") != 0)
34*66e63ce3Schristos     err ("rename");
35*66e63ce3Schristos 
36*66e63ce3Schristos   if (stat (PREFIX "testfoo2.tmp", &buf) != 0
37*66e63ce3Schristos       || !S_ISREG (buf.st_mode))
38*66e63ce3Schristos     err ("stat 1");
39*66e63ce3Schristos 
40*66e63ce3Schristos   if (stat ("testfoo2.tmp", &buf) != 0
41*66e63ce3Schristos       || !S_ISREG (buf.st_mode))
42*66e63ce3Schristos     err ("stat 2");
43*66e63ce3Schristos 
44*66e63ce3Schristos   if (unlink (PREFIX "testfoo2.tmp") != 0)
45*66e63ce3Schristos     err ("unlink");
46*66e63ce3Schristos 
47*66e63ce3Schristos   printf ("pass\n");
48*66e63ce3Schristos   return 0;
49*66e63ce3Schristos }
50