[GRASS-dev] r.viewshed fails on large raster: temp file already exists
Glynn Clements
glynn at gclements.plus.com
Fri Jan 17 11:55:06 PST 2014
Markus Neteler wrote:
> could anyone please implement G_mktemp() following the suggestions in
> the ticket (there is a link to a gfortran patch included which might
> be just "perfect":
I've added lib/gis/mkstemp.c, which needs testing and feedback.
G_mktemp() just generates the filename; as such it is prone to race
conditions (some other process may create that file after G_mktemp()
returns).
G_mkstemp() opens the file and returns a descriptor. G_mkstemp_fp()
opens the file and returns a FILE*.
The last two take the arguments "flags" and "mode". "flags" should be
O_WRONLY or O_RDWR, plus any other desired flags (e.g. O_APPEND).
"mode" is the file mode (0666 would be typical).
None of the functions use the PID, although the caller can do so.
In theory, up to 26^5 (= ~12 million) filenames will be attempted
until it finds one which doesn't exist.
In retrospect, it should probably use the last 5 Xs rather than the
first, as you may not be able to control the names of the leading
directories. Or the first 5 Xs after the last / or \. Or something.
But I'll wait to see what other comments are made before changing
anything.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list