os/ossrv/genericopenlibs/cstdlib/LCHAR/MEMCHR.C
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LCHAR/MEMCHR.C	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,71 @@
     1.4 +/*
     1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +* FUNCTION
    1.19 +* <<memchr>>---find character in memory
    1.20 +* INDEX
    1.21 +* memchr
    1.22 +* ANSI_SYNOPSIS
    1.23 +* #include <string.h>
    1.24 +* void *memchr(const void *<[src]>, int <[c]>, size_t <[length]>);
    1.25 +* TRAD_SYNOPSIS
    1.26 +* #include <string.h>
    1.27 +* void *memchr(<[src]>, <[c]>, <[length]>)
    1.28 +* void *<[src]>;
    1.29 +* void *<[c]>;
    1.30 +* size_t <[length]>;
    1.31 +* This function searches memory starting at <<*<[src]>>> for the
    1.32 +* character <[c]>.  The search only ends with the first
    1.33 +* occurrence of <[c]>, or after <[length]> characters; in
    1.34 +* particular, <<NULL>> does not terminate the search.
    1.35 +* RETURNS
    1.36 +* If the character <[c]> is found within <[length]> characters
    1.37 +* of <<*<[src]>>>, a pointer to the character is returned. If
    1.38 +* <[c]> is not found, then <<NULL>> is returned.
    1.39 +* PORTABILITY
    1.40 +* <<memchr>>> is ANSI C.
    1.41 +* <<memchr>>  requires no supporting OS subroutines.
    1.42 +* QUICKREF
    1.43 +* memchr ansi pure
    1.44 +* 
    1.45 +*
    1.46 +*/
    1.47 +
    1.48 +
    1.49 +
    1.50 +#include <_ansi.h>
    1.51 +#include <string.h>
    1.52 +
    1.53 +/**
    1.54 +Search buffer for a character.
    1.55 +Searches the first num bytes of memory block pointed by src_void for character c.
    1.56 +@return   A pointer to the first occurrence of c in buffer.
    1.57 +If character is not found the function returns NULL.
    1.58 +@param src_void Pointer to buffer. 
    1.59 +@param c Key character to look for. 
    1.60 +@param length Number of characters to check from buffer.
    1.61 +*/
    1.62 +EXPORT_C void *
    1.63 +memchr (const void* src_void, int c, size_t length)
    1.64 +{
    1.65 +  const unsigned char *src = (const unsigned char *) src_void;
    1.66 +
    1.67 +  while (length--)
    1.68 +    {
    1.69 +      if (*src == c)
    1.70 +	return (char *) src;
    1.71 +      src++;
    1.72 +    }
    1.73 +  return NULL;
    1.74 +}