X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstring%2Fmemchr.c;h=1c9563c7efa3641f166009935fe281cb0ce00c06;hb=c8f799d852e3698468a78954d82588e841cc0b70;hp=6a6440a80e3a6010937ee22402d3d289802879fe;hpb=e5456e3c2697c4e17fc9aa3439f2e305517b4d96;p=pdclib.old 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; } -*/