~ubuntu-branches/ubuntu/vivid/emscripten/vivid-proposed

« back to all changes in this revision

Viewing changes to system/lib/libc/musl/src/string/strchrnul.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2014-01-19 14:12:40 UTC
  • mfrom: (4.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140119141240-nfiw0p8033oitpfz
Tags: 1.9.0~20140119~7dc8c2f-1
* New snapshot release (Closes: #733714)
* Provide sources for javascript and flash. Done in orig-tar.sh
  Available in third_party/websockify/include/web-socket-js/src/
  (Closes: #735903)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <string.h>
 
2
#include <stdlib.h>
 
3
#include <stdint.h>
 
4
#include <limits.h>
 
5
#include "libc.h"
 
6
 
 
7
#define ALIGN (sizeof(size_t))
 
8
#define ONES ((size_t)-1/UCHAR_MAX)
 
9
#define HIGHS (ONES * (UCHAR_MAX/2+1))
 
10
#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
 
11
 
 
12
char *__strchrnul(const char *s, int c)
 
13
{
 
14
        size_t *w, k;
 
15
 
 
16
        c = (unsigned char)c;
 
17
        if (!c) return (char *)s + strlen(s);
 
18
 
 
19
        for (; (uintptr_t)s % ALIGN; s++)
 
20
                if (!*s || *(unsigned char *)s == c) return (char *)s;
 
21
        k = ONES * c;
 
22
        for (w = (void *)s; !HASZERO(*w) && !HASZERO(*w^k); w++);
 
23
        for (s = (void *)w; *s && *(unsigned char *)s != c; s++);
 
24
        return (char *)s;
 
25
}
 
26
 
 
27
weak_alias(__strchrnul, strchrnul);