[GRASS-dev] diglib test.c fails on 64bit win

Glynn Clements glynn at gclements.plus.com
Fri May 21 11:45:12 EDT 2010


Markus Metz wrote:

> >> Leave all that to a new "off_t G_file_size()" ?
> >
> > That's fine if the file is open (or would be opened before the size is
> > required). There may be cases where code needs the size of a file but
> > has reasons to avoid opening it.
> 
> Hm, either have "off_t G_file_size(FILE *fp, char *path)" that uses
> G_fseek/G_ftell if fp != NULL, otherwise stat(), needs to be called
> correctly, or have two functions like "off_t G_file_size_fp(FILE *fp)"
> and "off_t G_file_size_name(char *path)" ? And you thought about a
> version using file descriptor, something like "off_t
> G_file_size_fd(int fd)".

With a descriptor, there are two possibilities: lseek(SEEK_END) and
fstat().

There are situations where it matters which is used, but I don't think
that any of those apply to GRASS.

I'd suggest providing:

	G_file_size_fp(FILE *fp)	=> fseek() + ftell()
	G_file_size_fd(int fd)		=> lseek()

Anything which wants the size according to stat() can use G_stat().

stat()ing an open file has other problems besides the Windows size
issue, e.g. the file being stat()'d may not be the same as the one
which was open()ed (Unix allows files to be renamed or deleted while
open).

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list