os/ossrv/genericopenlibs/cstdlib/LCHAR/MEMCHR.C
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 * FUNCTION
    16 * <<memchr>>---find character in memory
    17 * INDEX
    18 * memchr
    19 * ANSI_SYNOPSIS
    20 * #include <string.h>
    21 * void *memchr(const void *<[src]>, int <[c]>, size_t <[length]>);
    22 * TRAD_SYNOPSIS
    23 * #include <string.h>
    24 * void *memchr(<[src]>, <[c]>, <[length]>)
    25 * void *<[src]>;
    26 * void *<[c]>;
    27 * size_t <[length]>;
    28 * This function searches memory starting at <<*<[src]>>> for the
    29 * character <[c]>.  The search only ends with the first
    30 * occurrence of <[c]>, or after <[length]> characters; in
    31 * particular, <<NULL>> does not terminate the search.
    32 * RETURNS
    33 * If the character <[c]> is found within <[length]> characters
    34 * of <<*<[src]>>>, a pointer to the character is returned. If
    35 * <[c]> is not found, then <<NULL>> is returned.
    36 * PORTABILITY
    37 * <<memchr>>> is ANSI C.
    38 * <<memchr>>  requires no supporting OS subroutines.
    39 * QUICKREF
    40 * memchr ansi pure
    41 * 
    42 *
    43 */
    44 
    45 
    46 
    47 #include <_ansi.h>
    48 #include <string.h>
    49 
    50 /**
    51 Search buffer for a character.
    52 Searches the first num bytes of memory block pointed by src_void for character c.
    53 @return   A pointer to the first occurrence of c in buffer.
    54 If character is not found the function returns NULL.
    55 @param src_void Pointer to buffer. 
    56 @param c Key character to look for. 
    57 @param length Number of characters to check from buffer.
    58 */
    59 EXPORT_C void *
    60 memchr (const void* src_void, int c, size_t length)
    61 {
    62   const unsigned char *src = (const unsigned char *) src_void;
    63 
    64   while (length--)
    65     {
    66       if (*src == c)
    67 	return (char *) src;
    68       src++;
    69     }
    70   return NULL;
    71 }