[GRASS-dev] diglib test.c fails on 64bit win
markus.metz.giswork at googlemail.com
Thu May 20 04:24:32 EDT 2010
Glynn Clements wrote:
> Markus Metz wrote:
>> 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.
Sounds good, but must work independent of whether the file is open.
> 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.
That could go to config.h.in as well I guess, have all the mingw stuff
together in one place.
>> > 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).
Although the vector libs use struct stat, the timestamp test has been
disabled some years ago. The message for r42320 was copied verbatim
from a comment in Vlib/open.c. AFAICT, the vector libs use stat() to
either check if a file exists or to get the file size, stat() can here
easily be eliminated.
At least clean_temp, d.font, g.mkfontcap, g.access need stat(), no way
to replace that with a more portable version to get time and/or mode?
>> 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.
Leave all that to a new "off_t G_file_size()" ?
More information about the grass-dev