Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
strspn.c File Reference
#include <stdint.h>
#include <string.h>
Include dependency graph for strspn.c:

Go to the source code of this file.

Macros

#define BITOP(a, b, op)   ((a)[(size_t)(b) / (8 * sizeof *(a))] op(size_t) 1 << ((size_t)(b) % (8 * sizeof *(a))))
 

Functions

size_t strspn (const char *s, const char *c)
 

Macro Definition Documentation

◆ BITOP

#define BITOP (   a,
  b,
  op 
)    ((a)[(size_t)(b) / (8 * sizeof *(a))] op(size_t) 1 << ((size_t)(b) % (8 * sizeof *(a))))

Definition at line 4 of file strspn.c.

Function Documentation

◆ strspn()

size_t strspn ( const char *  s,
const char *  c 
)

Definition at line 7 of file strspn.c.

8 {
9  const char* a = s;
10  size_t byteset[32 / sizeof(size_t)] = {0};
11 
12  if(!c[0])
13  {
14  return 0;
15  }
16 
17  if(!c[1])
18  {
19  for(; *s == *c; s++)
20  {
21  {
22  ;
23  }
24  }
25  return (uintptr_t)s - (uintptr_t)a;
26  }
27 
28  for(; *c && BITOP(byteset, *(const unsigned char*)c, |=); c++)
29  {
30  {
31  ;
32  }
33  }
34  for(; *s && BITOP(byteset, *(const unsigned char*)s, &); s++)
35  {
36  {
37  ;
38  }
39  }
40 
41  return (uintptr_t)s - (uintptr_t)a;
42 }
#define BITOP(a, b, op)
Definition: strspn.c:4

References BITOP.