Make this i386-compatible; massive clean-up.
[unix-history] / usr / src / lib / libc / string / strcspn.c
CommitLineData
5b6c2309
KB
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
317e5946
KB
3 * All rights reserved.
4 *
5b6c2309
KB
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * %sccs.include.redist.c%
36b10697
RE
9 */
10
2ce81398 11#if defined(LIBC_SCCS) && !defined(lint)
a64329b4 12static char sccsid[] = "@(#)strcspn.c 5.6 (Berkeley) %G%";
317e5946 13#endif /* LIBC_SCCS and not lint */
36b10697 14
a64329b4 15#include <sys/cdefs.h>
5b6c2309
KB
16#include <string.h>
17
18/*
19 * Span the complement of string s2.
20 */
21size_t
22strcspn(s1, s2)
23 const char *s1;
24 register const char *s2;
36b10697 25{
5b6c2309
KB
26 register const char *p, *spanp;
27 register char c, sc;
36b10697 28
5b6c2309
KB
29 /*
30 * Stop as soon as we find any character from s2. Note that there
31 * must be a NUL in s2; it suffices to stop when we find that, too.
32 */
33 for (p = s1;;) {
34 c = *p++;
35 spanp = s2;
36 do {
37 if ((sc = *spanp++) == c)
38 return (p - 1 - s1);
39 } while (sc != 0);
36b10697 40 }
5b6c2309 41 /* NOTREACHED */
36b10697 42}