1 /* Test of lseek() function.
2 Copyright (C) 2007-2008 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__); \
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 #if ! defined __BEOS__
53 /* POSIX says that the last lseek call, when failing, does not change
54 the current offset. But BeOS sets it to 0. */
55 ASSERT (lseek (0, (off_t)0, SEEK_CUR) == 2);
57 #if 0 /* leads to SIGSYS on IRIX 6.5 */
58 ASSERT (lseek (0, (off_t)0, (SEEK_SET | SEEK_CUR | SEEK_END) + 1) == -1);
59 ASSERT (errno == EINVAL);
61 ASSERT (lseek (1, (off_t)2, SEEK_SET) == 2);
63 ASSERT (lseek (1, (off_t)-4, SEEK_CUR) == -1);
64 ASSERT (errno == EINVAL);
66 #if ! defined __BEOS__
67 /* POSIX says that the last lseek call, when failing, does not change
68 the current offset. But BeOS sets it to 0. */
69 ASSERT (lseek (1, (off_t)0, SEEK_CUR) == 2);
71 #if 0 /* leads to SIGSYS on IRIX 6.5 */
72 ASSERT (lseek (1, (off_t)0, (SEEK_SET | SEEK_CUR | SEEK_END) + 1) == -1);
73 ASSERT (errno == EINVAL);
79 ASSERT (lseek (0, (off_t)0, SEEK_CUR) == -1);
80 ASSERT (errno == ESPIPE);
82 ASSERT (lseek (1, (off_t)0, SEEK_CUR) == -1);
83 ASSERT (errno == ESPIPE);
86 case '2': /* closed */
87 /* Explicitly close file descriptors 0 and 1. The <&- and >&- in the
88 invoking shell are not enough on HP-UX. */
92 ASSERT (lseek (0, (off_t)0, SEEK_CUR) == -1);
93 ASSERT (errno == EBADF);
95 ASSERT (lseek (1, (off_t)0, SEEK_CUR) == -1);
96 ASSERT (errno == EBADF);