1 /*
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * and/or other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 /*
19 FUNCTION
20 <<fseek>>, <<fseeko>>---set file position
21 
22 INDEX
23 	fseek
24 INDEX
25 	fseeko
26 INDEX
27 	_fseek_r
28 INDEX
29 	_fseeko_r
30 
31 SYNOPSIS
32 	#include <stdio.h>
33 	int fseek(FILE *<[fp]>, long <[offset]>, int <[whence]>);
34 	int fseeko(FILE *<[fp]>, off_t <[offset]>, int <[whence]>);
35 	int fseek( FILE *<[fp]>,
36 	             long <[offset]>, int <[whence]>);
37 	int fseeko( FILE *<[fp]>,
38 	             off_t <[offset]>, int <[whence]>);
39 
40 DESCRIPTION
41 Objects of type <<FILE>> can have a ``position'' that records how much
42 of the file your program has already read.  Many of the <<stdio>> functions
43 depend on this position, and many change it as a side effect.
44 
45 You can use <<fseek>>/<<fseeko>> to set the position for the file identified by
46 <[fp]>.  The value of <[offset]> determines the new position, in one
47 of three ways selected by the value of <[whence]> (defined as macros
48 in `<<stdio.h>>'):
49 
50 <<SEEK_SET>>---<[offset]> is the absolute file position (an offset
51 from the beginning of the file) desired.  <[offset]> must be positive.
52 
53 <<SEEK_CUR>>---<[offset]> is relative to the current file position.
54 <[offset]> can meaningfully be either positive or negative.
55 
56 <<SEEK_END>>---<[offset]> is relative to the current end of file.
57 <[offset]> can meaningfully be either positive (to increase the size
58 of the file) or negative.
59 
60 See <<ftell>>/<<ftello>> to determine the current file position.
61 
62 RETURNS
63 <<fseek>>/<<fseeko>> return <<0>> when successful.  On failure, the
64 result is <<EOF>>.  The reason for failure is indicated in <<errno>>:
65 either <<ESPIPE>> (the stream identified by <[fp]> doesn't support
66 repositioning) or <<EINVAL>> (invalid file position).
67 
68 PORTABILITY
69 ANSI C requires <<fseek>>.
70 
71 <<fseeko>> is defined by the Single Unix specification.
72 
73 Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
74 <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
75 */
76 
77 #define _DEFAULT_SOURCE
78 #include <_ansi.h>
79 #include <stdio.h>
80 #include <errno.h>
81 #include "local.h"
82 
83 int
fseek(register FILE * fp,long offset,int whence)84 fseek (
85        register FILE *fp,
86        long offset,
87        int whence)
88 {
89   return fseeko ( fp, offset, whence);
90 }
91