Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / tcg / cris / libc / check_openpf3.c
blob557adee92dec037d1abc32d9aaf1818e964d764c
1 /* Basic file operations (rename, unlink); once without sysroot. We
2 also test that the simulator has chdir:ed to PREFIX, when defined. */
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>
11 #ifndef PREFIX
12 #define PREFIX
13 #endif
15 void err (const char *s)
17 perror (s);
18 abort ();
21 int main (int argc, char *argv[])
23 FILE *f;
24 struct stat buf;
26 unlink (PREFIX "testfoo2.tmp");
28 f = fopen ("testfoo1.tmp", "w");
29 if (f == NULL)
30 err ("open");
31 fclose (f);
33 if (rename (PREFIX "testfoo1.tmp", PREFIX "testfoo2.tmp") != 0)
34 err ("rename");
36 if (stat (PREFIX "testfoo2.tmp", &buf) != 0
37 || !S_ISREG (buf.st_mode))
38 err ("stat 1");
40 if (stat ("testfoo2.tmp", &buf) != 0
41 || !S_ISREG (buf.st_mode))
42 err ("stat 2");
44 if (unlink (PREFIX "testfoo2.tmp") != 0)
45 err ("unlink");
47 printf ("pass\n");
48 return 0;