Movatterモバイル変換


[0]ホーム

URL:


strscpy
Prev String Manipulation Next

Name

strscpy — Copy a C-string into a sized buffer

Synopsis

ssize_tstrscpy(char *dest,
 const char *src,
 size_tcount);
 

Arguments

char * dest

Where to copy the string to

const char * src

Where to copy the string from

size_t count

Size of destination buffer

Description

Copy the string, or as much of it as fits, into the dest buffer. The routine returns the number of characters copied (not including the trailing NUL) or -E2BIG if the destination buffer wasn't big enough. The behavior is undefined if the string buffers overlap. The destination buffer is always NUL terminated, unless it's zero-sized.

Preferred tostrlcpy since the API doesn't require reading memory from the src string beyond the specifiedcount bytes, and since the return value is easier to error-check thanstrlcpy's. In addition, the implementation is robust to the string changing out from underneath it, unlike the currentstrlcpy implementation.

Preferred tostrncpy since it always returns a valid string, and doesn't unnecessarily force the tail of the destination buffer to be zeroed. If the zeroing is desired, it's likely cleaner to usestrscpy with an overflow test, then justmemset the tail of the dest buffer.


Prev Up Next
strlcpy Home strcat

[8]ページ先頭

©2009-2025 Movatter.jp