diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2002-05-24 23:44:39 +0000 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2002-05-24 23:44:39 +0000 |
commit | d29587b4789426217ace96c1dccb249e3682eaf8 (patch) | |
tree | 5eb3816b224b613db0274c8bccd57ef729261b68 /newlib/libc/string/strnlen.c | |
parent | 8b3e5e2d6e5076769d90662db759ce5009c1ba9c (diff) | |
download | cygnal-d29587b4789426217ace96c1dccb249e3682eaf8.tar.gz cygnal-d29587b4789426217ace96c1dccb249e3682eaf8.tar.bz2 cygnal-d29587b4789426217ace96c1dccb249e3682eaf8.zip |
2002-05-24 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/string.h: Add strnlen and strerror_r prototypes.
* libc/string/Makefile.am: Add strnlen.c and strerror_r.c support.
* libc/string/Makefile.in: Regenerated.
* libc/string/strerror_r.c: New file.
* libc/string/strnlen.c: New file.
* libc/sys/linux/Makefile.am: Add rename.c.
* libc/sys/linux/Makefile.in: Regenerated.
* libc/sys/linux/rename.c: New file to override default rename.
Diffstat (limited to 'newlib/libc/string/strnlen.c')
-rw-r--r-- | newlib/libc/string/strnlen.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/newlib/libc/string/strnlen.c b/newlib/libc/string/strnlen.c new file mode 100644 index 000000000..b9a3b5e77 --- /dev/null +++ b/newlib/libc/string/strnlen.c @@ -0,0 +1,49 @@ +/* +FUNCTION + <<strnlen>>---character string length + +INDEX + strnlen + +ANSI_SYNOPSIS + #include <string.h> + size_t strnlen(const char *<[str]>, size_t <[n]>); + +TRAD_SYNOPSIS + #include <string.h> + size_t strnlen(<[str]>, <[n]>) + char *<[src]>; + size_t <[n]>; + +DESCRIPTION + The <<strnlen>> function works out the length of the string + starting at <<*<[str]>>> by counting chararacters until it + reaches a NUL character or the maximum: <[n]> number of + characters have been inspected. + +RETURNS + <<strnlen>> returns the character count or <[n]>. + +PORTABILITY +<<strnlen>> is a Gnu extension. + +<<strnlen>> requires no supporting OS subroutines. + +*/ + +#undef __STRICT_ANSI__ +#include <_ansi.h> +#include <string.h> + +size_t +_DEFUN (strnlen, (str, n), + _CONST char *str _AND + size_t n) +{ + _CONST char *start = str; + + while (*str && n-- > 0) + str++; + + return str - start; +} |