Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
strdup + fread = fail?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Richard Tobin, post: 2864345"] fread() doesn't nul-terminate the data it reads, so you shouldn't call strdup() on it. If the data contains nul characters, you will only copy up to the first one; if it doesn't you will run off the end. For binary data you should use the known length (buf.st_size, assuming the fread() succeeds, which you should check) to allocate space for the copy, and then use memcpy(). -- Richard [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
strdup + fread = fail?
Top