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 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 <http://www.gnu.org/licenses/>. */
17 /* Written by Eric Blake, 2007. */
25 #define ASSERT(expr) \
30 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
36 /* ARGC must be 2; *ARGV[1] is '0' if stdin and stdout are files, '1'
37 if they are pipes, and '2' if they are closed. Check for proper
38 semantics of lseek. */
40 main (int argc, char **argv)
46 case '0': /* regular files */
47 ASSERT (lseek (0, (off_t)2, SEEK_SET) == 2);
48 ASSERT (lseek (0, (off_t)-4, SEEK_CUR) == -1);
49 ASSERT (errno == EINVAL);
51 #if ! defined __BEOS__
52 /* POSIX says that the last lseek call, when failing, does not change
53 the current offset. But BeOS sets it to 0. */
54 ASSERT (lseek (0, (off_t)0, SEEK_CUR) == 2);
56 #if 0 /* leads to SIGSYS on IRIX 6.5 */
57 ASSERT (lseek (0, (off_t)0, (SEEK_SET | SEEK_CUR | SEEK_END) + 1) == -1);
58 ASSERT (errno == EINVAL);
60 ASSERT (lseek (1, (off_t)2, SEEK_SET) == 2);
62 ASSERT (lseek (1, (off_t)-4, SEEK_CUR) == -1);
63 ASSERT (errno == EINVAL);
65 #if ! defined __BEOS__
66 /* POSIX says that the last lseek call, when failing, does not change
67 the current offset. But BeOS sets it to 0. */
68 ASSERT (lseek (1, (off_t)0, SEEK_CUR) == 2);
70 #if 0 /* leads to SIGSYS on IRIX 6.5 */
71 ASSERT (lseek (1, (off_t)0, (SEEK_SET | SEEK_CUR | SEEK_END) + 1) == -1);
72 ASSERT (errno == EINVAL);
78 ASSERT (lseek (0, (off_t)0, SEEK_CUR) == -1);
79 ASSERT (errno == ESPIPE);
81 ASSERT (lseek (1, (off_t)0, SEEK_CUR) == -1);
82 ASSERT (errno == ESPIPE);
85 case '2': /* closed */
86 /* Explicitly close file descriptors 0 and 1. The <&- and >&- in the
87 invoking shell are not enough on HP-UX. */
91 ASSERT (lseek (0, (off_t)0, SEEK_CUR) == -1);
92 ASSERT (errno == EBADF);
94 ASSERT (lseek (1, (off_t)0, SEEK_CUR) == -1);
95 ASSERT (errno == EBADF);