Hi russ
I was asking to check the errno after the ftell() call. Something like below.
#include <errno.h>
{
....
FILE *fp;
int ret_value;
/* do your stuff on fp */
extern int errno;
ret_value = ftell(fp);
if ( ret_value < 0 )
{
printf("%s\n", strerror(errno));
}
else
{
printf("%s\n", "Everything is fine"

;
}
}
I had meant the errno that is set after call to ftell(). If it is 0 then ftell() succeeds
and if it is one of the values as below , ftell() failed with the reason against the number.
Actually Visual C++ 5.0 gives pretty specific error numbers for such
a failed function on a file descriptor. Here are some of them.
EBADF - Bad file number. There are two possible causes:
1) The specified file handle is not a valid file-handle value or does not refer to an open file.
2) An attempt was made to write to a file or device opened for read-only access
EEXIST - Files exist. An attempt has been made to create a file that already exists.
For example, the _O_CREAT and _O_EXCL flags are specified in an _open call, but
the named file already exists.
EMFILE - Too many open files. No more file handles are available, so no more files can be opened.
If you are checking these error numbers after a call to fopen(), then they give a wide range
of things that could have gone wrong. But if you get say EBADF after calling ftell() on a file
that you were writing to sometime back, then obviously the reason is the (1) under EBADF.
What I am trying to tell is that though this is not a very good way of doing it, it does
give you an idea of what went wrong.
I think the idea of writing your own fclose() makes sense.
You could write your own ftell() also making use of the fact that fp is NULL..
extern void myfclose(FILE *fp)
{
fclose(fp);
fp=NULL;
}
extern int myftell(FILE *fp)
{
if (fp == NULL)
return 0;
else
return 1;
}
abp