stpcpy(3) — Linux manual page

NAME | LIBRARY | SYNOPSIS | DESCRIPTION | RETURN VALUE | ATTRIBUTES | STANDARDS | HISTORY | EXAMPLES | SEE ALSO | COLOPHON

stpcpy(3)                Library Functions Manual               stpcpy(3)

NAME         top

       stpcpy - string return-offset-pointer copy

LIBRARY         top

       Standard C library (libc, -lc)

SYNOPSIS         top

       #include <string.h>

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

   Feature Test Macro Requirements for glibc (see
   feature_test_macros(7)):

       stpcpy():
           Since glibc 2.10:
               _POSIX_C_SOURCE >= 200809L
           Before glibc 2.10:
               _GNU_SOURCE

DESCRIPTION         top

       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)

RETURN VALUE         top

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

ATTRIBUTES         top

       For an explanation of the terms used in this section, see
       attributes(7).
       ┌──────────────────────────────────────┬───────────────┬─────────┐
       │ Interface                            Attribute     Value   │
       ├──────────────────────────────────────┼───────────────┼─────────┤
       │ stpcpy()                             │ Thread safety │ MT-Safe │
       └──────────────────────────────────────┴───────────────┴─────────┘

STANDARDS         top

       POSIX.1-2008.

HISTORY         top

       POSIX.1-2008.

EXAMPLES         top

       #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);
       }

SEE ALSO         top

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

COLOPHON         top

       This page is part of the man-pages (Linux kernel and C library
       user-space interface documentation) project.  Information about
       the project can be found at 
       ⟨https://www.kernel.org/doc/man-pages/⟩.  If you have a bug report
       for this manual page, see
       ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.
       This page was obtained from the tarball man-pages-6.18.tar.gz
       fetched from
       ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on
       2026-05-24.  If you discover any rendering problems in this HTML
       version of the page, or you believe there is a better or more up-
       to-date source for the page, or you have corrections or
       improvements to the information in this COLOPHON (which is not
       part of the original manual page), send a mail to
       man-pages@man7.org

Linux man-pages 6.18            2026-03-03                      stpcpy(3)

Pages that refer to this page: strcpy(3)string(3)wcpcpy(3)feature_test_macros(7)signal-safety(7)string_copying(7)