I am thinking about some netapi32 improvements where I'd need to call the functions of the getpw/getgr family: getpwnam(), getpwent(), getgrent(), etc.
Configure checks for the "pwd.h" header and getpwuid(). Must I add more checks for all the functions I use, or is it ok to assume that getpwuid() presence implies getpwnam() presence?
Good question. I'm don't think we have any policy concerning this. Perhaps we should have.
One thing that you shouldn't assume is for example that if a function exists its reentrant variant exists as well.
For example that fact getpwnam exists doesn't imply that getpwnam_r exists. And yes, you really should use the reentrent variant if present as well as having an alternative implementation if not.
As to the implict existance question: I'm not sure. First of all, to answer the related question: Should you have a alternative implementation for defined(HAVE_GETPWUID) && !defined(HAVE_GETPWNAM)?
IMHO the answer is no. It is not worth the effort to support hypotetical platforms unless we can verify the existance of one.
To return to the original question: I suggest that we should detect the presence or absence of ALL function we use that is verified not to exist on some platform and have for example code like
#if defined(HAVE_GETPWUID) || defined(HAVE_GETPWNAM) || defined(HAVE_GETPWENT) # if (defined(HAVE_GETPWUID) + defined(HAVE_GETPWNAM) + defined(HAVE_GETPWENT)) == 3 # define __HAVE_GETPW # else # error All or none of the functions getpwuid, getpwnam and getpwent are assumed to exist # endif #endif
in order to formalize the assumptions and generate a common define to use in the code.
Comments? Suggestions?
Am Die, 2002-11-19 um 15.17 schrieb Patrik Stridvall:
One thing that you shouldn't assume is for example that if a function exists its reentrant variant exists as well.
Sure, got that.
And yes, you really should use the reentrent variant if present as well as having an alternative implementation if not.
Hmm - really really always? This generates messy code, and a lot of effort for very rare cases.
I think we need a compromise, something in the line of either
- a) use non-reentrant functions, protecting them with a critical section (IMO ok for rarely called functions) or - b) use only reentrant and treat the case where these aren't available like the case where the respective functions aren't available at all.
Of course b) would only be viable if a sufficiently large portion of systems that support the non-reentrant variant support the reentrant one as well. I have no idea whether that's the case for the getpwXYZ functions.
As to the implict existance question: I'm not sure. First of all, to answer the related question: Should you have a alternative implementation for defined(HAVE_GETPWUID) && !defined(HAVE_GETPWNAM)?
IMHO the answer is no. It is not worth the effort to support hypotetical platforms unless we can verify the existance of one.
Very true. Perhaps the practical way would be to assume HAVE_GETPWUID == HAVE_GETPWNAM and see whether someone with a really strange platform complains (but see below).
I suggest that we should detect the presence or absence of ALL function we use that is verified not to exist on some platform and have for example code like
#if defined(HAVE_GETPWUID) || defined(HAVE_GETPWNAM) || defined(HAVE_GETPWENT) # if (defined(HAVE_GETPWUID) + defined(HAVE_GETPWNAM) + defined(HAVE_GETPWENT)) == 3 # define __HAVE_GETPW # else # error All or none of the functions getpwuid, getpwnam and getpwent are assumed to exist # endif #endif
in order to formalize the assumptions and generate a common define to use in the code.
Well I'd say that for a start we could simply do something like
/* CAUTION: If there turns out to be some insane platform that has * getpwuid() but not getpwnam() and getpwent(), this must be * improved. */ #define __HAVE_GETPW HAVE_GETPWUID
This would keep bloat out of configure in the first place, while providing a generic __HAVE_GETPW macro for possible later use.
Martin
Martin Wilck Martin.Wilck@fujitsu-siemens.com writes:
Very true. Perhaps the practical way would be to assume HAVE_GETPWUID == HAVE_GETPWNAM and see whether someone with a really strange platform complains (but see below).
There's no reason to do that, it's trivial to check for both. If you use getpwnam() check for HAVE_GETPWNAM, if you use getpwuid() check for HAVE_GETPWUID. Simple, logical, and works even on strange platforms.