Back to libut API Reference


SYNOPSIS

    #include "libut/ut.h"
    char* UT_strncpy(char *dst, char *src, size_t n);


DESCRIPTION

This is a safer, NUL-terminating version of strncpy(3). It copies the src string to dst up to n bytes, making the last byte NUL.

The defect of strncpy(3) is that it does not NUL-terminate the destination string dst when the src string (without its NUL-terminator) is of length n bytes or longer. This function NUL-terminates the dst string at the n-th byte instead.


RETURN VALUE

The dst pointer is returned.


NOTES

An equivalent function called strlcpy is available on some platforms.


AUTHOR

Troy D. Hanson <thanson@users.sourceforge.net>