getcwd.m4 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # getcwd.m4 - check whether getcwd (NULL, 0) allocates memory for result
  2. # Copyright 2001 Free Software Foundation, Inc.
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2, or (at your option)
  6. # any later version.
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program; if not, write to the Free Software Foundation,
  13. # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  14. # Written by Paul Eggert.
  15. AC_DEFUN([AC_FUNC_GETCWD_NULL],
  16. [AC_CHECK_HEADERS(stdlib.h unistd.h)
  17. AC_CACHE_CHECK([whether getcwd (NULL, 0) allocates memory for result],
  18. [ac_cv_func_getcwd_null],
  19. [AC_TRY_RUN(
  20. [
  21. # ifdef HAVE_STDLIB_H
  22. # include <stdlib.h>
  23. # endif
  24. # ifdef HAVE_UNISTD_H
  25. # include <unistd.h>
  26. # endif
  27. # ifndef getcwd
  28. char *getcwd ();
  29. # endif
  30. int
  31. main ()
  32. {
  33. if (chdir ("/") != 0)
  34. exit (1);
  35. else
  36. {
  37. char *f = getcwd (NULL, 0);
  38. exit (! (f && f[0] == '/' && !f[1]));
  39. }
  40. }],
  41. [ac_cv_func_getcwd_null=yes],
  42. [ac_cv_func_getcwd_null=no],
  43. [ac_cv_func_getcwd_null=no])])
  44. if test $ac_cv_func_getcwd_null = yes; then
  45. AC_DEFINE(HAVE_GETCWD_NULL, 1,
  46. [Define if getcwd (NULL, 0) allocates memory for result.])
  47. fi])