Sponsored Content
Top Forums Programming Using fread if the buffer size is not known Post 30513 by Perderabo on Wednesday 23rd of October 2002 09:59:33 AM
Old 10-23-2002
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.
 

9 More Discussions You Might Find Interesting

1. AIX

Pipe Buffer Size

Hi:- One of our users is getting an error: "There is no process to read data written to a pipe.” I am trying to find out what the pipe buffer size is currently set to. How do I go about this? Thanks, (0 Replies)
Discussion started by: janet
0 Replies

2. Red Hat

buffer cache size

hi everyone, can any one help change the buffer cache size in redhat and suse?? this error i got when i installed oracle 10g and it went well and when i try to mount the database using startup cmd it says too many buffer cache parameters (error code : ora-1034) thnq in advance (0 Replies)
Discussion started by: gsr_kashyap
0 Replies

3. UNIX for Advanced & Expert Users

How to increase the buffer size in Unix

When I checked with top command, I found tht my buffers are always 137M, which means that they are sort of overloaded. My Inactive memory is 520M. Is it possible to increaase the buffer size and what would be the command for that? (0 Replies)
Discussion started by: ziabegg
0 Replies

4. UNIX for Dummies Questions & Answers

How to increase buffer size in Unix

The "top" command shows that my buffer size is always at 137M, which I think has reached to the maximum. However, Ido have lots of Inative memory? Is it possible to increae the buffer size? and what is the command for that? Further, this is the buffer for writing to the hard disk? (3 Replies)
Discussion started by: ziabegg
3 Replies

5. Shell Programming and Scripting

Expect buffer size increase, please help

Hi Group, I am struggling to increase buffer size of expect, sometimes after increasing the buffer size, expect captures all my expected output, sometimes not, :-( I tried match_max 700000 set expect_out(buffer) {} Could anybody guide me for any solution. HTH,... (1 Reply)
Discussion started by: jaduks
1 Replies

6. Programming

erase fread 's internal buffer ?

When fread is used twice, the second time it seems to overwrite the first time's output. Is there any way to clear fread's internal buffer after each use ? char *FILEREAD(const char *FILENAME) { static char READBUFFER = ""; READBUFFER = '\0'; // try to solve the problem but this will not... (2 Replies)
Discussion started by: limmer
2 Replies

7. Shell Programming and Scripting

sftp Invalid buffer size

For the above one I am getting an error like Invalid buffer size ...Could some one help (3 Replies)
Discussion started by: infernalhell
3 Replies

8. UNIX for Dummies Questions & Answers

Decrease buffer size

Hi, I am using the below command to get the output in a file called "Logs.txt" tail -f filename | egrep -i "cpu | hung " >> Logs.txt The problem is the Logs.txt file gets updated only after the buffer is 8Kb, but i want to update the file immediately and not wait for the buffer to get 8kb. Is... (8 Replies)
Discussion started by: @bhi
8 Replies

9. Programming

[c] How to calculate size of the file from size of the buffer?

Hi, Can I find size of the file from size of the buffer written? nbECRITS = fwrite(strstr(data->buffer, ";") + 1, sizeof(char), (data->buffsize) - LEN_NOM_FIC, fic_sortie); Thank You :) (1 Reply)
Discussion started by: ezee
1 Replies
fread(3S)																 fread(3S)

NAME
fread(), fwrite() - buffered binary input/output to a stream file SYNOPSIS
Obsolescent Interfaces DESCRIPTION
copies, into an array pointed to by ptr, up to nitems items of data from the named input stream, where an item of data is a sequence of bytes (not necessarily terminated by a null byte) of length size. stops appending bytes if an end-of-file or error condition is encoun- tered while reading stream, or if nitems items have been read. leaves the file pointer in stream, if defined, pointing to the byte follow- ing the last byte read if there is one. does not change the contents of stream. appends at most nitems items of data from the array pointed to by ptr to the named output stream. stops appending when it has appended nitems items of data or if an error condition is encountered on stream. does not change the contents of the array pointed to by ptr. The argument size is typically where the pseudo-function specifies the length of an item pointed to by ptr. Obsolescent Interfaces and buffered binary input/output to a stream file. APPLICATION USAGE
After or is applied to a stream, the stream becomes byte-oriented (see orientation(5)). RETURN VALUE
and return the number of items read or written. If size or nitems is 0, no characters are read or written and 0 is returned. The value returned will be less than nitems only if a read error or end-of-file is encountered. When the file corresponding to an open stream gets extended after the end-of-file is reached, any subsequent calls to will succeed and the end-of-file indicator will remain set. However, in the UNIX2003 standards environment (see standards(5)), this function will return zero and the end-of-file indicator will remain set. The or functions must be used to distinguish between an error condition and an end-of-file condition. ERRORS
Refer to getc(3S) for a description of errors returned by Refer to putc(3S) for a description of errors returned by WARNINGS
and are obsolescent interfaces supported only for compatibility with existing DCE applications. New multithreaded applications should use and SEE ALSO
read(2), write(2), fopen(3S), flockfile(3S), getc(3S), gets(3S), printf(3S), putc(3S), puts(3S), scanf(3S), orientation(5), standards(5), thread_safety(5), glossary(9). STANDARDS CONFORMANCE
fread(3S)
All times are GMT -4. The time now is 11:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy