| 1 |
'\" t |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.TH stpcpy 3 2026-03-03 "Linux man-pages 6.18" |
| 7 |
.SH NAME |
| 8 |
stpcpy \- string return-offset-pointer copy |
| 9 |
.SH LIBRARY |
| 10 |
Standard C library |
| 11 |
.RI ( libc ,\~ \-lc ) |
| 12 |
.SH SYNOPSIS |
| 13 |
.nf |
| 14 |
.B #include <string.h> |
| 15 |
.P |
| 16 |
.BI "char *stpcpy(char *restrict " dst ", const char *restrict " src ); |
| 17 |
.fi |
| 18 |
.P |
| 19 |
.RS -4 |
| 20 |
Feature Test Macro Requirements for glibc (see |
| 21 |
.BR feature_test_macros (7)): |
| 22 |
.RE |
| 23 |
.P |
| 24 |
.BR stpcpy (): |
| 25 |
.nf |
| 26 |
Since glibc 2.10: |
| 27 |
_POSIX_C_SOURCE >= 200809L |
| 28 |
Before glibc 2.10: |
| 29 |
_GNU_SOURCE |
| 30 |
.fi |
| 31 |
.SH DESCRIPTION |
| 32 |
.BR stpcpy () |
| 33 |
is similar to |
| 34 |
.BR strcpy (3), |
| 35 |
but returns a pointer to the terminating null byte in |
| 36 |
.IR dst . |
| 37 |
.P |
| 38 |
It is equivalent to both of the following expressions: |
| 39 |
.P |
| 40 |
.in +4n |
| 41 |
.EX |
| 42 |
memset(mempcpy(dst, src, strlen(src)), \[aq]\[rs]0\[aq], 1); |
| 43 |
strcpy(dst, src) + strlen(src) |
| 44 |
.EE |
| 45 |
.in |
| 46 |
.SH RETURN VALUE |
| 47 |
This function returns |
| 48 |
a pointer to the terminating null byte of the copied string. |
| 49 |
.SH ATTRIBUTES |
| 50 |
For an explanation of the terms used in this section, see |
| 51 |
.BR attributes (7). |
| 52 |
.TS |
| 53 |
allbox; |
| 54 |
lbx lb lb |
| 55 |
l l l. |
| 56 |
Interface Attribute Value |
| 57 |
T{ |
| 58 |
.na |
| 59 |
.nh |
| 60 |
.BR stpcpy () |
| 61 |
T} Thread safety MT-Safe |
| 62 |
.TE |
| 63 |
.SH STANDARDS |
| 64 |
POSIX.1-2008. |
| 65 |
.SH HISTORY |
| 66 |
POSIX.1-2008. |
| 67 |
.SH EXAMPLES |
| 68 |
.\" SRC BEGIN (stpcpy.c) |
| 69 |
.EX |
| 70 |
#include <err.h> |
| 71 |
#include <stdio.h> |
| 72 |
#include <stdlib.h> |
| 73 |
#include <string.h> |
| 74 |
\& |
| 75 |
int |
| 76 |
main(void) |
| 77 |
{ |
| 78 |
char *p; |
| 79 |
char *buf1; |
| 80 |
size_t len, size; |
| 81 |
\& |
| 82 |
size = strlen("Hello ") + strlen("world") + strlen("!") + 1; |
| 83 |
buf1 = malloc(sizeof(*buf1) * size); |
| 84 |
if (buf1 == NULL) |
| 85 |
err(EXIT_FAILURE, "malloc()"); |
| 86 |
\& |
| 87 |
p = buf1; |
| 88 |
p = stpcpy(p, "Hello "); |
| 89 |
p = stpcpy(p, "world"); |
| 90 |
p = stpcpy(p, "!"); |
| 91 |
len = p \- buf1; |
| 92 |
\& |
| 93 |
printf("[len = %zu]: ", len); |
| 94 |
puts(buf1); // "Hello world!" |
| 95 |
free(buf1); |
| 96 |
\& |
| 97 |
exit(EXIT_SUCCESS); |
| 98 |
} |
| 99 |
.EE |
| 100 |
.\" SRC END |
| 101 |
.SH SEE ALSO |
| 102 |
.BR strcpy (3), |
| 103 |
.BR strdup (3), |
| 104 |
.BR string (3), |
| 105 |
.BR wcpcpy (3), |
| 106 |
.BR string_copying (7) |