fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / string / wcswidth.c
blobbd3d9bbadae0ccb61b3d31e6abe3ef961586d4b8
1 /*
2 FUNCTION
3 <<wcswidth>>---number of column positions of a wide-character string
5 INDEX
6 wcswidth
8 ANSI_SYNOPSIS
9 #include <wchar.h>
10 int wcswidth(const wchar_t *<[pwcs]>, size_t <[n]>);
12 TRAD_SYNOPSIS
13 #include <wchar.h>
14 int wcswidth(<[pwcs]>, <[n]>)
15 wchar_t *<[wc]>;
16 size_t <[n]>;
18 DESCRIPTION
19 The <<wcswidth>> function shall determine the number of column
20 positions required for n wide-character codes (or fewer than n
21 wide-character codes if a null wide-character code is encountered
22 before n wide-character codes are exhausted) in the string pointed
23 to by pwcs.
25 RETURNS
26 The <<wcswidth>> function either shall return 0 (if pwcs points to a
27 null wide-character code), or return the number of column positions
28 to be occupied by the wide-character string pointed to by pwcs, or
29 return -1 (if any of the first n wide-character codes in the
30 wide-character string pointed to by pwcs is not a printable
31 wide-character code).
33 PORTABILITY
34 <<wcswidth>> has been introduced in the Single UNIX Specification Volume 2
35 <<wcswidth>> has been marked as extension in Single UNIX Specification Volume 3
38 #include <_ansi.h>
39 #include <wchar.h>
41 int
42 _DEFUN (wcswidth, (pwcs, n),
43 _CONST wchar_t *pwcs _AND
44 size_t n)
47 int w, len = 0;
48 if (!pwcs || n == 0)
49 return 0;
50 do {
51 if ((w = wcwidth (*pwcs)) < 0)
52 return -1;
53 len += w;
54 } while (*pwcs++ && --n > 0);
55 return len;