aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/string/strncpy.c
blob: 017fdab40a042dbf5fdb8d3c2fd805c34435afdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
/*
 * Copyright (c) 2008 Travis Geiselbrecht
 *
 * Use of this source code is governed by a MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT
 */
#include <string.h>
#include <sys/types.h>

char *
strncpy(char *dest, char const *src, size_t count) {
    char *tmp = dest;

    size_t i;
    for (i = 0; i < count && (*dest++ = *src++) != '\0'; i++)
        ;
    for (; i < count; i++)
        *dest++ = '\0';

    return tmp;
}