dnl CF_POSIX_SAVED_IDS version: 12 updated: 2023/12/03 19:55:51
dnl ------------------
dnl
dnl Check first if saved-ids are always supported.  Some systems
dnl may require runtime checks.
AC_DEFUN([CF_POSIX_SAVED_IDS],
[
AC_CHECK_HEADERS( \
sys/param.h \
)

AC_CACHE_CHECK(if POSIX saved-ids are supported,cf_cv_posix_saved_ids,[
AC_TRY_LINK(
[
#include <unistd.h>
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>		/* this may define "BSD" */
#endif
],[
#if defined(_POSIX_SAVED_IDS) && (_POSIX_SAVED_IDS > 0)
	int (*my_seteuid)(uid_t) = seteuid;
	int x = my_seteuid(geteuid());
	(void)x;
#elif defined(BSD) && (BSD >= 199103)
/* The BSD's may implement the runtime check - and it fails.
 * However, saved-ids work almost like POSIX (close enough for most uses).
 */
#else
#error no saved-ids found
#endif
],[cf_cv_posix_saved_ids=yes
],[
AC_TRY_RUN([
$ac_includes_default

int main(void)
{
	void *p = (void *) seteuid;
	long code = sysconf(_SC_SAVED_IDS);
	(void)p;
	${cf_cv_main_return:-return}  ((code > 0) ? 0 : 1);
}],
	cf_cv_posix_saved_ids=yes,
	cf_cv_posix_saved_ids=no,
	cf_cv_posix_saved_ids=unknown)
])
])

test "$cf_cv_posix_saved_ids" = yes && AC_DEFINE(HAVE_POSIX_SAVED_IDS,1,[Define to 1 if POSIX saved-ids are supported])
])
