os-workshop

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

memchr.c (620B)


      1 /*
      2 ** Copyright 2001, Manuel J. Petit. 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 void *
     16 memchr(void const *buf, int c, size_t len) {
     17     size_t i;
     18     unsigned char const *b= buf;
     19     unsigned char        x= (c&0xff);
     20 
     21     for (i= 0; i< len; i++) {
     22         if (b[i]== x) {
     23             return (void *)(b+i);
     24         }
     25     }
     26 
     27     return NULL;
     28 }
     29