bad file pointer from fopen

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: lynn tilby
Date:  
Subject: bad file pointer from fopen
I am receiving a bad file pointer from fopen.

The permissions on the foo_data (input) file are 777,
owner is the person executing the compiled code, the code is
being executed in the same dir as the foo_data file.

The interesting thing is that fopen is NOT returning a NULL
file pointer. The program continues on and gives the message
of successfully opening foo_data. In the real (non-example)
code the prog eventually core dumps on the fread.

gcc version is:
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)

Here is the sample code:
#include <stdio.h>
FILE *in_ptr, *fopen();
main()
{
  if((in_ptr = fopen ( "./foo_data" , "r")) == NULL)
  {
    printf("\nfopen failed on foo_data\n\n");
    exit(1);
  }
  printf("\nfopen successful on foo_data\n\n");
}


Here is the xxgdb output:
Breakpoint 1, 0x804838c in fopen ()
(xxgdb) step
Single stepping until exit from function fopen,
which has no line number information.
_IO_new_fopen (filename=0x8048522 "./foo_data", mode=0x8048520 "r") at
iofopen.c:42
42    iofopen.c: No such file or directory.
(xxgdb)


ANY THOUGHTS??????

Thanks for you response!
Lynn