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 /* Set some control flags or file descript for the stream
26 ** Written by Kiem-Phong Vo.
30 int sfset(Sfio_t
* f
, int flags
, int set
)
32 int sfset(f
,flags
,set
)
43 if(flags
== 0 && set
== 0)
44 SFMTXRETURN(f
, (f
->flags
&SF_FLAGS
));
46 if((oflags
= (f
->mode
&SF_RDWR
)) != (int)f
->mode
&& _sfmode(f
,oflags
,0) < 0)
50 SFMTXRETURN(f
, (f
->flags
&SF_FLAGS
));
54 /* preserve at least one rd/wr flag */
56 if(!(f
->bits
&SF_BOTH
) || (flags
&SF_RDWR
) == SF_RDWR
)
61 f
->flags
|= (flags
&SF_SETS
);
62 else f
->flags
&= ~(flags
&SF_SETS
);
64 /* must have at least one of read/write */
65 if(!(f
->flags
&SF_RDWR
))
66 f
->flags
|= (oflags
&SF_RDWR
);
69 f
->flags
&= ~SF_APPENDWR
;
71 /* turn to appropriate mode as necessary */
72 if((flags
&= SF_RDWR
) )
74 { if(flags
== SF_READ
)
78 if((flags
== SF_WRITE
&& !(f
->mode
&SF_WRITE
)) ||
79 (flags
== SF_READ
&& !(f
->mode
&(SF_READ
|SF_SYNCED
))) )
80 (void)_sfmode(f
,flags
,1);
83 /* if not shared or unseekable, public means nothing */
84 if(!(f
->flags
&SF_SHARE
) || f
->extent
< 0)
85 f
->flags
&= ~SF_PUBLIC
;
88 SFMTXRETURN(f
, (oflags
&SF_FLAGS
));