1 /* Test of lseek() 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 Eric Blake, 2007. */
26 #define ASSERT(expr) \
31 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
37 /* ARGC must be 2; *ARGV[1] is '0' if stdin and stdout are files, '1'
38 if they are pipes, and '2' if they are closed. Check for proper
39 semantics of lseek. */
41 main (int argc, char **argv)
47 case '0': /* regular files */
48 ASSERT (lseek (0, (off_t)2, SEEK_SET) == 2);
49 ASSERT (lseek (0, (off_t)-4, SEEK_CUR) == -1);
50 ASSERT (errno == EINVAL);
52 ASSERT (lseek (0, (off_t)0, SEEK_CUR) == 2);
53 ASSERT (lseek (0, (off_t)0, (SEEK_SET | SEEK_CUR | SEEK_END) + 1) == -1);
54 ASSERT (errno == EINVAL);
55 ASSERT (lseek (1, (off_t)2, SEEK_SET) == 2);
57 ASSERT (lseek (1, (off_t)-4, SEEK_CUR) == -1);
58 ASSERT (errno == EINVAL);
60 ASSERT (lseek (1, (off_t)0, SEEK_CUR) == 2);
61 ASSERT (lseek (1, (off_t)0, (SEEK_SET | SEEK_CUR | SEEK_END) + 1) == -1);
62 ASSERT (errno == EINVAL);
67 ASSERT (lseek (0, (off_t)0, SEEK_CUR) == -1);
68 ASSERT (errno == ESPIPE);
70 ASSERT (lseek (1, (off_t)0, SEEK_CUR) == -1);
71 ASSERT (errno == ESPIPE);
74 case '2': /* closed */
76 ASSERT (lseek (0, (off_t)0, SEEK_CUR) == -1);
77 ASSERT (errno == EBADF);
79 ASSERT (lseek (1, (off_t)0, SEEK_CUR) == -1);
80 ASSERT (errno == EBADF);