X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstring%2Fmemchr.c;h=1c9563c7efa3641f166009935fe281cb0ce00c06;hp=6a6440a80e3a6010937ee22402d3d289802879fe;hb=1d9d92ba957a0b8307c9a65c35867fde68e6533b;hpb=0a5395faab237ba9008352b0f4bee9659bbd3d5f diff --git a/functions/string/memchr.c b/functions/string/memchr.c index 6a6440a..1c9563c 100644 --- a/functions/string/memchr.c +++ b/functions/string/memchr.c @@ -1,33 +1,23 @@ -// ---------------------------------------------------------------------------- -// $Id$ -// ---------------------------------------------------------------------------- -// Public Domain C Library - http://pdclib.sourceforge.net -// This code is Public Domain. Use, modify, and redistribute at will. -// ---------------------------------------------------------------------------- +/* ---------------------------------------------------------------------------- + * $Id$ + * ---------------------------------------------------------------------------- + * Public Domain C Library - http://pdclib.sourceforge.net + * This code is Public Domain. Use, modify, and redistribute at will. + * --------------------------------------------------------------------------*/ -// ---------------------------------------------------------------------------- -// C++ +#include <__size_t.h> +#include <__NULL.h> -const void * memchr( const void * s, int c, size_t n ) { /* TODO */ }; -void * memchr( void * s, int c, size_t n ) { /* TODO */ }; - -// ---------------------------------------------------------------------------- -// Standard C - -void * memchr( const void * s, int c, size_t n ) { /* TODO */ }; - -/* PDPC code - unreviewed +void * memchr( const void * src, int c, size_t n ) { - const unsigned char *p; - size_t x = 0; - - p = (const unsigned char *)s; - while (x < n) + const unsigned char * p = (const unsigned char *) src; + while ( n-- ) { - if (*p == (unsigned char)c) return ((void *)p); - p++; - x++; + if ( *p == (unsigned char) c ) + { + return (void *) p; + } + ++p; } - return (NULL); + return NULL; } -*/