1 /* Test of ftell() function.
2 Copyright (C) 2007-2020 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
19 /* None of the files accessed by this test are large, so disable the
20 fseek link warning if we are not using the gnulib fseek module. */
21 #define _GL_NO_LARGE_FILES
28 #define TESTFILE "t-ftell3.tmp"
35 /* Create a file with some contents. */
36 fp
= fopen (TESTFILE
, "w");
39 if (fwrite ("foogarsh", 1, 8, fp
) < 8)
44 /* The file's contents is now "foogarsh". */
46 /* Try writing after reading to EOF. */
47 fp
= fopen (TESTFILE
, "r+");
50 if (fseek (fp
, -1, SEEK_END
))
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");
64 ASSERT (fread (buf
, 1, 10, fp
) == 9);
65 ASSERT (memcmp (buf
, "foogarsh!", 9) == 0);
67 ASSERT (fclose (fp
) == 0);
69 /* The file's contents is now "foogarsh!". */
75 fprintf (stderr
, "Skipping test: prerequisite file operations failed.\n");