1 /* Test of fpurge() function.
2 Copyright (C) 2007 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 2, or (at your option)
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, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
27 #define ASSERT(expr) if (!(expr)) abort ();
29 #define TESTFILE "t-fpurge.tmp"
36 /* Create a file with some contents. */
37 fp = fopen (TESTFILE, "w");
40 if (fwrite ("foobarsh", 1, 8, fp) < 8)
45 /* Open it in read-write mode. */
46 fp = fopen (TESTFILE, "r+");
49 if (fseek (fp, 3, SEEK_CUR))
51 if (fwrite ("g", 1, 1, fp) < 1)
55 if (fwrite ("az", 1, 2, fp) < 2)
57 ASSERT (fpurge (fp) == 0);
58 ASSERT (fclose (fp) == 0);
60 /* Open it in read-only mode. */
61 fp = fopen (TESTFILE, "r");
66 if (fread (buf, 1, 8, fp) < 8)
68 ASSERT (memcmp (buf, "foogarsh", 8) == 0);
70 ASSERT (fpurge (fp) == 0);
71 ASSERT (fclose (fp) == 0);
76 fprintf (stderr, "Skipping test: file operations failed.\n");