fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / string / wcsnlen.c
blobe84342d3ddb6a5e09dae8720287e967863b43cde
1 /*
2 FUNCTION
3 <<wcsnlen>>---get fixed-size wide character string length
5 INDEX
6 wcsnlen
8 ANSI_SYNOPSIS
9 #include <wchar.h>
10 size_t wcsnlen(const wchar_t *<[s]>, size_t <[maxlen]>);
12 TRAD_SYNOPSIS
13 #include <wchar.h>
14 size_t wcsnlen(<[s]>, <[maxlen]>)
15 wchar_t *<[s]>;
16 size_t <[maxlen]>;
18 DESCRIPTION
19 The <<wcsnlen>> function computes the number of wide character codes
20 in the wide character string pointed to by <[s]> not including the
21 terminating L'\0' wide character but at most <[maxlen]> wide
22 characters.
24 RETURNS
25 <<wcsnlen>> returns the length of <[s]> if it is less then <[maxlen]>,
26 or <[maxlen]> if there is no L'\0' wide character in first <[maxlen]>
27 characters.
29 PORTABILITY
30 <<wcsnlen>> is GNU extension..
31 <<wcsnlen>> requires no supporting OS subroutines.
35 * Copyright (c) 2003, Artem B. Bityuckiy (dedekind@mail.ru).
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the above copyright notice,
39 * this condition statement, and the following disclaimer are retained
40 * in any redistributions of the source code.
42 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 * SUCH DAMAGE.
55 #include <_ansi.h>
56 #include <sys/types.h>
57 #include <wchar.h>
59 size_t
60 _DEFUN(wcsnlen, (s, maxlen),
61 _CONST wchar_t *s _AND
62 size_t maxlen)
64 _CONST wchar_t *p;
66 p = s;
67 while (*p && maxlen-- > 0)
68 p++;
70 return (size_t)(p - s);