Filesize() Function
Brian K. White
bw.aljex at gmail.com
Wed May 13 11:03:04 PDT 2020
On 5/13/20 10:18 AM, Nancy Palmquist via Filepro-list wrote:
> Friends and filePro Experts,
>
> Does anyone have an idea what it means when I do the following commands?
>
> aa(8,.0)=Open([Name of file])
I can't tell what the return values mean from filesize()
We don't know what filesize() does internally. There is no such exactly
matching c function like there is for say, open(). There are a few
different common ways c programs generally get file size. Internally, fp
might be using fstat() and giving back the st_size field from the struct
returned by stat(), and the error could be an overall return value from
the stat() call, or it could be a value that stat() put in the st_size
field.
There is a c function explain_stat() exactly for this purpose, but we
can't use it because to use it, you'd have to have the fp source, and
you'd add the function immediately after the stat() call, feeding it the
same parameters. But obviously we can't do that.
Or fp could be doing open(), then seek() to end, and returning the value
from seek(), and maybe the error value is the return value from seek().
That could be looked up if we knew for sure that's what provided the value.
We COULD find out what fp is doing internally by just making a small prc
table that just does an open() and a filesize() on a file (use a unique
filename you can search for in a mass of text later), and run that prc
table in strace and/or ltrace (strace -e all -o trace.txt rreport ...)
and then search the output for the filename to get to the right area.
That would show what functions fp called in order to do the filesize().
THEN, you could look up the meanings of the error values those functions
return (actually I think they would already be decoded right in the
strace output, IE, it wouldn't just say "4" it would say "EINTR" which
means interrupted system call. Not too useful in this case, but that is
probably from stat(), and the real info is in the values stat() returned
in it's struct, and needs explain_stat() to show it.
Don't worry I'm not actually saying to bother with all that because
probably you can find out the real problem easier.
You CAN tell what the return value means from open() for sure.
So just test aa before using it.
If: aa < "0"
Then: errorbox "Failed to open \""{fn"\"\nReason:"<aa
If the open() failed, then you'll get the errorbox and a negative number.
take the negative value, ignore the negative and match the number from:
/usr/include/asm-generic/errno-base.h
and
/usr/include/asm-generic/errno.h
Or here is a more convenient table:
https://www.thegeekstuff.com/2010/10/linux-error-codes/
Hopefully, the error from open() is more meaningful than "interrupted
system call", more like
"-13" EACCES (permission denied), and then you'll have a clue to work with.
--
bkw
>
> ab(8,.0)=filesize(aa) 'should report the filesize of the opened file
> and does most of the time.
>
> But sometimes I get the value "-4" instead of a positive number of
> some kind.
>
> I expect it might be an error of some kind and if a -4 is possible,
> can I expect other negative numbers?
>
> I would appreciate any insight on this. I am kind of assuming the
> file was not created or something bad like that happened.
>
> Nancy Palmquist
>
More information about the Filepro-list
mailing list