There are many, many discussions on this topic. The usual suspects, such as strncpy, strlcpy and everything that reappears here, I'm sure. Just enter "strcpy" in the search field and read some longer threads to get an overview.
My advice: whatever your final choice, itβs nice to follow the DRY principle and continue to do so, as in your my_strcpy () example. Don't make raw calls all over your code, use wrappers and centralize them in your own string processing library. This will reduce the overall code (template), and you have one central place to make changes if you change your mind later.
Of course, this opens up some other banks of worms, especially for beginners: responsibility for memory processing and interface design. And the topic itself, and 5 people will give you 10 suggestions on how to do this. The central library, as a rule, has a pleasant effect that it provides a decision that you will follow throughout your code base, instead of using method a in module A and method b in module B, causing problems when trying to connect A to B. .
Secure
source share