OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libc/] [stdio64/] [ftello64.c] - Blame information for rev 297

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/*
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
<<ftello64>>---return position in a stream or file
21
 
22
INDEX
23
        ftello64
24
INDEX
25
        _ftello64_r
26
 
27
ANSI_SYNOPSIS
28
        #include <stdio.h>
29
        _off64_t ftello64(FILE *<[fp]>);
30
        _off64_t _ftello64_r(struct _reent *<[ptr]>, FILE *<[fp]>);
31
 
32
TRAD_SYNOPSIS
33
        #include <stdio.h>
34
        _off64_t ftello64(<[fp]>)
35
        FILE *<[fp]>;
36
 
37
        _off64_t _ftello64_r(<[ptr]>, <[fp]>)
38
        struct _reent *<[ptr]>;
39
        FILE *<[fp]>;
40
 
41
DESCRIPTION
42
Objects of type <<FILE>> can have a ``position'' that records how much
43
of the file your program has already read.  Many of the <<stdio>> functions
44
depend on this position, and many change it as a side effect.
45
 
46
The result of <<ftello64>> is the current position for a large file
47
identified by <[fp]>.  If you record this result, you can later
48
use it with <<fseeko64>> to return the file to this
49
position.  The difference between <<ftello>> and <<ftello64>> is that
50
<<ftello>> returns <<off_t>> and <<ftello64>> is designed to work
51
for large files (>2GB) and returns <<_off64_t>>.
52
 
53
In the current implementation, <<ftello64>> simply uses a character
54
count to represent the file position; this is the same number that
55
would be recorded by <<fgetpos64>>.
56
 
57
The function exists only if the __LARGE64_FILES flag is defined.
58
An error occurs if the <[fp]> was not opened via <<fopen64>>.
59
 
60
RETURNS
61
<<ftello64>> returns the file position, if possible.  If it cannot do
62
this, it returns <<-1>>.  Failure occurs on streams that do not support
63
positioning or not opened via <<fopen64>>; the global <<errno>> indicates
64
this condition with the value <<ESPIPE>>.
65
 
66
PORTABILITY
67
<<ftello64>> is a glibc extension.
68
 
69
No supporting OS subroutines are required.
70
*/
71
 
72
#if defined(LIBC_SCCS) && !defined(lint)
73
static char sccsid[] = "%W% (Berkeley) %G%";
74
#endif /* LIBC_SCCS and not lint */
75
 
76
/*
77
 * ftello64: return current offset.
78
 */
79
 
80
#include <stdio.h>
81
#include <errno.h>
82
 
83
#include "local.h"
84
 
85
#ifdef __LARGE64_FILES
86
 
87
_off64_t
88
_DEFUN (_ftello64_r, (ptr, fp),
89
        struct _reent *ptr _AND
90
        register FILE * fp)
91
{
92
  _fpos64_t pos;
93
 
94
  /* Only do 64-bit tell on large file.  */
95
  if (!(fp->_flags & __SL64))
96
    return (_off64_t) _ftello_r (ptr, fp);
97
 
98
  /* Ensure stdio is set up.  */
99
 
100
  CHECK_INIT (ptr, fp);
101
 
102
  _flockfile(fp);
103
 
104
  if (fp->_seek64 == NULL)
105
    {
106
      ptr->_errno = ESPIPE;
107
      _funlockfile(fp);
108
      return -1L;
109
    }
110
 
111
  /* Find offset of underlying I/O object, then adjust for buffered
112
     bytes.  Flush a write stream, since the offset may be altered if
113
     the stream is appending.  Do not flush a read stream, since we
114
     must not lose the ungetc buffer.  */
115
  if (fp->_flags & __SWR)
116
    _fflush_r (ptr, fp);
117
  if (fp->_flags & __SOFF)
118
    pos = fp->_offset;
119
  else
120
    {
121
      pos = fp->_seek64 (ptr, fp->_cookie, (_fpos64_t) 0, SEEK_CUR);
122
      if (pos == -1L)
123
        {
124
          _funlockfile(fp);
125
          return pos;
126
        }
127
    }
128
  if (fp->_flags & __SRD)
129
    {
130
      /*
131
       * Reading.  Any unread characters (including
132
       * those from ungetc) cause the position to be
133
       * smaller than that in the underlying object.
134
       */
135
      pos -= fp->_r;
136
      if (HASUB (fp))
137
        pos -= fp->_ur;
138
    }
139
  else if (fp->_flags & __SWR && fp->_p != NULL)
140
    {
141
      /*
142
       * Writing.  Any buffered characters cause the
143
       * position to be greater than that in the
144
       * underlying object.
145
       */
146
      pos += fp->_p - fp->_bf._base;
147
    }
148
 
149
  _funlockfile(fp);
150
  return pos;
151
}
152
 
153
#ifndef _REENT_ONLY
154
 
155
_off64_t
156
_DEFUN (ftello64, (fp),
157
        register FILE * fp)
158
{
159
  return _ftello64_r (_REENT, fp);
160
}
161
 
162
#endif /* !_REENT_ONLY */
163
 
164
#endif /* __LARGE64_FILES */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.