This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <config.h>
18
19
20
21 #define _GL_NO_LARGE_FILES
22 #include <stdio.h>
23
24 #include <string.h>
25
26 #include "macros.h"
27
28 #define TESTFILE "t-ftell3.tmp"
29
30 int
31 main (void)
32 {
33 FILE *fp;
34
35
36 fp = fopen (TESTFILE, "w");
37 if (fp == NULL)
38 goto skip;
39 if (fwrite ("foogarsh", 1, 8, fp) < 8)
40 goto skip;
41 if (fclose (fp))
42 goto skip;
43
44
45
46
47 fp = fopen (TESTFILE, "r+");
48 if (fp == NULL)
49 goto skip;
50 if (fseek (fp, -1, SEEK_END))
51 goto skip;
52 ASSERT (getc (fp) == 'h');
53 ASSERT (getc (fp) == EOF);
54 ASSERT (ftell (fp) == 8);
55 ASSERT (ftell (fp) == 8);
56 ASSERT (putc ('!', fp) == '!');
57 ASSERT (ftell (fp) == 9);
58 ASSERT (fclose (fp) == 0);
59 fp = fopen (TESTFILE, "r");
60 if (fp == NULL)
61 goto skip;
62 {
63 char buf[10];
64 ASSERT (fread (buf, 1, 10, fp) == 9);
65 ASSERT (memcmp (buf, "foogarsh!", 9) == 0);
66 }
67 ASSERT (fclose (fp) == 0);
68
69
70
71 remove (TESTFILE);
72 return 0;
73
74 skip:
75 fprintf (stderr, "Skipping test: prerequisite file operations failed.\n");
76 remove (TESTFILE);
77 return 77;
78 }