OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [string/] [strnlen.c] - Rev 1773

Go to most recent revision | Compare with Previous | Blame | View Log

/* 
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;
}
 

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.