\hypertarget{strcspn_8c_source}{}\doxysection{strcspn.\+c}
\label{strcspn_8c_source}\index{libkern/strcspn.c@{libkern/strcspn.c}}
\mbox{\hyperlink{strcspn_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00001}00001 \textcolor{comment}{/*-\/}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00002}00002 \textcolor{comment}{ * SPDX-\/License-\/Identifier: BSD-\/2-\/Clause-\/FreeBSD}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00003}00003 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00004}00004 \textcolor{comment}{ * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00005}00005 \textcolor{comment}{ * All rights reserved.}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00006}00006 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00007}00007 \textcolor{comment}{ * Redistribution and use in source and binary forms, with or without}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00008}00008 \textcolor{comment}{ * modification, are permitted provided that the following conditions}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00009}00009 \textcolor{comment}{ * are met:}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00010}00010 \textcolor{comment}{ * 1. Redistributions of source code must retain the above copyright}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00011}00011 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer.}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00012}00012 \textcolor{comment}{ * 2. Redistributions in binary form must reproduce the above copyright}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00013}00013 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer in the}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00014}00014 \textcolor{comment}{ *    documentation and/or other materials provided with the distribution.}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00015}00015 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00016}00016 \textcolor{comment}{ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00017}00017 \textcolor{comment}{ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00018}00018 \textcolor{comment}{ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00019}00019 \textcolor{comment}{ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00020}00020 \textcolor{comment}{ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00021}00021 \textcolor{comment}{ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00022}00022 \textcolor{comment}{ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00023}00023 \textcolor{comment}{ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00024}00024 \textcolor{comment}{ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00025}00025 \textcolor{comment}{ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00026}00026 \textcolor{comment}{ * SUCH DAMAGE.}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00027}00027 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00028}00028 }
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00029}00029 \textcolor{preprocessor}{\#include <sys/cdefs.h>}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00030}\mbox{\hyperlink{strcspn_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{00030}} \mbox{\hyperlink{strcspn_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{\_\_FBSDID}}(\textcolor{stringliteral}{"{}\$FreeBSD\$"{}});}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00031}00031 }
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00032}00032 \textcolor{preprocessor}{\#include <sys/libkern.h>}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00033}00033 \textcolor{preprocessor}{\#include <sys/types.h>}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00034}00034 \textcolor{preprocessor}{\#include <sys/limits.h>}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00035}00035 }
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00036}\mbox{\hyperlink{strcspn_8c_a69811eff93c8ab4d1354e75f4421af43}{00036}} \textcolor{preprocessor}{\#define IDX(c)  ((u\_char)(c) / LONG\_BIT)}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00037}\mbox{\hyperlink{strcspn_8c_adac7f4e489ae912797a46346cab80d41}{00037}} \textcolor{preprocessor}{\#define BIT(c)  ((u\_long)1 << ((u\_char)(c) \% LONG\_BIT))}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00038}00038 }
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00039}00039 \textcolor{keywordtype}{size\_t} }
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00040}\mbox{\hyperlink{strcspn_8c_a40e73df85659af0b12e889089b6f72ef}{00040}} \mbox{\hyperlink{strcspn_8c_a40e73df85659af0b12e889089b6f72ef}{strcspn}}(\textcolor{keyword}{const} \textcolor{keywordtype}{char} *s, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *charset)}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00041}00041 \{}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00042}00042         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00043}00043 \textcolor{comment}{         * NB: idx and bit are temporaries whose use causes gcc 3.4.2 to}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00044}00044 \textcolor{comment}{         * generate better code.  Without them, gcc gets a little confused.}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00045}00045 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00046}00046         \textcolor{keyword}{const} \textcolor{keywordtype}{char} *s1;}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00047}00047         u\_long bit;}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00048}00048         u\_long tbl[(UCHAR\_MAX + 1) / LONG\_BIT];}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00049}00049         \textcolor{keywordtype}{int} idx;}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00050}00050 }
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00051}00051         \textcolor{keywordflow}{if}(*s == \textcolor{charliteral}{'\(\backslash\)0'})}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00052}00052                 \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00053}00053 }
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00054}00054 \textcolor{preprocessor}{\#if LONG\_BIT == 64      }\textcolor{comment}{/* always better to unroll on 64-\/bit architectures */}\textcolor{preprocessor}{}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00055}00055         tbl[0] = 1;}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00056}00056         tbl[3] = tbl[2] = tbl[1] = 0;}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00057}00057 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00058}00058         \textcolor{keywordflow}{for} (tbl[0] = idx = 1; idx < \textcolor{keyword}{sizeof}(tbl) / \textcolor{keyword}{sizeof}(tbl[0]); idx++)}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00059}00059                 tbl[idx] = 0;}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00060}00060 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00061}00061         \textcolor{keywordflow}{for} (; *charset != \textcolor{charliteral}{'\(\backslash\)0'}; charset++) \{}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00062}00062                 idx = \mbox{\hyperlink{strcspn_8c_a69811eff93c8ab4d1354e75f4421af43}{IDX}}(*charset);}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00063}00063                 bit = \mbox{\hyperlink{strcspn_8c_adac7f4e489ae912797a46346cab80d41}{BIT}}(*charset);}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00064}00064                 tbl[idx] |= bit;}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00065}00065         \}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00066}00066 }
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00067}00067         \textcolor{keywordflow}{for}(s1 = s; ; s1++) \{}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00068}00068                 idx = \mbox{\hyperlink{strcspn_8c_a69811eff93c8ab4d1354e75f4421af43}{IDX}}(*s1);}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00069}00069                 bit = \mbox{\hyperlink{strcspn_8c_adac7f4e489ae912797a46346cab80d41}{BIT}}(*s1);}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00070}00070                 \textcolor{keywordflow}{if} ((tbl[idx] \& bit) != 0)}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00071}00071                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00072}00072         \}}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00073}00073         \textcolor{keywordflow}{return} (s1 -\/ s);}
\DoxyCodeLine{\Hypertarget{strcspn_8c_source_l00074}00074 \}}

\end{DoxyCode}
