Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / stdio / fwide.c
blob1d24304681161460f5cca112548cbf41bb126c01
1 /*
2 FUNCTION
3 <<fwide>>---set and determine the orientation of a FILE stream
5 INDEX
6 fwide
7 INDEX
8 _fwide_r
10 SYNOPSIS
11 #include <wchar.h>
12 int fwide(FILE *<[fp]>, int <[mode]>);
14 int _fwide_r(struct _reent *<[ptr]>, FILE *<[fp]>, int <[mode]>);
16 DESCRIPTION
17 When <[mode]> is zero, the <<fwide>> function determines the current
18 orientation of <[fp]>. It returns a value > 0 if <[fp]> is
19 wide-character oriented, i.e. if wide character I/O is permitted but
20 char I/O is disallowed. It returns a value < 0 if <[fp]> is byte
21 oriented, i.e. if char I/O is permitted but wide character I/O is
22 disallowed. It returns zero if <[fp]> has no orientation yet; in
23 this case the next I/O operation might change the orientation (to byte
24 oriented if it is a char I/O operation, or to wide-character oriented
25 if it is a wide character I/O operation).
27 Once a stream has an orientation, it cannot be changed and persists
28 until the stream is closed, unless the stream is re-opened with freopen,
29 which removes the orientation of the stream.
31 When <[mode]> is non-zero, the <<fwide>> function first attempts to set
32 <[fp]>'s orientation (to wide-character oriented if <[mode]> > 0, or to
33 byte oriented if <[mode]> < 0). It then returns a value denoting the
34 current orientation, as above.
36 RETURNS
37 The <<fwide>> function returns <[fp]>'s orientation, after possibly
38 changing it. A return value > 0 means wide-character oriented. A return
39 value < 0 means byte oriented. A return value of zero means undecided.
41 PORTABILITY
42 C99, POSIX.1-2001.
46 #include <_ansi.h>
47 #include <wchar.h>
48 #include "local.h"
50 int
51 _fwide_r (struct _reent *ptr,
52 FILE *fp,
53 int mode)
55 int ret;
57 CHECK_INIT(ptr, fp);
59 _newlib_flockfile_start (fp);
60 if (mode != 0) {
61 (void) ORIENT (fp, mode);
63 if (!(fp->_flags & __SORD))
64 ret = 0;
65 else
66 ret = (fp->_flags2 & __SWID) ? 1 : -1;
67 _newlib_flockfile_end (fp);
68 return ret;
71 int
72 fwide (FILE *fp,
73 int mode)
75 return _fwide_r (_REENT, fp, mode);