]> git.ipfire.org Git - thirdparty/glibc.git/blame - libio/ioseekoff.c
Replace FSF snail mail address with URLs.
[thirdparty/glibc.git] / libio / ioseekoff.c
CommitLineData
bbdef797
UD
1/* Copyright (C) 1993, 1997, 1998, 1999, 2001, 2002, 2003
2 Free Software Foundation, Inc.
41bdb6e2 3 This file is part of the GNU C Library.
40a55d20 4
41bdb6e2
AJ
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
40a55d20 9
41bdb6e2
AJ
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
40a55d20 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 13 Lesser General Public License for more details.
40a55d20 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>.
40a55d20 18
41bdb6e2
AJ
19 As a special exception, if you link the code in this file with
20 files compiled with a GNU compiler to produce an executable,
21 that does not cause the resulting executable to be covered by
22 the GNU Lesser General Public License. This exception does not
23 however invalidate any other reasons why the executable file
24 might be covered by the GNU Lesser General Public License.
25 This exception applies to code released by its copyright holders
26 in files containing the exception. */
96aa2d94 27
40a982a9 28#include <stdlib.h>
96aa2d94 29#include <libioP.h>
d64b6ad0
UD
30#include <errno.h>
31#ifndef errno
32extern int errno;
33#endif
34#ifndef __set_errno
35# define __set_errno(Val) errno = (Val)
36#endif
96aa2d94 37
d64b6ad0 38_IO_off64_t
52a16e58 39_IO_seekoff_unlocked (fp, offset, dir, mode)
40a55d20 40 _IO_FILE *fp;
dfd2257a 41 _IO_off64_t offset;
40a55d20
UD
42 int dir;
43 int mode;
96aa2d94 44{
d64b6ad0
UD
45 if (dir != _IO_seek_cur && dir != _IO_seek_set && dir != _IO_seek_end)
46 {
47 __set_errno (EINVAL);
48 return EOF;
4a582094
UD
49 }
50
96aa2d94
RM
51 /* If we have a backup buffer, get rid of it, since the __seekoff
52 callback may not know to do the right thing about it.
53 This may be over-kill, but it'll do for now. TODO */
77fe0b9c 54 if (mode != 0 && ((_IO_fwide (fp, 0) < 0 && _IO_have_backup (fp))
0b9225cd 55 || (_IO_fwide (fp, 0) > 0 && _IO_have_wbackup (fp))))
96aa2d94
RM
56 {
57 if (dir == _IO_seek_cur && _IO_in_backup (fp))
40a982a9 58 {
bbdef797 59 if (_IO_vtable_offset (fp) != 0 || fp->_mode <= 0)
40a982a9
UD
60 offset -= fp->_IO_read_end - fp->_IO_read_ptr;
61 else
62 abort ();
63 }
77fe0b9c
UD
64 if (_IO_fwide (fp, 0) < 0)
65 INTUSE(_IO_free_backup_area) (fp);
66 else
67 INTUSE(_IO_free_wbackup_area) (fp);
96aa2d94 68 }
00bc5db0 69
52a16e58
UD
70 return _IO_SEEKOFF (fp, offset, dir, mode);
71}
72
73
74_IO_off64_t
75_IO_seekoff (fp, offset, dir, mode)
76 _IO_FILE *fp;
77 _IO_off64_t offset;
78 int dir;
79 int mode;
80{
81 _IO_off64_t retval;
82
0261d33f 83 _IO_acquire_lock (fp);
52a16e58 84 retval = _IO_seekoff_unlocked (fp, offset, dir, mode);
0261d33f 85 _IO_release_lock (fp);
61eb22d3 86 return retval;
96aa2d94 87}