filelength call

Hello. I am migrating from DOS, where I use a ‘long filelength(int handle)’
type call to read the size of a file before I attempt to read it into a
buffer. Borland says portability is dos, win32, unix … but it doesn’t seem
to work under qnx. At least my grep of the /usr/include and
/usr/include/sys didn’t turn up anything. Anyone know the equivalent call or
how to do this under qnx?

Thanks,
Ed
ps: have mercy on a newbie, if this turns out to be a dumb question …

Ed Clark <edclark1@mindspring.com> wrote:

Hello. I am migrating from DOS, where I use a ‘long filelength(int handle)’
type call to read the size of a file before I attempt to read it into a
buffer. Borland says portability is dos, win32, unix … but it doesn’t seem
to work under qnx. At least my grep of the /usr/include and
/usr/include/sys didn’t turn up anything. Anyone know the equivalent call or
how to do this under qnx?

Thanks,
Ed
ps: have mercy on a newbie, if this turns out to be a dumb question …

Not a dumb question; but easy to answer:

use “lseek”:

fd = open (“filename”, …
size = lseek (fd, SEEK_END, 0);

and now “size” has the size of the file…

Cheers,
-RK


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Consulting and Training at www.parse.com
Email my initials at parse dot com.

Robert Krten <nospam91@parse.com> wrote:

Ed Clark <> edclark1@mindspring.com> > wrote:
Hello. I am migrating from DOS, where I use a ‘long filelength(int handle)’
type call to read the size of a file before I attempt to read it into a
buffer. Borland says portability is dos, win32, unix … but it doesn’t seem
to work under qnx. At least my grep of the /usr/include and
/usr/include/sys didn’t turn up anything. Anyone know the equivalent call or
how to do this under qnx?

Thanks,
Ed
ps: have mercy on a newbie, if this turns out to be a dumb question …

Not a dumb question; but easy to answer:

use “lseek”:

fd = open (“filename”, …
size = lseek (fd, SEEK_END, 0);

and now “size” has the size of the file…

One thing to watch out for; this will seek your file to the end-of-file
position. You can do a:

currpos = lseek (fd, SEEK_CUR, 0);
size = lseek (fd, SEEK_END, 0);
lseek (fd, SEEK_SET, currpos);

If you don’t want to move the file position during your “length” operation.

Cheers,
-RK


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Consulting and Training at www.parse.com
Email my initials at parse dot com.

“Ed Clark” <edclark1@mindspring.com> wrote in message
news:a0oro0$obc$1@inn.qnx.com

Hello. I am migrating from DOS, where I use a ‘long filelength(int
handle)’
type call to read the size of a file before I attempt to read it into a
buffer. Borland says portability is dos, win32, unix … but it doesn’t
seem
to work under qnx. At least my grep of the /usr/include and
/usr/include/sys didn’t turn up anything. Anyone know the equivalent call
or
how to do this under qnx?

Thanks,
Ed
ps: have mercy on a newbie, if this turns out to be a dumb question …

Check out stat() function
http://qdn.qnx.com/support/docs/neutrino_2.11_en/lib_ref/s/stat.html

Field st_size of stat structure hold the file size in bytes

Thanks for your help. By the way our training budget for qnx consisted of
the purchase of two copies of your book.

Ed

“Robert Krten” <nospam91@parse.com> wrote in message
news:a0pvgl$hun$1@inn.qnx.com

Robert Krten <> nospam91@parse.com> > wrote:
Ed Clark <> edclark1@mindspring.com> > wrote:
Hello. I am migrating from DOS, where I use a ‘long filelength(int
handle)’
type call to read the size of a file before I attempt to read it into a
buffer. Borland says portability is dos, win32, unix … but it doesn’t
seem
to work under qnx. At least my grep of the /usr/include and
/usr/include/sys didn’t turn up anything. Anyone know the equivalent
call or
how to do this under qnx?

Thanks,
Ed
ps: have mercy on a newbie, if this turns out to be a dumb question …

Not a dumb question; but easy to answer:

use “lseek”:

fd = open (“filename”, …
size = lseek (fd, SEEK_END, 0);

and now “size” has the size of the file…

One thing to watch out for; this will seek your file to the end-of-file
position. You can do a:

currpos = lseek (fd, SEEK_CUR, 0);
size = lseek (fd, SEEK_END, 0);
lseek (fd, SEEK_SET, currpos);

If you don’t want to move the file position during your “length”
operation.

Cheers,
-RK


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Consulting and Training at
www.parse.com
Email my initials at parse dot com.

Ed Clark <edclark1@mindspring.com> wrote:

Thanks for your help. By the way our training budget for qnx consisted of
the purchase of two copies of your book.

No probs!

(Better that than no training, eh? :slight_smile:)
-RK

“Robert Krten” <> nospam91@parse.com> > wrote in message
news:a0pvgl$hun$> 1@inn.qnx.com> …
Robert Krten <> nospam91@parse.com> > wrote:
Ed Clark <> edclark1@mindspring.com> > wrote:
Hello. I am migrating from DOS, where I use a ‘long filelength(int
handle)’
type call to read the size of a file before I attempt to read it into a
buffer. Borland says portability is dos, win32, unix … but it doesn’t
seem
to work under qnx. At least my grep of the /usr/include and
/usr/include/sys didn’t turn up anything. Anyone know the equivalent
call or
how to do this under qnx?

Thanks,
Ed
ps: have mercy on a newbie, if this turns out to be a dumb question …

Not a dumb question; but easy to answer:

use “lseek”:

fd = open (“filename”, …
size = lseek (fd, SEEK_END, 0);

and now “size” has the size of the file…

One thing to watch out for; this will seek your file to the end-of-file
position. You can do a:

currpos = lseek (fd, SEEK_CUR, 0);
size = lseek (fd, SEEK_END, 0);
lseek (fd, SEEK_SET, currpos);

If you don’t want to move the file position during your “length”
operation.

Cheers,
-RK


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Consulting and Training at
www.parse.com
Email my initials at parse dot com.


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Consulting and Training at www.parse.com
Email my initials at parse dot com.

“Mario Charest” <goto@nothingness.com> wrote in message
news:a0qm7b$2da$1@inn.qnx.com

Check out stat() function
http://qdn.qnx.com/support/docs/neutrino_2.11_en/lib_ref/s/stat.html

Field st_size of stat structure hold the file size in bytes

In fact, there is an example to do exactly what Ed wanted that in the help
under fstat().

-Adam