1863f95b1Smrg/*
2863f95b1Smrg * Copyright (c) 2009 Apple Inc.
3863f95b1Smrg *
4863f95b1Smrg * Permission is hereby granted, free of charge, to any person obtaining a
5863f95b1Smrg * copy of this software and associated documentation files (the "Software"),
6863f95b1Smrg * to deal in the Software without restriction, including without limitation
7863f95b1Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8863f95b1Smrg * and/or sell copies of the Software, and to permit persons to whom the
9863f95b1Smrg * Software is furnished to do so, subject to the following conditions:
10863f95b1Smrg *
11863f95b1Smrg * The above copyright notice and this permission notice shall be included in
12863f95b1Smrg * all copies or substantial portions of the Software.
13863f95b1Smrg *
14863f95b1Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15863f95b1Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16863f95b1Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17863f95b1Smrg * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18863f95b1Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19863f95b1Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20863f95b1Smrg * DEALINGS IN THE SOFTWARE.
21863f95b1Smrg */
22863f95b1Smrg
23863f95b1Smrg /*
24863f95b1Smrg  * Author:  Jeremy Huddleston, Apple Inc.
25863f95b1Smrg  */
26863f95b1Smrg
27863f95b1Smrg#ifdef HAVE_CONFIG_H
28863f95b1Smrg#include "config.h"
29863f95b1Smrg#endif
30863f95b1Smrg
31863f95b1Smrg#include <strnlen.h>
32863f95b1Smrg#include <string.h>
33863f95b1Smrg
34863f95b1Smrgsize_t strnlen(const char *s, size_t maxlen) {
35863f95b1Smrg    const char *p = memchr(s, 0, maxlen);
36863f95b1Smrg    return (size_t)(p ? (p - s) : maxlen);
37863f95b1Smrg}
38