Assuming that I have opened a file in assembly and have the file handle for that file in register eax. How would I go about getting the size of the file so I can allocate enough buffer space for it?
I researched another discussion here that suggested using the sys_fstat(28)
system call to get the file stats but couldn't implement it...
#My attempt at getting the file size
_test: movl filehandle, %ebx #move filehandle (file descriptor) into ebx
movl $28, %eax #fstat syscall
int $0x80 # always end up with -14 in here not sure why
My solution -- Just use .lcomm to create locations for all the named variables
Here is how is implemented in FreshLib. It is a wrapper in order to provide portability. You can simplify it of course (see below).
The minimal version can look this way (much less readable and not thread safe):