source: trunk/libs/newlib/src/newlib/libc/stdio/fwide.c @ 567

Last change on this file since 567 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.9 KB
Line 
1/*
2FUNCTION
3<<fwide>>---set and determine the orientation of a FILE stream
4
5INDEX
6        fwide
7INDEX
8        _fwide_r
9
10SYNOPSIS
11        #include <wchar.h>
12        int fwide(FILE *<[fp]>, int <[mode]>);
13
14        int _fwide_r(struct _reent *<[ptr]>, FILE *<[fp]>, int <[mode]>);
15
16DESCRIPTION
17When <[mode]> is zero, the <<fwide>> function determines the current
18orientation of <[fp]>. It returns a value > 0 if <[fp]> is
19wide-character oriented, i.e. if wide character I/O is permitted but
20char I/O is disallowed. It returns a value < 0 if <[fp]> is byte
21oriented, i.e. if char I/O is permitted but wide character I/O is
22disallowed. It returns zero if <[fp]> has no orientation yet; in
23this case the next I/O operation might change the orientation (to byte
24oriented if it is a char I/O operation, or to wide-character oriented
25if it is a wide character I/O operation).
26
27Once a stream has an orientation, it cannot be changed and persists
28until the stream is closed, unless the stream is re-opened with freopen,
29which removes the orientation of the stream.
30
31When <[mode]> is non-zero, the <<fwide>> function first attempts to set
32<[fp]>'s orientation (to wide-character oriented if <[mode]> > 0, or to
33byte oriented if <[mode]> < 0). It then returns a value denoting the
34current orientation, as above.
35
36RETURNS
37The <<fwide>> function returns <[fp]>'s orientation, after possibly
38changing it. A return value > 0 means wide-character oriented. A return
39value < 0 means byte oriented. A return value of zero means undecided.
40
41PORTABILITY
42C99, POSIX.1-2001.
43
44*/
45
46#include <_ansi.h>
47#include <wchar.h>
48#include "local.h"
49
50int
51_fwide_r (struct _reent *ptr,
52        FILE *fp,
53        int mode)
54{
55  int ret;
56
57  CHECK_INIT(ptr, fp);
58
59  _newlib_flockfile_start (fp);
60  if (mode != 0) {
61    ORIENT (fp, mode);
62  }
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;
69}
70
71int
72fwide (FILE *fp,
73        int mode)
74{
75  return _fwide_r (_REENT, fp, mode);
76}
Note: See TracBrowser for help on using the repository browser.