source: branches/libc-0.6/src/emx/testcase/lseek1.c

Last change on this file was 830, checked in by bird, 22 years ago

a little testcase.

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.3 KB
Line 
1/* $Id: lseek1.c 830 2003-10-12 14:00:12Z bird $ */
2/** @file
3 *
4 * Testcase for lseek which might be subject to bugs in DosSetFilePtrL().
5 *
6 * Copyright (c) 2003 knut st. osmundsen <bird-srcspam@anduin.net>
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with This program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25
26#include <unistd.h>
27#include <sys/fcntl.h>
28#include <errno.h>
29
30
31
32int main(int argc, char **argv)
33{
34 int rc = 0;
35 int fh;
36 off_t cb;
37 off_t off;
38
39
40 fh = open(argv[0], O_RDONLY, 0755);
41 if (fh < 0)
42 {
43 printf("error: Failed to open '%s', errno=%d\n", argv[0], errno);
44 return 1;
45 }
46
47 cb = lseek(fh, 0, SEEK_END);
48 if (cb < 0)
49 {
50 printf("error: Failed to seek to end of file errno=%d\n", errno);
51 rc++;
52 }
53
54 cb = tell(fh);
55 if (cb < 0)
56 {
57 printf("error: Failed to tell file position, errno=%d\n", errno);
58 rc++;
59 }
60
61 off = lseek(fh, -cb / 2, SEEK_END);
62 if (off < 0)
63 {
64 printf("error: Failed to seek to middle of file from the end, errno=%d\n", errno);
65 rc++;
66 }
67
68 off = lseek(fh, cb / 4, SEEK_CUR);
69 if (off < 0)
70 {
71 printf("error: Failed to seek a quarter ahead, errno=%d\n", errno);
72 rc++;
73 }
74
75 off = lseek(fh, -cb / 3, SEEK_CUR);
76 if (off < 0)
77 {
78 printf("error: Failed to seek a third backward, errno=%d\n", errno);
79 rc++;
80 }
81
82 off = lseek(fh, cb / 3, SEEK_SET);
83 if (off < 0)
84 {
85 printf("error: Failed to seek to a third into the file, errno=%d\n", errno);
86 rc++;
87 }
88
89 close(fh);
90
91 /* summary */
92 if (rc)
93 printf("testcase failed\n", errno);
94 else
95 printf("testcase succeeded\n", errno);
96 return rc;
97}
Note: See TracBrowser for help on using the repository browser.