Import from coreutils.
[gnulib.git] / m4 / rmdir-errno.m4
1 #serial 7
2
3 # Copyright (C) 2000, 2001, 2005, 2006 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.
7
8 # When rmdir fails because the specified directory is not empty, it sets
9 # errno to some value, usually ENOTEMPTY.  However, on some AIX systems,
10 # ENOTEMPTY is mistakenly defined to be EEXIST.  To work around this, and
11 # in general, to avoid depending on the use of any particular symbol, this
12 # test runs a test to determine the actual numeric value.
13 AC_DEFUN([gl_FUNC_RMDIR_NOTEMPTY],
14 [dnl
15   AC_CACHE_CHECK([for rmdir-not-empty errno value],
16     gl_cv_func_rmdir_errno_not_empty,
17     [
18       # Arrange for deletion of the temporary directory this test creates.
19       ac_clean_files="$ac_clean_files confdir2"
20       mkdir confdir2; : > confdir2/file
21       AC_TRY_RUN([
22 #include <stdio.h>
23 #include <errno.h>
24         int main ()
25         {
26           FILE *s;
27           int val;
28           rmdir ("confdir2");
29           val = errno;
30           s = fopen ("confdir2/errno", "w");
31           fprintf (s, "%d\n", val);
32           return 0;
33         }
34         ],
35       gl_cv_func_rmdir_errno_not_empty=`cat confdir2/errno`,
36       gl_cv_func_rmdir_errno_not_empty='configure error in rmdir-errno.m4',
37       gl_cv_func_rmdir_errno_not_empty=ENOTEMPTY
38       )
39     ]
40   )
41
42   AC_DEFINE_UNQUOTED([RMDIR_ERRNO_NOT_EMPTY],
43     $gl_cv_func_rmdir_errno_not_empty,
44     [the value to which errno is set when rmdir fails on a nonempty directory])
45 ])