summaryrefslogtreecommitdiffstats
path: root/newlib/libc/string/wcsnlen.c
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2003-10-23 18:07:13 +0000
committerJeff Johnston <jjohnstn@redhat.com>2003-10-23 18:07:13 +0000
commit4340b63bc1e20c0311f7a723b8c3ee3b1760a60a (patch)
tree850fb7887a946302c4af37593d9732788dcc5038 /newlib/libc/string/wcsnlen.c
parent34dd9dbc047a6aa8547d1c6c2f04154d272ee76f (diff)
downloadcygnal-4340b63bc1e20c0311f7a723b8c3ee3b1760a60a.tar.gz
cygnal-4340b63bc1e20c0311f7a723b8c3ee3b1760a60a.tar.bz2
cygnal-4340b63bc1e20c0311f7a723b8c3ee3b1760a60a.zip
2003-10-23 Artem B. Bityuckiy <mail_lists@mail.ru>
* libc/string/wcsnlen.c: New file. * libc/include/wchar.h: Add wcsnlen prototype. * libc/string/Makefile.am: Add wcsnlen support. * libc/string/Makefile.in: Regenerated. * libc/string/wcstrings.tex: Add wcsnlen documentation.
Diffstat (limited to 'newlib/libc/string/wcsnlen.c')
-rw-r--r--newlib/libc/string/wcsnlen.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/newlib/libc/string/wcsnlen.c b/newlib/libc/string/wcsnlen.c
new file mode 100644
index 000000000..e84342d3d
--- /dev/null
+++ b/newlib/libc/string/wcsnlen.c
@@ -0,0 +1,74 @@
+/*
+FUNCTION
+ <<wcsnlen>>---get fixed-size wide character string length
+
+INDEX
+ wcsnlen
+
+ANSI_SYNOPSIS
+ #include <wchar.h>
+ size_t wcsnlen(const wchar_t *<[s]>, size_t <[maxlen]>);
+
+TRAD_SYNOPSIS
+ #include <wchar.h>
+ size_t wcsnlen(<[s]>, <[maxlen]>)
+ wchar_t *<[s]>;
+ size_t <[maxlen]>;
+
+DESCRIPTION
+ The <<wcsnlen>> function computes the number of wide character codes
+ in the wide character string pointed to by <[s]> not including the
+ terminating L'\0' wide character but at most <[maxlen]> wide
+ characters.
+
+RETURNS
+ <<wcsnlen>> returns the length of <[s]> if it is less then <[maxlen]>,
+ or <[maxlen]> if there is no L'\0' wide character in first <[maxlen]>
+ characters.
+
+PORTABILITY
+<<wcsnlen>> is GNU extension..
+<<wcsnlen>> requires no supporting OS subroutines.
+*/
+
+/*
+ * Copyright (c) 2003, Artem B. Bityuckiy (dedekind@mail.ru).
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the above copyright notice,
+ * this condition statement, and the following disclaimer are retained
+ * in any redistributions of the source code.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <_ansi.h>
+#include <sys/types.h>
+#include <wchar.h>
+
+size_t
+_DEFUN(wcsnlen, (s, maxlen),
+ _CONST wchar_t *s _AND
+ size_t maxlen)
+{
+ _CONST wchar_t *p;
+
+ p = s;
+ while (*p && maxlen-- > 0)
+ p++;
+
+ return (size_t)(p - s);
+}
+
+
+