]> pd.if.org Git - pdclib/blobdiff - functions/string/strrchr.c
Added a warning about missing test drivers.
[pdclib] / functions / string / strrchr.c
index 77504433f9182a0066e821e65dd139e7c24df052..b29d0a6e26525d236a5d7ec64d963fb2c4e91b3a 100644 (file)
@@ -1,31 +1,27 @@
-// ----------------------------------------------------------------------------
-// $Id$
-// ----------------------------------------------------------------------------
-// Public Domain C Library - http://pdclib.sourceforge.net
-// This code is Public Domain. Use, modify, and redistribute at will.
-// ----------------------------------------------------------------------------
+/* $Id$ */
 
-// ----------------------------------------------------------------------------
-// C++
+/* Release $Name$ */
 
-const char * strrchr( const char * s, int c ) { /* TODO */ };
-char * strrchr( char * s, int c ) { /* TODO */ };
+/* strrchr( const char *, int c )
 
-// ----------------------------------------------------------------------------
-// Standard C
+   This file is part of the Public Domain C Library (PDCLib).
+   Permission is granted to use, modify, and / or redistribute at will.
+*/
 
-char * strrchr( const char * s, int c ) { /* TODO */ };
+#include <string.h>
 
-/* PDPC code - unreviewed
+char * strrchr( const char * s, int c )
 {
-    const char *p;
-    
-    p = s + strlen(s);
-    while (p >= s)
+    size_t i = 0;
+    while ( p[i++] );
+    do
     {
-        if (*p == (char)c) return ((char *)p);
-        p--;
-    }
-    return (NULL);
+        if ( p[--i] == (char) c )
+        {
+            return (char *) p + i;
+        }
+    } while ( i );
+    return NULL;
 }
-*/
+
+#warning Test driver missing.