On May 6, 3:09 pm, paragon.j...@[EMAIL PROTECTED]
wrote:
> Hello all,
>
> I am trying to read a file into some allocated memory as part of a
> program and I am running into a problem. The program gets a
> segmentation fault during fread. I have previously used this code on
> 64-bit RHEL4 without any problems but I am not having this issue on 32-
> bit RHEL5. I have simplified the code to it's most basic form and I
> am still seeing the issue. Below is a full program that causes the
> error. If anybody knows what may be causing the problem, help would
> be greatly appreciated....
>
> #include <stdio.h>
> #include <fcntl.h>
>
> int main()
> {
> int data_size = 1024*1024;
> u_char *data_buf;
> FILE *data_file;
> int data_num;
>
> data_buf = (unsigned char *) valloc(data_size);
> printf("Memory allocated.\n");
> data_file = fopen("data_file","rb");
> printf("File opened.");
> data_num = fread(data_buf, sizeof(u_char), data_size, data_file);
> printf("File read.");
> return 0;
>
> }
>
> Thanks for your help!
Thank you for the help guys. I've figured it out. I feel dumb for
not checking the return values on the functions.


|