Fix a compiler warning in initStringInfo().
[pgsql.git] / src / port / strnlen.c
blob60c3b458c6bf8eeb934771fbbbc565f10b02a0a7
1 /*-------------------------------------------------------------------------
3 * strnlen.c
4 * Fallback implementation of strnlen().
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * IDENTIFICATION
11 * src/port/strnlen.c
13 *-------------------------------------------------------------------------
16 #include "c.h"
19 * Implementation of posix' strnlen for systems where it's not available.
21 * Returns the number of characters before a null-byte in the string pointed
22 * to by str, unless there's no null-byte before maxlen. In the latter case
23 * maxlen is returned.
25 size_t
26 strnlen(const char *str, size_t maxlen)
28 const char *p = str;
30 while (maxlen-- > 0 && *p)
31 p++;
32 return p - str;