1 # getcwd.m4 - check for working getcwd that is compatible with glibc
3 # Copyright (C) 2001, 2003-2007, 2009-2011 Free Software Foundation, Inc.
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.
8 # Written by Paul Eggert.
11 AC_DEFUN([gl_FUNC_GETCWD_NULL],
13 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
14 AC_CACHE_CHECK([whether getcwd (NULL, 0) allocates memory for result],
15 [gl_cv_func_getcwd_null],
16 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
22 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
23 /* mingw cwd does not start with '/', but getcwd does allocate.
24 However, mingw fails to honor non-zero size. */
30 char *f = getcwd (NULL, 0);
41 [gl_cv_func_getcwd_null=yes],
42 [gl_cv_func_getcwd_null=no],
45 # Guess yes on glibc systems.
46 *-gnu*) gl_cv_func_getcwd_null="guessing yes";;
47 # Guess yes on Cygwin.
48 cygwin*) gl_cv_func_getcwd_null="guessing yes";;
49 # If we don't know, assume the worst.
50 *) gl_cv_func_getcwd_null="guessing no";;
55 AC_DEFUN([gl_FUNC_GETCWD_SIGNATURE],
57 AC_CACHE_CHECK([for getcwd with POSIX signature],
58 [gl_cv_func_getcwd_posix_signature],
61 [[#include <unistd.h>]],
66 char *getcwd (char *, size_t);
69 [gl_cv_func_getcwd_posix_signature=yes],
70 [gl_cv_func_getcwd_posix_signature=no])
74 dnl Guarantee that getcwd will malloc with a NULL first argument. Assumes
75 dnl that either the system getcwd is robust, or that calling code is okay
76 dnl with spurious failures when run from a directory with an absolute name
77 dnl larger than 4k bytes.
79 dnl Assumes that getcwd exists; if you are worried about obsolete
80 dnl platforms that lacked getcwd(), then you need to use the GPL module.
81 AC_DEFUN([gl_FUNC_GETCWD_LGPL],
83 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
84 AC_REQUIRE([gl_FUNC_GETCWD_NULL])
85 AC_REQUIRE([gl_FUNC_GETCWD_SIGNATURE])
87 case $gl_cv_func_getcwd_null,$gl_cv_func_getcwd_posix_signature in
90 dnl Minimal replacement lib/getcwd-lgpl.c.
96 dnl Check for all known getcwd bugs; useful for a program likely to be
97 dnl executed from an arbitrary location.
98 AC_DEFUN([gl_FUNC_GETCWD],
100 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
101 AC_REQUIRE([gl_FUNC_GETCWD_NULL])
102 AC_REQUIRE([gl_FUNC_GETCWD_SIGNATURE])
103 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
106 case $gl_cv_func_getcwd_null,$host_os in
108 gl_cv_func_getcwd_path_max=yes;;
110 gl_FUNC_GETCWD_PATH_MAX
111 gl_FUNC_GETCWD_ABORT_BUG([gl_abort_bug=yes]);;
114 case $gl_cv_func_getcwd_null,$gl_cv_func_getcwd_posix_signature$gl_cv_func_getcwd_path_max,$gl_abort_bug in
117 dnl Full replacement lib/getcwd.c, overrides LGPL replacement.
122 # Prerequisites of lib/getcwd.c, when full replacement is in effect.
123 AC_DEFUN([gl_PREREQ_GETCWD],
125 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
126 AC_REQUIRE([gl_CHECK_TYPE_STRUCT_DIRENT_D_INO])