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