# Designing a Better \`strcpy\`

DevFeed: [Designing a Better \`strcpy\`](<https://devfeed.tech/articles/designing-a-better-strcpy-27355.md>)

Original publisher: [Read original article](<https://saagarjha.com/blog/2020/04/12/designing-a-better-strcpy/>)

Published: 2020-04-12T00:00:00Z

Content type: article

Language: en

Sources: [Saagar Jha](<https://devfeed.tech/sources/saagar-jha.md>)

Topics: [C](<https://devfeed.tech/topics/c.md>), [Security](<https://devfeed.tech/topics/security.md>), [POSIX](<https://devfeed.tech/topics/posix.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [compilers](<https://devfeed.tech/tags/compilers.md>), [function](<https://devfeed.tech/tags/function.md>), [memory](<https://devfeed.tech/tags/memory.md>), [security](<https://devfeed.tech/tags/security.md>)

## AI overview

This article examines the design of a safer and more efficient C string-copying function intended to preserve null termination, report truncation or overflow, minimize unnecessary memory access, support vectorization, and comply with portable standards such as ISO C or POSIX.

## Source excerpt

Like them or not, null-terminated strings are essential to C, and working with them is necessary in all but the most trivial programs. While C-style strings are a fundamental part of using the language, manipulating them is a common source of security bugs and lost performance. One of the most common operations is copying a string from one buffer to another, and there are a variety of string functions that claim to do this in C. Anecdotally, however, there is much confusion about what they actually do, and many people desire a string copying function with the following properties: