stpncpy.c (559a218c9b257775fb249b67945fe4a05b7a6b9f) stpncpy.c (e55512504d0178983978d64d67eed1cc85826523)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 14 unchanged lines hidden (view full) ---

23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <string.h>
30
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 14 unchanged lines hidden (view full) ---

23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <string.h>
30
31#undef stpncpy /* _FORTIFY_SOURCE */
32
31char *
32stpncpy(char * __restrict dst, const char * __restrict src, size_t n)
33{
34
35 for (; n--; dst++, src++) {
36 if (!(*dst = *src)) {
37 char *ret = dst;
38 while (n--)
39 *++dst = '\0';
40 return (ret);
41 }
42 }
43 return (dst);
44}
33char *
34stpncpy(char * __restrict dst, const char * __restrict src, size_t n)
35{
36
37 for (; n--; dst++, src++) {
38 if (!(*dst = *src)) {
39 char *ret = dst;
40 while (n--)
41 *++dst = '\0';
42 return (ret);
43 }
44 }
45 return (dst);
46}