getlogin_r.m4 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #serial 13
  2. # Copyright (C) 2005-2007, 2009-2021 Free Software Foundation, Inc.
  3. #
  4. # This file is free software; the Free Software Foundation
  5. # gives unlimited permission to copy and/or distribute it,
  6. # with or without modifications, as long as this notice is preserved.
  7. dnl From Derek Price
  8. dnl
  9. dnl Provide getlogin_r when the system lacks it.
  10. dnl
  11. AC_DEFUN([gl_FUNC_GETLOGIN_R],
  12. [
  13. AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
  14. dnl Persuade glibc <unistd.h> to declare getlogin_r().
  15. dnl Persuade Solaris <unistd.h> to provide the POSIX compliant declaration of
  16. dnl getlogin_r().
  17. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
  18. AC_CHECK_DECLS_ONCE([getlogin_r])
  19. if test $ac_cv_have_decl_getlogin_r = no; then
  20. HAVE_DECL_GETLOGIN_R=0
  21. fi
  22. AC_CHECK_FUNCS_ONCE([getlogin_r])
  23. if test $ac_cv_func_getlogin_r = no; then
  24. HAVE_GETLOGIN_R=0
  25. else
  26. HAVE_GETLOGIN_R=1
  27. dnl On Mac OS X 10.13 and OSF/1 5.1, getlogin_r returns a truncated result
  28. dnl if the buffer is not large enough.
  29. AC_REQUIRE([AC_CANONICAL_HOST])
  30. AC_CACHE_CHECK([whether getlogin_r works with small buffers],
  31. [gl_cv_func_getlogin_r_works],
  32. [
  33. dnl Initial guess, used when cross-compiling.
  34. changequote(,)dnl
  35. case "$host_os" in
  36. # Guess no on Mac OS X, OSF/1.
  37. darwin* | osf*) gl_cv_func_getlogin_r_works="guessing no" ;;
  38. # Guess yes otherwise.
  39. *) gl_cv_func_getlogin_r_works="guessing yes" ;;
  40. esac
  41. changequote([,])dnl
  42. AC_RUN_IFELSE(
  43. [AC_LANG_SOURCE([[
  44. #include <stddef.h>
  45. #include <string.h>
  46. #include <unistd.h>
  47. #if !HAVE_DECL_GETLOGIN_R
  48. extern
  49. # ifdef __cplusplus
  50. "C"
  51. # endif
  52. int getlogin_r (char *, size_t);
  53. #endif
  54. int
  55. main (void)
  56. {
  57. int result = 0;
  58. char buf[100];
  59. if (getlogin_r (buf, 0) == 0)
  60. result |= 1;
  61. if (getlogin_r (buf, 1) == 0)
  62. result |= 2;
  63. if (getlogin_r (buf, 100) == 0)
  64. {
  65. size_t n = strlen (buf);
  66. if (getlogin_r (buf, n) == 0)
  67. result |= 4;
  68. }
  69. return result;
  70. }]])],
  71. [gl_cv_func_getlogin_r_works=yes],
  72. [gl_cv_func_getlogin_r_works=no],
  73. [:])
  74. ])
  75. case "$gl_cv_func_getlogin_r_works" in
  76. *yes) ;;
  77. *) REPLACE_GETLOGIN_R=1 ;;
  78. esac
  79. fi
  80. ])
  81. AC_DEFUN([gl_PREREQ_GETLOGIN_R],
  82. [
  83. AC_CHECK_DECLS_ONCE([getlogin])
  84. ])