Mercurial > hg > octave-lyh > gnulib-hg
changeset 5852:995d030c6a1f
New unlinkdir module.
* MODULES.html.sh (File system functions): Add unlinkdir.
* lib/unlinkdir.c, lib/unlinkdir.h, m4/unlinkdir.m4, modules/unlinkdir:
New file.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sun, 15 May 2005 06:11:32 +0000 |
parents | d39411e1c5e6 |
children | e9b4b8791acd |
files | ChangeLog MODULES.html MODULES.html.sh lib/ChangeLog lib/unlinkdir.c lib/unlinkdir.h m4/ChangeLog m4/unlinkdir.m4 modules/unlinkdir |
diffstat | 9 files changed, 179 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ 2005-05-14 Paul Eggert <eggert@cs.ucla.edu> + Sync from coreutils. + * modules/unlinkdir: New file. * modules/yesno (Depends-on): Add getline. + * MODULES.html.sh (File system functions): Add unlinkdir. 2005-05-13 Paul Eggert <eggert@cs.ucla.edu>
--- a/MODULES.html +++ b/MODULES.html @@ -2,7 +2,7 @@ <HTML> <HEAD> <TITLE>Gnulib Module List</TITLE> - <META NAME="keywords" CONTENT="acl, alloca, alloca-opt, allocsa, argmatch, argp, argz, assert, atexit, backupfile, base64, bcopy, binary-io, byteswap, c-bs-a, c-ctype, c-stack, c-strtod, c-strtold, calloc, canon-host, canonicalize, chdir-long, chown, classpath, cloexec, closeout, copy-file, cycle-check, diacrit, dirfd, dirname, dummy, dup2, eealloc, error, euidaccess, exclude, execute, exit, exitfail, extensions, fatal-signal, file-type, fileblocks, filemode, findprog, fnmatch, fnmatch-gnu, fnmatch-posix, fpending, free, fsusage, ftruncate, full-read, full-write, fwriteerror, gcd, getaddrinfo, getcwd, getdate, getdomainname, getgroups, gethostname, gethrxtime, getline, getloadavg, getndelim2, getnline, getopt, getpagesize, getpass, getpass-gnu, getsubopt, gettext, gettime, gettimeofday, getugroups, getusershell, group-member, hard-locale, hash, hash-pjw, human, iconv, iconvme, idcache, inet_ntop, inttostr, isdir, javacomp, javaexec, lchown, linebreak, linebuffer, localcharset, long-options, lstat, makepath, malloc, mathl, mbswidth, md5, memcasecmp, memchr, memcmp, memcoll, memcpy, memmem, memmove, mempcpy, memrchr, memset, minmax, mkdir, mkdtemp, mkstemp, mktime, modechange, mountlist, nanosleep, obstack, openat, pagealign_alloc, path-concat, pathmax, pathname, physmem, pipe, poll, posixtm, posixver, progname, putenv, quote, quotearg, raise, readlink, readtokens, readtokens0, readutmp, realloc, regex, rename, restrict, rmdir, rpmatch, safe-read, safe-write, same, save-cwd, savedir, setenv, settime, sh-quote, sha1, sig2str, snprintf, stat, stat-macros, stdbool, stdint, stdio-safer, stpcpy, stpncpy, strcase, strchrnul, strcspn, strdup, strerror, strftime, strndup, strnlen, strpbrk, strsep, strstr, strtod, strtoimax, strtok_r, strtol, strtoll, strtoul, strtoull, strtoumax, strverscmp, sysexits, time_r, timegm, timespec, tzset, ucs4-utf16, ucs4-utf8, ullong_max, unicodeio, unistd-safer, unlocked-io, userspec, utf16-ucs4, utf8-ucs4, utime, utimecmp, utimens, vasnprintf, vasprintf, version-etc, version-etc-fsf, vsnprintf, wait-process, xalloc, xalloc-die, xallocsa, xgetcwd, xgetdomainname, xgethostname, xmemcoll, xnanosleep, xreadlink, xsetenv, xsize, xstrndup, xstrtod, xstrtoimax, xstrtol, xstrtoumax, xvasprintf, yesno"> + <META NAME="keywords" CONTENT="acl, alloca, alloca-opt, allocsa, argmatch, argp, argz, assert, atexit, backupfile, base64, bcopy, binary-io, byteswap, c-bs-a, c-ctype, c-stack, c-strtod, c-strtold, calloc, canon-host, canonicalize, chdir-long, chown, classpath, cloexec, closeout, copy-file, cycle-check, diacrit, dirfd, dirname, dummy, dup2, eealloc, error, euidaccess, exclude, execute, exit, exitfail, extensions, fatal-signal, file-type, fileblocks, filemode, findprog, fnmatch, fnmatch-gnu, fnmatch-posix, fpending, free, fsusage, ftruncate, full-read, full-write, fwriteerror, gcd, getaddrinfo, getcwd, getdate, getdomainname, getgroups, gethostname, gethrxtime, getline, getloadavg, getndelim2, getnline, getopt, getpagesize, getpass, getpass-gnu, getsubopt, gettext, gettime, gettimeofday, getugroups, getusershell, group-member, hard-locale, hash, hash-pjw, human, iconv, iconvme, idcache, inet_ntop, inttostr, isdir, javacomp, javaexec, lchown, linebreak, linebuffer, localcharset, long-options, lstat, makepath, malloc, mathl, mbswidth, md5, memcasecmp, memchr, memcmp, memcoll, memcpy, memmem, memmove, mempcpy, memrchr, memset, minmax, mkdir, mkdtemp, mkstemp, mktime, modechange, mountlist, nanosleep, obstack, openat, pagealign_alloc, path-concat, pathmax, pathname, physmem, pipe, poll, posixtm, posixver, progname, putenv, quote, quotearg, raise, readlink, readtokens, readtokens0, readutmp, realloc, regex, rename, restrict, rmdir, rpmatch, safe-read, safe-write, same, save-cwd, savedir, setenv, settime, sh-quote, sha1, sig2str, snprintf, stat, stat-macros, stdbool, stdint, stdio-safer, stpcpy, stpncpy, strcase, strchrnul, strcspn, strdup, strerror, strftime, strndup, strnlen, strpbrk, strsep, strstr, strtod, strtoimax, strtok_r, strtol, strtoll, strtoul, strtoull, strtoumax, strverscmp, sysexits, time_r, timegm, timespec, tzset, ucs4-utf16, ucs4-utf8, ullong_max, unicodeio, unistd-safer, unlinkdir, unlocked-io, userspec, utf16-ucs4, utf8-ucs4, utime, utimecmp, utimens, vasnprintf, vasprintf, version-etc, version-etc-fsf, vsnprintf, wait-process, xalloc, xalloc-die, xallocsa, xgetcwd, xgetdomainname, xgethostname, xmemcoll, xnanosleep, xreadlink, xsetenv, xsize, xstrndup, xstrtod, xstrtoimax, xstrtol, xstrtoumax, xvasprintf, yesno"> </HEAD> <BODY> <H1>Gnulib Module List</H1> @@ -724,6 +724,10 @@ <TD ALIGN=LEFT VALIGN=TOP WIDTH="80%">Return the entries of a directory (just the names) as an argz string. </TR> <TR WIDTH="100%"> + <TD ALIGN=LEFT VALIGN=TOP WIDTH="20%"><A HREF="#module=unlinkdir">unlinkdir</A> + <TD ALIGN=LEFT VALIGN=TOP WIDTH="80%">Determine (and maybe change) whether we can unlink directories. + </TR> + <TR WIDTH="100%"> <TD ALIGN=LEFT VALIGN=TOP WIDTH="20%"><A HREF="#module=utimecmp">utimecmp</A> <TD ALIGN=LEFT VALIGN=TOP WIDTH="80%">compare file time stamps </TR> @@ -2597,6 +2601,13 @@ <TD ALIGN=LEFT VALIGN=TOP>xalloc </TR> <TR> + <TD ALIGN=LEFT VALIGN=TOP><A NAME="module=unlinkdir"></A><A HREF="modules/unlinkdir">unlinkdir</A> + <TD ALIGN=LEFT VALIGN=TOP>#include "<A HREF="lib/unlinkdir.h">unlinkdir.h</A>" + <TD ALIGN=LEFT VALIGN=TOP><A HREF="lib/unlinkdir.c">unlinkdir.c</A> + <TD ALIGN=LEFT VALIGN=TOP><A HREF="m4/unlinkdir.m4">unlinkdir.m4</A><BR>gl_UNLINKDIR + <TD ALIGN=LEFT VALIGN=TOP>stdbool + </TR> + <TR> <TD ALIGN=LEFT VALIGN=TOP><A NAME="module=utimecmp"></A><A HREF="modules/utimecmp">utimecmp</A> <TD ALIGN=LEFT VALIGN=TOP>#include "<A HREF="lib/utimecmp.h">utimecmp.h</A>" <TD ALIGN=LEFT VALIGN=TOP><A HREF="lib/intprops.h">intprops.h</A><BR><A HREF="lib/utimecmp.c">utimecmp.c</A> @@ -2948,7 +2959,7 @@ <TD ALIGN=LEFT VALIGN=TOP>#include "<A HREF="lib/yesno.h">yesno.h</A>" <TD ALIGN=LEFT VALIGN=TOP><A HREF="lib/yesno.c">yesno.c</A> <TD ALIGN=LEFT VALIGN=TOP><A HREF="m4/yesno.m4">yesno.m4</A><BR>gl_YESNO - <TD ALIGN=LEFT VALIGN=TOP>rpmatch<BR>stdbool + <TD ALIGN=LEFT VALIGN=TOP>getline<BR>rpmatch<BR>stdbool </TR> <TR> <TD ALIGN=LEFT VALIGN=TOP><A NAME="module=ucs4-utf8"></A><A HREF="modules/ucs4-utf8">ucs4-utf8</A> @@ -3315,6 +3326,6 @@ <LI>A testsuite </UL> <HR> - Generated from <CODE>MODULES.html.sh</CODE> on 10 May 2005. + Generated from <CODE>MODULES.html.sh</CODE> on 14 May 2005. </BODY> </HTML>
--- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -1826,6 +1826,7 @@ func_module same func_module save-cwd func_module savedir + func_module unlinkdir func_module utimecmp func_module utimens func_module xgetcwd
--- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,6 +1,7 @@ 2005-05-14 Paul Eggert <eggert@cs.ucla.edu> Sync from coreutils. + * unlinkdir.c, unlinkdir.h: New files. * gethrxtime.c, gethrxtime.h, getpass.h, mountlist.h, path-concat.c, regex.h, strtoll.c, unlocked-io.h, xtime.h: White space changes only.
new file mode 100644 --- /dev/null +++ b/lib/unlinkdir.c @@ -0,0 +1,70 @@ +/* unlinkdir.c - determine (and maybe change) whether we can unlink directories + + Copyright (C) 2005 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Paul Eggert and Jim Meyering. */ + +#include <config.h> + +#include "unlinkdir.h" + +#if HAVE_PRIV_H +# include <priv.h> +#endif +#if HAVE_UNISTD_H +# include <unistd.h> +#endif + +#if ! UNLINK_CANNOT_UNLINK_DIR + +/* Return true if we cannot unlink directories, false if we might be + able to unlink directories. If possible, tell the kernel we don't + want to be able to unlink directories, so that we can return true. */ + +bool +cannot_unlink_dir (void) +{ + static bool initialized; + static bool cannot; + + if (! initialized) + { +# if defined PRIV_EFFECTIVE && defined PRIV_SYS_LINKDIR + /* We might be able to unlink directories if we cannot + determine our privileges, or if we have the + PRIV_SYS_LINKDIR privilege and cannot delete it. */ + priv_set_t *pset = priv_allocset (); + if (pset) + { + cannot = + (getppriv (PRIV_EFFECTIVE, pset) == 0 + && (! priv_ismember (pset, PRIV_SYS_LINKDIR) + || (priv_delset (pset, PRIV_SYS_LINKDIR) == 0 + && setppriv (PRIV_SET, PRIV_EFFECTIVE, pset) == 0))); + priv_freeset (pset); + } +# else + /* In traditional Unix, only root can unlink directories. */ + cannot = (geteuid () != 0); +# endif + initialized = true; + } + + return cannot; +} + +#endif
new file mode 100644 --- /dev/null +++ b/lib/unlinkdir.h @@ -0,0 +1,27 @@ +/* unlinkdir.h - determine (and maybe change) whether we can unlink directories + + Copyright (C) 2005 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Paul Eggert and Jim Meyering. */ + +#include <stdbool.h> + +#if UNLINK_CANNOT_UNLINK_DIR +static bool cannot_unlink_dir (void) { return true; } +#else +bool cannot_unlink_dir (void); +#endif
--- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,8 @@ +2005-05-14 Paul Eggert <eggert@cs.ucla.edu> + + Sync from coreutils. + * unlinkdir.m4: New file. + 2005-05-10 Derek Price <derek@ximbiot.com> * getopt.m4 (gl_GETOPT): Check for Solaris 10 bug, not decl, when
new file mode 100644 --- /dev/null +++ b/m4/unlinkdir.m4 @@ -0,0 +1,34 @@ +#serial 2 + +# Copyright (C) 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# Written by Paul Eggert. + +AC_DEFUN([gl_UNLINKDIR], +[ + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_CHECK_HEADERS_ONCE(priv.h unistd.h) + + AC_LIBSOURCES([unlinkdir.c, unlinkdir.h]) + AC_LIBOBJ([unlinkdir]) + + # The Hurd, the Linux kernel, the FreeBSD kernel version 2.2 and later, + # and Cygwin never let anyone (even root) unlink directories. + # If anyone knows of another system for which unlink can never + # remove a directory, please report it to <bug-coreutils@gnu.org>. + # Unfortunately this is difficult to test for, since it requires root access + # and might create garbage in the file system, + # so the code below simply relies on the kernel name and version number. + case $host in + *-*-gnu[0-9]* | \ + *-*-linux-* | *-*-linux | \ + *-*-freebsd2.2* | *-*-freebsd[3-9]* | *-*-freebsd[1-9][0-9]* | \ + *-cygwin) + AC_DEFINE([UNLINK_CANNOT_UNLINK_DIR], 1, + [Define to 1 if unlink (dir) cannot possibly succeed.]);; + esac +])
new file mode 100644 --- /dev/null +++ b/modules/unlinkdir @@ -0,0 +1,24 @@ +Description: +Determine (and maybe change) whether we can unlink directories. + +Files: +lib/unlinkdir.h +lib/unlinkdir.c +m4/unlinkdir.m4 + +Depends-on: +stdbool + +configure.ac: +gl_UNLINKDIR + +Makefile.am: + +Include: +"unlinkdir.h" + +License: +GPL + +Maintainer: +Paul Eggert, Jim Meyering