1271612Sdes/*-
2271612Sdes * Copyright (c) 2011-2012 Dag-Erling Sm��rgrav
3271612Sdes * All rights reserved.
4271612Sdes *
5271612Sdes * Redistribution and use in source and binary forms, with or without
6271612Sdes * modification, are permitted provided that the following conditions
7271612Sdes * are met:
8271612Sdes * 1. Redistributions of source code must retain the above copyright
9271612Sdes *    notice, this list of conditions and the following disclaimer.
10271612Sdes * 2. Redistributions in binary form must reproduce the above copyright
11271612Sdes *    notice, this list of conditions and the following disclaimer in the
12271612Sdes *    documentation and/or other materials provided with the distribution.
13271612Sdes * 3. The name of the author may not be used to endorse or promote
14271612Sdes *    products derived from this software without specific prior written
15271612Sdes *    permission.
16271612Sdes *
17271612Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18271612Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19271612Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20271612Sdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21271612Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22271612Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23271612Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24271612Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25271612Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26271612Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27271612Sdes * SUCH DAMAGE.
28271612Sdes *
29271612Sdes * $Id: openpam_strlset.c 807 2014-09-09 09:41:32Z des $
30271612Sdes */
31271612Sdes
32271612Sdes#ifdef HAVE_CONFIG_H
33271612Sdes# include "config.h"
34271612Sdes#endif
35271612Sdes
36271612Sdes#ifndef HAVE_STRLSET
37271612Sdes
38271612Sdes#include <stddef.h>
39271612Sdes
40271612Sdes#include "openpam_strlset.h"
41271612Sdes
42271612Sdes/*
43271612Sdes * like memset(3), but stops at the first NUL byte and NUL-terminates the
44271612Sdes * result.  Returns the number of bytes that were written, not including
45271612Sdes * the terminating NUL.
46271612Sdes */
47271612Sdessize_t
48271612Sdesopenpam_strlset(char *str, int ch, size_t size)
49271612Sdes{
50271612Sdes	size_t len;
51271612Sdes
52271612Sdes	for (len = 0; *str && size > 1; ++len, --size)
53271612Sdes		*str++ = ch;
54271612Sdes	*str = '\0';
55271612Sdes	return (++len);
56271612Sdes}
57271612Sdes
58271612Sdes#endif
59