~ubuntu-branches/ubuntu/quantal/gnutls26/quantal

« back to all changes in this revision

Viewing changes to gl/fseeko.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-05-20 13:07:18 UTC
  • mfrom: (12.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110520130718-db41dybbanzfvlji
Tags: 2.10.5-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Fix build failure with --no-add-needed.
  - Build for multiarch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* An fseeko() function that, together with fflush(), is POSIX compliant.
2
 
   Copyright (C) 2007-2009 Free Software Foundation, Inc.
 
2
   Copyright (C) 2007-2010 Free Software Foundation, Inc.
3
3
 
4
4
   This program is free software; you can redistribute it and/or modify
5
5
   it under the terms of the GNU General Public License as published by
25
25
 
26
26
#include "stdio-impl.h"
27
27
 
 
28
int
 
29
fseeko (FILE *fp, off_t offset, int whence)
28
30
#undef fseeko
29
31
#if !HAVE_FSEEKO
30
32
# undef fseek
31
33
# define fseeko fseek
32
34
#endif
33
 
 
34
 
int
35
 
rpl_fseeko (FILE *fp, off_t offset, int whence)
36
35
{
37
36
#if LSEEK_PIPE_BROKEN
38
37
  /* mingw gives bogus answers rather than failure on non-seekable files.  */
50
49
  if ((fp->_flags & __SL64) == 0)
51
50
    {
52
51
      /* Cygwin 1.5.0 through 1.5.24 failed to open stdin in 64-bit
53
 
         mode; but has an fseeko that requires 64-bit mode.  */
 
52
         mode; but has an fseeko that requires 64-bit mode.  */
54
53
      FILE *tmp = fopen ("/dev/null", "r");
55
54
      if (!tmp)
56
 
        return -1;
 
55
        return -1;
57
56
      fp->_flags |= __SL64;
58
57
      fp->_seek64 = tmp->_seek64;
59
58
      fclose (tmp);
62
61
  if (fp_->_p == fp_->_bf._base
63
62
      && fp_->_r == 0
64
63
      && fp_->_w == ((fp_->_flags & (__SLBF | __SNBF | __SRD)) == 0 /* fully buffered and not currently reading? */
65
 
                     ? fp_->_bf._size
66
 
                     : 0)
 
64
                     ? fp_->_bf._size
 
65
                     : 0)
67
66
      && fp_ub._base == NULL)
68
67
#elif defined __EMX__               /* emx+gcc */
69
68
  if (fp->_ptr == fp->_buffer
77
76
  if (((fp->__modeflags & __FLAG_WRITING) == 0
78
77
       || fp->__bufpos == fp->__bufstart)
79
78
      && ((fp->__modeflags & (__FLAG_READONLY | __FLAG_READING)) == 0
80
 
          || fp->__bufpos == fp->__bufread))
 
79
          || fp->__bufpos == fp->__bufread))
81
80
#elif defined __QNX__               /* QNX */
82
 
  if ((fp->_Mode & _MWRITE ? fp->_Next == fp->_Buf : fp->_Next == fp->_Rend)
 
81
  if ((fp->_Mode & 0x2000 /* _MWRITE */ ? fp->_Next == fp->_Buf : fp->_Next == fp->_Rend)
83
82
      && fp->_Rback == fp->_Back + sizeof (fp->_Back)
84
83
      && fp->_Rsave == NULL)
85
84
#elif defined __MINT__              /* Atari FreeMiNT */
92
91
#endif
93
92
    {
94
93
      /* We get here when an fflush() call immediately preceded this one.  We
95
 
         know there are no buffers.
96
 
         POSIX requires us to modify the file descriptor's position.
97
 
         But we cannot position beyond end of file here.  */
 
94
         know there are no buffers.
 
95
         POSIX requires us to modify the file descriptor's position.
 
96
         But we cannot position beyond end of file here.  */
98
97
      off_t pos =
99
 
        lseek (fileno (fp),
100
 
               whence == SEEK_END && offset > 0 ? 0 : offset,
101
 
               whence);
 
98
        lseek (fileno (fp),
 
99
               whence == SEEK_END && offset > 0 ? 0 : offset,
 
100
               whence);
102
101
      if (pos == -1)
103
 
        {
 
102
        {
104
103
#if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */
105
 
          fp_->_flags &= ~__SOFF;
 
104
          fp_->_flags &= ~__SOFF;
106
105
#endif
107
 
          return -1;
108
 
        }
 
106
          return -1;
 
107
        }
109
108
 
110
109
#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
111
110
      fp->_flags &= ~_IO_EOF_SEEN;
112
111
#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */
 
112
# if defined __CYGWIN__
 
113
      /* fp_->_offset is typed as an integer.  */
113
114
      fp_->_offset = pos;
 
115
# else
 
116
      /* fp_->_offset is an fpos_t.  */
 
117
      {
 
118
        /* Use a union, since on NetBSD, the compilation flags
 
119
           determine whether fpos_t is typedef'd to off_t or a struct
 
120
           containing a single off_t member.  */
 
121
        union
 
122
          {
 
123
            fpos_t f;
 
124
            off_t o;
 
125
          } u;
 
126
        u.o = pos;
 
127
        fp_->_offset = u.f;
 
128
      }
 
129
# endif
114
130
      fp_->_flags |= __SOFF;
115
131
      fp_->_flags &= ~__SEOF;
116
132
#elif defined __EMX__               /* emx+gcc */
122
138
      fp->__eof = 0;
123
139
#endif
124
140
      /* If we were not requested to position beyond end of file, we're
125
 
         done.  */
 
141
         done.  */
126
142
      if (!(whence == SEEK_END && offset > 0))
127
 
        return 0;
 
143
        return 0;
128
144
    }
129
145
  return fseeko (fp, offset, whence);
130
146
}