Blame src/strnlen.h

Packit ae9e2a
/*
Packit ae9e2a
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit ae9e2a
 *
Packit ae9e2a
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit ae9e2a
 * a Linking Exception. For full terms see the included COPYING file.
Packit ae9e2a
 */
Packit ae9e2a
#ifndef INCLUDE_strlen_h__
Packit ae9e2a
#define INCLUDE_strlen_h__
Packit ae9e2a
Packit ae9e2a
#if defined(__MINGW32__) || defined(__sun) || defined(__APPLE__) || defined(__MidnightBSD__) ||\
Packit ae9e2a
	(defined(_MSC_VER) && _MSC_VER < 1500)
Packit ae9e2a
#   define NO_STRNLEN
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
#ifdef NO_STRNLEN
Packit ae9e2a
GIT_INLINE(size_t) p_strnlen(const char *s, size_t maxlen) {
Packit ae9e2a
	const char *end = memchr(s, 0, maxlen);
Packit ae9e2a
	return end ? (size_t)(end - s) : maxlen;
Packit ae9e2a
}
Packit ae9e2a
#else
Packit ae9e2a
#   define p_strnlen strnlen
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
#endif