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

Go to the source code of this file.

Macros

#define ALIGN   (sizeof(size_t))
 
#define ONES   ((size_t)-1 / UCHAR_MAX)
 
#define HIGHS   (ONES * (UCHAR_MAX / 2 + 1))
 
#define HASZERO(x)   ((x)-ONES & ~(x)&HIGHS)
 

Functions

char * __strchrnul (const char *s, int c)
 

Macro Definition Documentation

◆ ALIGN

#define ALIGN   (sizeof(size_t))

Definition at line 8 of file strchrnul.c.

◆ HASZERO

#define HASZERO (   x)    ((x)-ONES & ~(x)&HIGHS)

Definition at line 11 of file strchrnul.c.

◆ HIGHS

#define HIGHS   (ONES * (UCHAR_MAX / 2 + 1))

Definition at line 10 of file strchrnul.c.

◆ ONES

#define ONES   ((size_t)-1 / UCHAR_MAX)

Definition at line 9 of file strchrnul.c.

Function Documentation

◆ __strchrnul()

char* __strchrnul ( const char *  s,
int  c 
)

Definition at line 13 of file strchrnul.c.

14 {
15  const size_t* w;
16  size_t k;
17  c = (unsigned char)c;
18 
19  if(!c)
20  {
21  return (char*)(uintptr_t)s + strlen(s);
22  }
23 
24  for(; (uintptr_t)s % ALIGN; s++)
25  {
26  if(!*s || *(const unsigned char*)s == c)
27  {
28  return (char*)(uintptr_t)s;
29  }
30  }
31 
32  k = ONES * (unsigned long)c;
33 
34  for(w = (const void*)s; !HASZERO(*w) && !HASZERO(*w ^ k); w++)
35  {
36  {
37  ;
38  }
39  }
40  for(s = (const void*)w; *s && *(const unsigned char*)s != c; s++)
41  {
42  {
43  ;
44  }
45  }
46 
47  return (char*)(uintptr_t)s;
48 }
#define HASZERO(x)
Definition: strchrnul.c:11
#define ONES
Definition: strchrnul.c:9
size_t strlen(const char *str)
Returns the length of the given null-terminated byte string.
Definition: strlen.c:77
#define ALIGN
Definition: strchrnul.c:8

References ALIGN, HASZERO, ONES, and strlen().

Referenced by strchr(), and strcspn().

Here is the caller graph for this function: