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