The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to increase buffer size in Unix ziabegg UNIX for Dummies Questions & Answers 3 01-05-2007 12:17 PM
buffer cache size gsr_kashyap Linux 0 09-06-2006 10:34 PM
Pipe Buffer Size janet AIX 0 08-29-2006 04:30 AM
What is my UDP send/recieve buffer size nhatch UNIX for Dummies Questions & Answers 3 01-26-2005 02:52 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-23-2002
Registered User
 

Join Date: Oct 2002
Posts: 1
Using fread if the buffer size is not known

Hi...

I am trying to read a binary data that have different types of messages of different lengths. I am using fread() but this functions needs the size and count to read the buffer from the file. I think this may cause that the buffer overlaps other messages.

Is there an alternative to read from a binary file without specifying the length?
Reply With Quote
Forum Sponsor
  #2  
Old 10-23-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,654
fread will read data and place it into arrays that you allocate. The size and nitems tell fread how much space you allocated for it to work with. Without them, the data might overflow your buffer and clobber other data. This is the "buffer overflow" bug that hackers love to see in a program.

Yes, you can use gets(). There is no way to specify a length to gets. If it overflows your buffer, tough. But writing gets() the way it is was a big mistake. And if you use it, you too are making a big mistake.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 01:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0