1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
24 /* Seek function that knows discipline
26 ** Written by Kiem-Phong Vo.
29 Sfoff_t
sfsk(Sfio_t
* f
, Sfoff_t addr
, int type
, Sfdisc_t
* disc
)
31 Sfoff_t
sfsk(f
,addr
,type
,disc
)
44 SFMTXENTER(f
, (Sfoff_t
)(-1));
47 if(!local
&& !(f
->bits
&SF_DCDOWN
))
48 { if((mode
= f
->mode
&SF_RDWR
) != (int)f
->mode
&& _sfmode(f
,mode
,0) < 0)
49 SFMTXRETURN(f
, (Sfoff_t
)(-1));
51 SFMTXRETURN(f
, (Sfoff_t
)(-1));
53 if(f
->mode
== SF_READ
&& (f
->bits
&SF_MMAP
) && f
->data
)
54 { SFMUNMAP(f
, f
->data
, f
->endb
-f
->data
);
55 f
->data
= NIL(uchar
*);
58 f
->next
= f
->endb
= f
->endr
= f
->endw
= f
->data
;
61 if((type
&= (SEEK_SET
|SEEK_CUR
|SEEK_END
)) > SEEK_END
)
62 SFMTXRETURN(f
, (Sfoff_t
)(-1));
66 if(f
->flags
&SF_STRING
)
70 else if(type
== SEEK_CUR
)
71 s
= (ssize_t
)(addr
+ f
->here
);
72 else s
= (ssize_t
)(addr
+ f
->extent
);
77 { SFDCSK(f
,addr
,type
,dc
,p
);
80 { p
= syslseekf(f
->file
,(sfoff_t
)addr
,type
);
89 switch(_sfexcept(f
,SF_SEEK
,s
,dc
))
93 if(f
->flags
&SF_STRING
)
94 SFMTXRETURN(f
, (Sfoff_t
)s
);
97 SFMTXRETURN(f
, (Sfoff_t
)(-1));
101 for(dc
= f
->disc
; dc
; dc
= dc
->disc
)