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 | <<fgetpos>>---record position in a stream or file |
---|
21 | |
---|
22 | INDEX |
---|
23 | fgetpos |
---|
24 | INDEX |
---|
25 | _fgetpos_r |
---|
26 | |
---|
27 | SYNOPSIS |
---|
28 | #include <stdio.h> |
---|
29 | int fgetpos(FILE *restrict <[fp]>, fpos_t *restrict <[pos]>); |
---|
30 | int _fgetpos_r(struct _reent *<[ptr]>, FILE *restrict <[fp]>, fpos_t *restrict <[pos]>); |
---|
31 | |
---|
32 | DESCRIPTION |
---|
33 | Objects of type <<FILE>> can have a ``position'' that records how much |
---|
34 | of the file your program has already read. Many of the <<stdio>> functions |
---|
35 | depend on this position, and many change it as a side effect. |
---|
36 | |
---|
37 | You can use <<fgetpos>> to report on the current position for a file |
---|
38 | identified by <[fp]>; <<fgetpos>> will write a value |
---|
39 | representing that position at <<*<[pos]>>>. Later, you can |
---|
40 | use this value with <<fsetpos>> to return the file to this |
---|
41 | position. |
---|
42 | |
---|
43 | In the current implementation, <<fgetpos>> simply uses a character |
---|
44 | count to represent the file position; this is the same number that |
---|
45 | would be returned by <<ftell>>. |
---|
46 | |
---|
47 | RETURNS |
---|
48 | <<fgetpos>> returns <<0>> when successful. If <<fgetpos>> fails, the |
---|
49 | result is <<1>>. Failure occurs on streams that do not support |
---|
50 | positioning; the global <<errno>> indicates this condition with the |
---|
51 | value <<ESPIPE>>. |
---|
52 | |
---|
53 | PORTABILITY |
---|
54 | <<fgetpos>> is required by the ANSI C standard, but the meaning of the |
---|
55 | value it records is not specified beyond requiring that it be |
---|
56 | acceptable as an argument to <<fsetpos>>. In particular, other |
---|
57 | conforming C implementations may return a different result from |
---|
58 | <<ftell>> than what <<fgetpos>> writes at <<*<[pos]>>>. |
---|
59 | |
---|
60 | No supporting OS subroutines are required. |
---|
61 | */ |
---|
62 | |
---|
63 | #include <_ansi.h> |
---|
64 | #include <reent.h> |
---|
65 | #include <stdio.h> |
---|
66 | |
---|
67 | int |
---|
68 | _fgetpos_r (struct _reent * ptr, |
---|
69 | FILE *__restrict fp, |
---|
70 | _fpos_t *__restrict pos) |
---|
71 | { |
---|
72 | *pos = _ftell_r (ptr, fp); |
---|
73 | |
---|
74 | if (*pos != -1) |
---|
75 | { |
---|
76 | return 0; |
---|
77 | } |
---|
78 | return 1; |
---|
79 | } |
---|
80 | |
---|
81 | #ifndef _REENT_ONLY |
---|
82 | |
---|
83 | int |
---|
84 | fgetpos (FILE *__restrict fp, |
---|
85 | _fpos_t *__restrict pos) |
---|
86 | { |
---|
87 | return _fgetpos_r (_REENT, fp, pos); |
---|
88 | } |
---|
89 | |
---|
90 | #endif /* !_REENT_ONLY */ |
---|