stpncpy(3) Library Functions Manual stpncpy(3) stpncpy, strncpy - (libc -lc) #include char *strncpy(size_t dsize; char dst[restrict dsize], const char *restrict src, size_t dsize); char *stpncpy(size_t dsize; char dst[restrict dsize], const char *restrict src, size_t dsize); glibc ( feature_test_macros(7)): stpncpy(): glibc 2.10: _POSIX_C_SOURCE >= 200809L glibc 2.10: _GNU_SOURCE src dst. . . . strncpy() stpncpy(dst, src, dsize), dst stpncpy() memset(mempcpy(dst, src, strnlen(src, dsize)), '\0', dsize - strnlen(src, dsize)) strncpy() dst. stpncpy() dest + strnlen(src, n). attributes(7). +------------+------------------------------------+--------------------+ || | | +------------+------------------------------------+--------------------+ |stpncpy(), | | MT-Safe | |strncpy() | | | +------------+------------------------------------+--------------------+ strncpy() C11, POSIX.1-2008. stpncpy() POSIX.1-2008. strncpy() C89, POSIX.1-2001, SVr4, 4.3BSD. stpncpy() glibc 1.07. POSIX.1-2008. . ( string_copying(7)). : strncpy(buf, "1", 5); // { '1', 0, 0, 0, 0 } strncpy(buf, "1234", 5); // { '1', '2', '3', '4', 0 } strncpy(buf, "12345", 5); // { '1', '2', '3', '4', '5' } strncpy(buf, "123456", 5); // { '1', '2', '3', '4', '5' } . ( ) . #include #include #include #include int main(void) { char *p; char buf1[20]; char buf2[20]; size_t len; if (sizeof(buf2) < strlen("Hello world!")) errx("strncpy: truncating character sequence"); strncpy(buf2, "Hello world!", sizeof(buf2)); len = strnlen(buf2, sizeof(buf2)); printf("[len = %zu]: ", len); fwrite(buf2, 1, len, stdout); putchar('\n'); if (sizeof(buf1) < strlen("Hello world!")) errx("stpncpy: truncating character sequence"); p = stpncpy(buf1, "Hello world!", sizeof(buf1)); len = p - buf1; printf("[len = %zu]: ", len); fwrite(buf1, 1, len, stdout); putchar('\n'); exit(EXIT_SUCCESS); } wcpncpy(3), string_copying(7) 3 . . : . 6.18 25 2026 stpncpy(3)