lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

The Lua IO library src/lib/liolib.c has support for pipes using popen
and pclose, which according to the config file is enabled by default on
POSIX systems.  The mechanism that is used for inclusion of popen/pclose
(line 39), is to check if the _POSIX_C_SOURCE variable is defined and it
is equal or greater than 2.  If these conditions hold true, the USE_OPEN
variable is defined.  Unfortunately, this mechanism does not work in
many POSIX systems.

According to the IEEE Std 1003.1-2001 (POSIX.1-2001), as well as
previous revisions of the standard, the _POSIX_C_SOURCE macro is used to
allow an application to inform the system of the revision of the POSIX
standard to which it conforms.  The _POSIX_C_SOURCE variable is by
default undefined in POSIX compliant systems, thus popen/pclose support
is never build in those systems.

The POSIX standard defines that systems that conform to a specific
version of POSIX, shall set the symbolic constant _POSIX_VERSION (eg.
199309L, 200112L).  Applications that want to test which version of
POSIX is supported by the system libraries (or if POSIX support is
present at all), should do it by checking the _POSIX_VERSION constant.
Also, the _POSIX_VERSION constant is defined in unistd.h in any POSIX
system.

Specifically, in case of the popen(3) and pclose(3) C library functions,
the _POSIX_C_VERSION macro should be set to 2 before any #include of a
system header file (or maybe during compilation, using gcc's -D
operator), and the _POSIX_VERSION constant should be checked to be equal
or greater than 199209L, for example:

	#include <unistd.h>

	...
	
	#ifdef _POSIX_VERSION
	#if _POSIX_VERSION >= 199209
	#define USE_POPEN	1

The same problem exists in src/lua/lua.c (line 32) where the
_POSIX_C_SOURCE constant is tested in order to find out if unistd.h can
be included.  The _POSIX_VERSION should be tested instead, but of course
this cannot be done without first including unistd.h.

Maybe a Makefile (ie. config) variable to manually define whether the
system is POSIX or not, would solve this...