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