linkat: new module
[gnulib.git] / m4 / unlink.m4
index 95c0810..626c3ad 100644 (file)
@@ -1,32 +1,27 @@
-#serial 4
+# unlink.m4 serial 1
+dnl Copyright (C) 2009 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
 
-dnl From J. David Anglin.
-
-dnl HPUX and other systems can't unlink shared text that is being executed.
-
-AC_DEFUN(jm_FUNC_UNLINK_BUSY_TEXT,
-[dnl
-  AC_CACHE_CHECK([whether a program can unlink itself],
-    jm_cv_func_unlink_busy_text,
-    [
-      AC_TRY_RUN([
-        main (argc, argv)
-          int argc;
-          char **argv;
-        {
-          if (!argc)
-            exit (-1);
-          exit (unlink (argv[0]));
-        }
-       ],
-      jm_cv_func_unlink_busy_text=yes,
-      jm_cv_func_unlink_busy_text=no,
-      jm_cv_func_unlink_busy_text=no
-      )
-    ]
-  )
-
-  if test $jm_cv_func_unlink_busy_text = no; then
-    INSTALL=$ac_install_sh
+AC_DEFUN([gl_FUNC_UNLINK],
+[
+  AC_REQUIRE([gl_AC_DOS])
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  dnl Detect Solaris 9 bug.
+  AC_CACHE_CHECK([whether unlink honors trailing slashes],
+    [gl_cv_func_unlink_works],
+    [touch conftest.file
+     AC_RUN_IFELSE(
+       [AC_LANG_PROGRAM(
+         [[#include <stdio.h>
+           #include <errno.h>
+]], [[return !unlink ("conftest.file/") || errno != ENOTDIR;]])],
+      [gl_cv_func_unlink_works=yes], [gl_cv_func_unlink_works=no],
+      [gl_cv_func_unlink_works="guessing no"])
+     rm -f conftest.file])
+  if test x"$gl_cv_func_unlink_works" != xyes; then
+    REPLACE_UNLINK=1
+    AC_LIBOBJ([unlink])
   fi
 ])