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 | * advertising materials, and 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 | <<fsetpos>>---restore position of a stream or file |
---|
21 | |
---|
22 | INDEX |
---|
23 | fsetpos |
---|
24 | INDEX |
---|
25 | _fsetpos_r |
---|
26 | |
---|
27 | SYNOPSIS |
---|
28 | #include <stdio.h> |
---|
29 | int fsetpos(FILE *<[fp]>, const fpos_t *<[pos]>); |
---|
30 | int _fsetpos_r(struct _reent *<[ptr]>, FILE *<[fp]>, |
---|
31 | const fpos_t *<[pos]>); |
---|
32 | |
---|
33 | DESCRIPTION |
---|
34 | Objects of type <<FILE>> can have a ``position'' that records how much |
---|
35 | of the file your program has already read. Many of the <<stdio>> functions |
---|
36 | depend on this position, and many change it as a side effect. |
---|
37 | |
---|
38 | You can use <<fsetpos>> to return the file identified by <[fp]> to a previous |
---|
39 | position <<*<[pos]>>> (after first recording it with <<fgetpos>>). |
---|
40 | |
---|
41 | See <<fseek>> for a similar facility. |
---|
42 | |
---|
43 | RETURNS |
---|
44 | <<fgetpos>> returns <<0>> when successful. If <<fgetpos>> fails, the |
---|
45 | result is <<1>>. The reason for failure is indicated in <<errno>>: |
---|
46 | either <<ESPIPE>> (the stream identified by <[fp]> doesn't support |
---|
47 | repositioning) or <<EINVAL>> (invalid file position). |
---|
48 | |
---|
49 | PORTABILITY |
---|
50 | ANSI C requires <<fsetpos>>, but does not specify the nature of |
---|
51 | <<*<[pos]>>> beyond identifying it as written by <<fgetpos>>. |
---|
52 | |
---|
53 | Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, |
---|
54 | <<lseek>>, <<read>>, <<sbrk>>, <<write>>. |
---|
55 | */ |
---|
56 | |
---|
57 | #include <_ansi.h> |
---|
58 | #include <reent.h> |
---|
59 | #include <stdio.h> |
---|
60 | |
---|
61 | int |
---|
62 | _fsetpos_r (struct _reent * ptr, |
---|
63 | FILE * iop, |
---|
64 | const _fpos_t * pos) |
---|
65 | { |
---|
66 | int x = _fseek_r (ptr, iop, *pos, SEEK_SET); |
---|
67 | |
---|
68 | if (x != 0) |
---|
69 | return 1; |
---|
70 | return 0; |
---|
71 | } |
---|
72 | |
---|
73 | #ifndef _REENT_ONLY |
---|
74 | |
---|
75 | int |
---|
76 | fsetpos (FILE * iop, |
---|
77 | const _fpos_t * pos) |
---|
78 | { |
---|
79 | return _fsetpos_r (_REENT, iop, pos); |
---|
80 | } |
---|
81 | |
---|
82 | #endif /* !_REENT_ONLY */ |
---|