usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-ftell3.c
blob5e777d1e7c4955f86d05f0a8b0be591ba7079b68
1 /* Test of ftell() function.
2 Copyright (C) 2007-2024 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/>. */
17 #include <config.h>
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
22 #include <stdio.h>
24 #include <string.h>
26 #include "macros.h"
28 #define TESTFILE "t-ftell3.tmp"
30 int
31 main (void)
33 FILE *fp;
35 /* Create a file with some contents. */
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;
44 /* The file's contents is now "foogarsh". */
46 /* Try writing after reading to EOF. */
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;
63 char buf[10];
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!". */
71 remove (TESTFILE);
72 return test_exit_status;
74 skip:
75 remove (TESTFILE);
76 if (test_exit_status != EXIT_SUCCESS)
77 return test_exit_status;
78 fprintf (stderr, "Skipping test: prerequisite file operations failed.\n");
79 return 77;