stpcpy

Section: C Library Functions (3)
Updated: 2026-03-03
Index JM Home Page roff page
 

名前

stpcpy - string return-offset-pointer copy  

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#include <string.h>

char *stpcpy(char *restrict dst, const char *restrict src);

glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):

stpcpy():

    Since glibc 2.10:
        _POSIX_C_SOURCE >= 200809L
    Before glibc 2.10:
        _GNU_SOURCE
 

説明

stpcpy() is similar to strcpy(3), but returns a pointer to the terminating null byte in dst.

It is equivalent to both of the following expressions:

memset(mempcpy(dst, src, strlen(src)), '\0', 1);
strcpy(dst, src) + strlen(src)
 

返り値

This function returns a pointer to the terminating null byte of the copied string.  

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース属性値
stpcpy() Thread safetyMT-Safe
 

標準規格

POSIX.1-2008.  

歴史

POSIX.1-2008.  

例

#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
main(void)
{
    char    *p;
    char    *buf1;
    size_t  len, size;

    size = strlen("Hello ") + strlen("world") + strlen("!") + 1;
    buf1 = malloc(sizeof(*buf1) * size);
    if (buf1 == NULL)
        err(EXIT_FAILURE, "malloc()");

    p = buf1;
    p = stpcpy(p, "Hello ");
    p = stpcpy(p, "world");
    p = stpcpy(p, "!");
    len = p - buf1;

    printf("[len = %zu]: ", len);
    puts(buf1);  // "Hello world!"
    free(buf1);

    exit(EXIT_SUCCESS);
}
 

関連項目

strcpy(3), strdup(3), string(3), wcpcpy(3), string_copying(7)


 

Index

名前
ライブラリ
書式
説明
返り値
属性
標準規格
歴史
例
関連項目

This document was created by man2html, using the manual pages.