]> pd.if.org Git - pdclib/blobdiff - functions/string/strcspn.c
Added dummy test drivers to each *.c file, and target 'test' to Makefile.
[pdclib] / functions / string / strcspn.c
index c2db7ab32abc73b2bac4349ae1b868417875720e..308fe362fcfdf47f59233348a64140a12010e00d 100644 (file)
@@ -1,28 +1,39 @@
-// ----------------------------------------------------------------------------
-// $Id$
-// ----------------------------------------------------------------------------
-// Public Domain C Library - http://pdclib.sourceforge.net
-// This code is Public Domain. Use, modify, and redistribute at will.
-// ----------------------------------------------------------------------------
+/* $Id$ */
 
-size_t strcspn( const char * s1, const char * s2 ) { /* TODO */ };
+/* Release $Name$ */
 
-/* PDPC code - unreviewed
+/* strcspn( const char *, const char * )
+
+   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>
+
+size_t strcspn( const char * s1, const char * s2 )
 {
-    const char *p1;
-    const char *p2;
-    
-    p1 = s1;
-    while (*p1 != '\0')
+    size_t len = 0;
+    const char * p;
+    while ( s1[len] )
     {
-        p2 = s2;
-        while (*p2 != '\0')
+        p = s2;
+        while ( *p )
         {
-            if (*p1 == *p2) return ((size_t)(p1 - s1));
-            p2++;
+            if ( s1[len] == *p++ )
+            {
+                return len;
+            }
         }
-        p1++;
+        ++len;
     }
-    return ((size_t)(p1 - s1));
+    return len;
 }
-*/
+
+#warning Test driver missing.
+
+#ifdef TEST
+int main()
+{
+    return 0;
+}
+#endif