|
1 /* WSETUP.C |
|
2 * |
|
3 * Portions Copyright (c) 1990-1999 Nokia Corporation and/or its subsidiary(-ies). |
|
4 * All rights reserved. |
|
5 */ |
|
6 |
|
7 /* No user fns here. Pesch 15apr92. */ |
|
8 |
|
9 /* |
|
10 * Copyright (c) 1990 The Regents of the University of California. |
|
11 * All rights reserved. |
|
12 * |
|
13 * Redistribution and use in source and binary forms are permitted |
|
14 * provided that the above copyright notice and this paragraph are |
|
15 * duplicated in all such forms and that any documentation, |
|
16 * advertising materials, and other materials related to such |
|
17 * distribution and use acknowledge that the software was developed |
|
18 * by the University of California, Berkeley. The name of the |
|
19 * University may not be used to endorse or promote products derived |
|
20 * from this software without specific prior written permission. |
|
21 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
|
22 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
|
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
|
24 */ |
|
25 |
|
26 #include <stdio_r.h> |
|
27 #include <stdlib_r.h> |
|
28 #include "LOCAL.H" |
|
29 |
|
30 /* |
|
31 * Various output routines call wsetup to be sure it is safe to write, |
|
32 * because either _flags does not include __SWR, or _buf is NULL. |
|
33 * _wsetup returns 0 if OK to write, nonzero otherwise. |
|
34 */ |
|
35 |
|
36 int |
|
37 __swsetup (register FILE * fp) |
|
38 { |
|
39 /* Make sure stdio is set up. */ |
|
40 |
|
41 CHECK_INIT (fp); |
|
42 |
|
43 /* |
|
44 * If we are not writing, we had better be reading and writing. |
|
45 */ |
|
46 |
|
47 if ((fp->_flags & __SWR) == 0) |
|
48 { |
|
49 if ((fp->_flags & __SRW) == 0) |
|
50 return EOF; |
|
51 if (fp->_flags & __SRD) |
|
52 { |
|
53 /* clobber any ungetc data */ |
|
54 if (HASUB (fp)) |
|
55 FREEUB (fp); |
|
56 fp->_flags &= ~(__SRD | __SEOF); |
|
57 fp->_r = 0; |
|
58 fp->_p = fp->_bf._base; |
|
59 } |
|
60 fp->_flags |= __SWR; |
|
61 } |
|
62 |
|
63 /* |
|
64 * Make a buffer if necessary, then set _w. |
|
65 */ |
|
66 /* NOT NEEDED FOR CYGNUS SPRINTF ONLY jpg */ |
|
67 if (fp->_bf._base == NULL) |
|
68 __smakebuf (fp); |
|
69 |
|
70 if (fp->_flags & __SLBF) |
|
71 { |
|
72 /* |
|
73 * It is line buffered, so make _lbfsize be -_bufsize |
|
74 * for the putc() macro. We will change _lbfsize back |
|
75 * to 0 whenever we turn off __SWR. |
|
76 */ |
|
77 fp->_w = 0; |
|
78 fp->_lbfsize = -fp->_bf._size; |
|
79 } |
|
80 else |
|
81 fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size; |
|
82 |
|
83 return 0; |
|
84 } |