os-workshop

same materials and sample source for RV32 OS projects
git clone http://frotz.net/git/os-workshop.git
Log | Files | Refs

strspn.c (705B)


      1 /*
      2 ** Copyright 2001, Travis Geiselbrecht. All rights reserved.
      3 ** Distributed under the terms of the NewOS License.
      4 */
      5 /*
      6  * Copyright (c) 2008 Travis Geiselbrecht
      7  *
      8  * Use of this source code is governed by a MIT-style
      9  * license that can be found in the LICENSE file or at
     10  * https://opensource.org/licenses/MIT
     11  */
     12 #include <string.h>
     13 #include <stdint.h>
     14 
     15 size_t
     16 strspn(char const *s, char const *accept) {
     17     const char *p;
     18     const char *a;
     19     size_t count = 0;
     20 
     21     for (p = s; *p != '\0'; ++p) {
     22         for (a = accept; *a != '\0'; ++a) {
     23             if (*p == *a)
     24                 break;
     25         }
     26         if (*a == '\0')
     27             return count;
     28         ++count;
     29     }
     30 
     31     return count;
     32 }