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

Glynn Clements glynn at gclements.plus.com
Wed May 19 11:00:59 EDT 2010

Markus Metz wrote:

> > If you redirect stat() to stat64(), you also need to redirect
> > "struct stat" to "struct __stat64". But I'm not sure how to go about
> > that.
> I was looking around a bit in the Linux system headers but could not
> find anything. Either redirecting stat() to stat64() seems to work out
> of the box or an explicit stat64() expects struct stat64.

In bits/stat.h, "struct stat" has several fields conditionalised upon
__USE_FILE_OFFSET64. If this is set, "struct stat" ends up being
identical to "struct stat64".

> Alternatively, I found 26 files in trunk using struct stat. All these
> would need to be modified by hand...

I would guess that many of them only use it for the st_size field. In
which case, adding "off_t G_file_size(const char *filename)" would
reduce the number of call sites.

Other than that, adding e.g.:

#if defined(__MINGW32__) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS==64
typedef struct _stati64 STRUCT_STAT;
typedef struct stat STRUCT_STAT;

would be perferable to adding a similar conditional to individual
source files.

> > Also, there are two 64-bit stat interfaces, stati64() and
> > "struct _stati64", and stat64() and "struct __stat64". AFAICT, the
> > latter requires MSVCRT >= 6.1 (and uses __time64_t instead of time_t
> > for the timestamps).
> At first glance it seems that the timestamp is usually not used in
> grass, only file size is used.

Vect_coor_info() (lib/vector/Vlib/open.c) and clean_temp use st_mtime,
d.font, g.mkfontcap, g.access use st_mode. A few files use stat()
simply to determine whether the file exists (access() is preferable
for that case).

> In these cases, stat() could be
> replaced in trunk with

> curr_pos = G_ftell(fp)
> G_fseek(fp, 0, SEEK_END)
> filesize = G_ftell(fp)
> G_fseek(fp, curr_pos, SEEK_SET)
> something like that is done e.g. in lib/vector/Vlib/open.c (all branches)

That's an option if the file is already open (and has the advantage
that it works with open files on Windows, which stat() doesn't; see
#1006). I'd be inclined to add a version using a file descriptor.

Glynn Clements <glynn at gclements.plus.com>

More information about the grass-dev mailing list