[GRASS5] Portability issues

Glynn Clements glynn.clements at virgin.net
Fri Oct 4 08:11:21 EDT 2002


Eric G. Miller wrote:

> > Some of these could simply be replaced with ANSI functions, while
> > others suggest that new functions should be added to e.g. libgis to
> > improve portability.
> > 
> > Some comments on specific functions:
> > 
> > + open close creat read write lseek truncate
> > 
> > Many of these could probably be replaced with the ANSI stdio
> > equivalents.
> 
> libgis uses file descriptors heavily, so POSIX functions are
> useful/mandatory. ANSI doesn't have a truncate() or ftruncate().

I'm not really concerned about libgis. Implementing multiple versions
of core functions is feasible; doing the same for all the individual
modules isn't.

truncate() is only used by d.labels, and its use there appears to be
unnecessary.

Basically, I'm suggesting that modules which simply need to read/write
files should prefer the ANSI stdio mechansims over the POSIX ones.

> > + mkdir chdir opendir closedir readdir
> > 
> > The ANSI libraries don't deal with directories. However, any system on
> > which GRASS runs will have equivalent functionality; we just need to
> > provide a portable interface.
> 
> Not a bad idea to have system interface (though Winders supposedly is
> supporting POSIX these days...).

NT has a POSIX subsystem, but it's "bare" POSIX.1 (e.g. no sockets),
and it's completely detached from the rest of Windows (i.e. a POSIX
program can't use the Win32 API).

> > + snprintf
> > 
> > C9X defines this, so in a couple of decades it won't be a problem. For
> > now, a wide variety of solutions are possible, all with their own
> > advantages and disadvantages.
> 
> Couple of *decades*! ;^) I think mostly we'd rather have an asprintf()
> available...

Yeah, but asprintf() isn't standard either, and requires non-trivial
code changes.

This simplest workaround is an snprintf() look-alike which simply
ignores the length option, and passes the rest to vsprintf(). In most
of the cases which I examined, the caller doesn't actually check
whether the buffer was too short, so you would probably still get
erroneous behaviour.

> > + sigaction sigemptyset
> > 
> > Only used by r.mapcalc. signal() can be used instead, although
> > signal() has problems of its own (BSD-vs-SysV signal semantics,
> > general lack of flexibility).
> 
> sigaction is POSIX, so should be fairly portable by now.  ANSI only
> minimally describes signals, hence the BSD vs. SysV, etc...

r.mapcalc only actually uses it to set a flag if SIGFPE occurs, so
signal() would probably suffice here.

> > + putenv
> > 
> > Used by XDRIVER; it probably doesn't need to be portable.
> 
> Why not setenv()?

setenv() is BSD 4.3. putenv() is POSIX, BSD 4.3, SVID 3. Neither are
ANSI. The C99 description of getenv() says:

	The set of environment names and the method for altering the
	environment list are implementation-defined.

> > + gethostname
> > 
> > Used by G__machine_name(), which is sensible enough. Presumably
> > equivalent functionality is available on any networked system (and, on
> > non-networked systems, you don't really need a per-machine
> > identifier).
> 
> That's mostly for the tmpfile thing these days, no?  Probably could
> think about getting rid of it if the whole mapset permissions thing
> is redone.. (Hmm, there's also that email interface...).

The only caller of G__machine_name() is G__temp_element(), which is
presumably to handle the case where GISDBASE is on a network share.

-- 
Glynn Clements <glynn.clements at virgin.net>




More information about the grass-dev mailing list