Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: safe strcpy()?

From: Ben Pfaff <blp(at)cs.stanford.edu>
Date: Wed Jan 29 2003 - 18:40:16 EST

"Michael Howard" <mikehow@microsoft.com> writes:

> The point I'm making is people seem to think they can write crap code,

The usual reason cited not to use strncpy() is that it doesn't necessarily null-terminate its output buffer. But there's at least one other reason: using strncpy() into a large buffer can be very inefficient. strncpy() always writes to every byte in the destination buffer, which can waste a lot of time if the destination buffer is much longer than the source string.

As a result, strncpy() is hardly ever the right function to use. strlcpy() from OpenBSD is usually a better choice.

-- 
"If a person keeps faithfully busy each hour of the working day, he
 can count on waking up some morning to find himself one of the
 competent ones of his generation."
--William James
Received on Wed Jan 29 18:56:32 2003

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 14:02:46 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library