]> pd.if.org Git - pdclib/blobdiff - functions/string/strrchr.c
Test-compile fixes.
[pdclib] / functions / string / strrchr.c
index 4f1e2b5cb58fbd230de5b04776d5050f62cc14f0..77b633fffc6968ac6e8286d1c1f5aa8fd684a377 100644 (file)
@@ -1,26 +1,27 @@
-/* ----------------------------------------------------------------------------
- * $Id$
- * ----------------------------------------------------------------------------
- * Public Domain C Library - http://pdclib.sourceforge.net
- * This code is Public Domain. Use, modify, and redistribute at will.
- * --------------------------------------------------------------------------*/
+/* $Id$ */
 
-#include <__NULL.h>
+/* Release $Name$ */
 
-char * strrchr( const char * src, int c )
+/* strrchr( const char *, int c )
+
+   This file is part of the Public Domain C Library (PDCLib).
+   Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+#include <string.h>
+
+char * strrchr( const char * s, int c )
 {
-    const char * p = src;
-    while ( *p != '\0' )
+    size_t i = 0;
+    while ( s[i++] );
+    do
     {
-        ++p;
-    }
-    while ( p >= src )
-    {
-        if ( *p == (char) c )
+        if ( s[--i] == (char) c )
         {
-            return (char *) p;
+            return (char *) s + i;
         }
-        --p;
-    }
+    } while ( i );
     return NULL;
 }
+
+#warning Test driver missing.