From d5f7e64df8267621f5e17b2def101343f767b86e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 6 Nov 2006 18:21:34 +0000 Subject: [PATCH] * MODULES.html.sh (File system functions): New module canonicalize-lgpl. * lib/canonicalize.h: Add comments for canonicalize_filename_mode and canonicalize_file_name. * lib/canonicalize-lgpl.c, m4/canonicalize-lgpl.m4: * modules/canonicalize-lgpl: New files. --- ChangeLog | 160 +++++++++++---------- MODULES.html.sh | 1 + lib/canonicalize-lgpl.c | 353 ++++++++++++++++++++++++++++++++++++++++++++++ lib/canonicalize.h | 9 ++ m4/canonicalize-lgpl.m4 | 26 ++++ modules/canonicalize-lgpl | 27 ++++ 6 files changed, 498 insertions(+), 78 deletions(-) create mode 100644 lib/canonicalize-lgpl.c create mode 100755 m4/canonicalize-lgpl.m4 create mode 100755 modules/canonicalize-lgpl diff --git a/ChangeLog b/ChangeLog index d62ba7e45..8ee0e23fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-11-06 Paul Eggert + + * MODULES.html.sh (File system functions): New module + canonicalize-lgpl. + * lib/canonicalize.h: Add comments for canonicalize_filename_mode + and canonicalize_file_name. + * lib/canonicalize-lgpl.c, m4/canonicalize-lgpl.m4: + * modules/canonicalize-lgpl: New files. + 2006-11-05 Bruno Haible * gnulib-tool (func_import, func_create_testdir): Create directories @@ -1974,7 +1983,7 @@ * lib/mkdir-p.c: Include dirname.h, for IS_ABSOLUTE_FILE_NAME. (make_dir_parents): Use a subprocess if necessary. New arg WD; all users changed. - * lib/savewd.c, savewd.h: New files. + * lib/savewd.c, lib/savewd.h: New files. 2006-09-15 Jim Meyering @@ -2500,7 +2509,7 @@ 2006-08-29 Paul Eggert - * lib/isapipe.c, isapipe.h: New files. + * lib/isapipe.c, lib/isapipe.h: New files. 2006-08-29 Jim Meyering @@ -3566,7 +3575,7 @@ * m4/cycle-check.m4: New file. Require gl_STRUCT_DEV_INO and gl_SAME_INODE. - * m4/dev-ino.m4, same-inode.m4: New files. + * m4/dev-ino.m4, m4/same-inode.m4: New files. 2006-08-10 Eric Blake @@ -3638,7 +3647,7 @@ 2006-08-08 Eric Blake - * lib/verror.h, verror.c: New files. + * lib/verror.h, lib/verror.c: New files. 2006-08-08 Eric Blake @@ -3979,7 +3988,7 @@ 2006-07-22 Paul Eggert - * lib/close-stream.c, close-stream.h: New files. + * lib/close-stream.c, lib/close-stream.h: New files. 2006-07-22 Bruno Haible @@ -4282,7 +4291,7 @@ * modules/oset: New file. * modules/array-oset: New file. * modules/avltree-oset, modules/avltree-oset-tests: New files. - * modules/rbtree-oset, rbtree-oset-tests: New files. + * modules/rbtree-oset, modules/rbtree-oset-tests: New files. * tests/test-carray_list.c: New file. * tests/test-linked_list.c: New file. * tests/test-avltree_list.c: New file. @@ -4351,8 +4360,8 @@ 2006-07-16 Paul Eggert - * lib/dirchownmod.c, dirchownmod.h, mkancesdirs.c, mkancesdirs.h: - New files. + * lib/dirchownmod.c, lib/dirchownmod.h, lib/mkancesdirs.c: + * lib/mkancesdirs.h: New files. * lib/mkdir-p.c: Don't include alloca.h, stdio.h, sys/types.h, unistd.h, string.h, chdir-safer.h, dirname.h, lchmod.h, lchown.h, save-cwd.h. Instead, include dirchownmod.h and mkancesdirs.h. @@ -5790,7 +5799,8 @@ 2006-04-18 Derek Price Paul Eggert - * m4/_inttypes_h.m4, full-header-path.m4, include_next: New files. + * m4/_inttypes_h.m4, m4/full-header-path.m4, m4/include_next.m4: + New files. 2006-04-18 Derek Price Paul Eggert @@ -7001,7 +7011,7 @@ * lib/version-etc.c (COPYRIGHT_YEAR): Update to 2006. - * lib/chdir-safer.h, chdir-safer.c: New files. + * lib/chdir-safer.h, lib/chdir-safer.c: New files. * lib/modechange.c (mode_compile): Reject an invalid mode string that starts with an octal digit. From Andreas Gruenbacher. @@ -7189,7 +7199,7 @@ 2005-12-16 Jim Meyering - * lib/fprintftime.c, fprintftime.h: New files. + * lib/fprintftime.c, lib/fprintftime.h: New files. 2005-12-15 Simon Josefsson @@ -7403,7 +7413,7 @@ * lib/gc-gnulib.c: Add MD2. Implement gc_hash_* API. - * lib/md2.h, md2.c: New files. + * lib/md2.h, lib/md2.c: New files. 2005-10-28 Paul Eggert @@ -7511,13 +7521,13 @@ 2005-10-21 Simon Josefsson - * lib/des.h, des.c: New files. + * lib/des.h, lib/des.c: New files. * lib/gc-gnulib.c: Support DES.c 2005-10-21 Simon Josefsson - * lib/arctwo.h, arctwo.c: New files. + * lib/arctwo.h, lib/arctwo.c: New files. * lib/gc-gnulib.c: Support ARCTWO. @@ -7614,7 +7624,7 @@ 2005-10-18 Simon Josefsson - * lib/md4.h, md4.c: New files, based on md5.?. + * lib/md4.h, lib/md4.c: New files, based on md5.?. 2005-10-17 Stepan Kasal @@ -7693,9 +7703,9 @@ 2005-10-15 Simon Josefsson - * lib/rijndael-api-fst.h, rijndael-api-fst.c: New files. + * lib/rijndael-api-fst.h, lib/rijndael-api-fst.c: New files. - * lib/rijndael-alg-fst.h, rijndael-alg-fst.c: New files. + * lib/rijndael-alg-fst.h, lib/rijndael-alg-fst.c: New files. 2005-10-14 Simon Josefsson @@ -7709,7 +7719,7 @@ 2005-10-14 Simon Josefsson - * lib/arcfour.h, arcfour.c: New files. + * lib/arcfour.h, lib/arcfour.c: New files. 2005-10-14 Roland McGrath @@ -7800,7 +7810,7 @@ 2005-10-12 Simon Josefsson - * m4/gc-md5.m4, gc-hmac-md5: New files. + * m4/gc-md5.m4, m4/gc-hmac-md5.m4: New files. * m4/gc.m4: Don't call gl_MD5, gl_MEMXOR or gl_HMAC_MD5. @@ -7864,7 +7874,7 @@ 2005-10-11 Simon Josefsson - * lib/crc.h, crc.c: New files. + * lib/crc.h, lib/crc.c: New files. * lib/gc.h (gc_hash_buffer): Add doc. @@ -7961,7 +7971,7 @@ * lib/md5.h (MD5_DIGEST_SIZE, MD5_BLOCK_SIZE): Add, see also . - * lib/memxor.h, memxor.c: New files. + * lib/memxor.h, lib/memxor.c: New files. * lib/getaddrinfo.h: Don't protect sys/types.h with HAVE_SYS_TYPES_H, we assume all systems have it, suggested by Jim Meyering @@ -9554,7 +9564,7 @@ 2005-08-24 Jim Meyering Sync from coreutils. - * lib/fcntl--.h, fcntl-safer.h, open-safer.c: New files. + * lib/fcntl--.h, lib/fcntl-safer.h, lib/open-safer.c: New files. 2005-08-24 Jim Meyering @@ -10099,7 +10109,7 @@ * lib/getline.h, getline.c: Rewrite. - * lib/getdelim.h, getdelim.c: New files, ported from glibc. + * lib/getdelim.h, lib/getdelim.c: New files, ported from glibc. 2005-07-31 Bruno Haible @@ -10331,7 +10341,8 @@ 2005-07-07 Paul Eggert * lib/regex.c, regex.h: Sync from libc. - * lib/regcomp.c, regexec_internal.c, regex_internal.h, regexec.c: + * lib/regcomp.c, lib/regexec_internal.c, lib/regex_internal.h: + * lib/regexec.c: New files, synced from libc, except that regex_internal.h currently has a small porting fix. @@ -10440,7 +10451,7 @@ 2005-06-28 Simon Josefsson - * lib/check-version.h, check-version.c: New files. + * lib/check-version.h, lib/check-version.c: New files. 2005-06-28 Simon Josefsson @@ -10710,7 +10721,7 @@ 2005-05-29 Derek Price Paul Eggert - * lib/glob_.h, glob.c: New files. + * lib/glob_.h, lib/glob.c: New files. 2005-05-27 Paul Eggert @@ -10747,16 +10758,7 @@ 2005-05-25 Derek Price Paul Eggert - * modules/getlogin_r: New files. - -2005-05-25 Derek Price - Paul Eggert - - * m4/getlogin_r.m4: New files. - -2005-05-25 Derek Price - Paul Eggert - + * modules/getlogin_r, m4/getlogin_r.m4: New files. * lib/getlogin_r.c, getlogin_r.h: New files. 2005-05-25 Bruno Haible @@ -10906,7 +10908,7 @@ 2005-05-17 Jim Meyering - * lib/fts.c, fts_.h: New files, from coreutils. + * lib/fts.c, lib/fts_.h: New files, from coreutils. 2005-05-14 Paul Eggert @@ -10916,7 +10918,7 @@ 2005-05-14 Paul Eggert Sync from coreutils. - * lib/unlinkdir.c, unlinkdir.h: New files. + * lib/unlinkdir.c, lib/unlinkdir.h: New files. * lib/gethrxtime.c, lib/gethrxtime.h, lib/getpass.h, lib/mountlist.h, lib/path-concat.c, lib/regex.h, lib/unlocked-io.h, lib/xtime.h: White space changes only. @@ -11788,12 +11790,12 @@ 2005-02-25 Paul Eggert - * m4/gethrxtime.m4, xnanosleep.m4: New files. + * m4/gethrxtime.m4, m4/xnanosleep.m4: New files. * m4/gettime.m4 (gl_GETTIME): Check for nanotime. 2005-02-25 Paul Eggert - * lib/gethrxtime.h, gethrxtime.c, xtime.h: New files. + * lib/gethrxtime.h, lib/gethrxtime.c, lib/xtime.h: New files. * lib/timespec.h (gettime): Return void, since it always succeeds now. All uses changed. * lib/gettime.c (gettime) Likewise. @@ -11846,7 +11848,7 @@ 2005-02-22 Simon Josefsson - * lib/iconvme.h, iconvme.c: New files, from libc. + * lib/iconvme.h, lib/iconvme.c: New files, from libc. 2005-02-22 Simon Josefsson @@ -12123,7 +12125,7 @@ 2005-01-18 Jim Meyering Merge from coreutils. - * m4/chdir-long.m4, openat.m4: New files. + * m4/chdir-long.m4, m4/openat.m4: New files. * m4/save-cwd.m4 (gl_SAVE_CWD): Add AC_LIBSOURCES for save-cwd.c, save-cwd.h. Add AC_LIBOBJ for save-cwd. * m4/chown.m4 (gl_FUNC_CHOWN): When cross-compiling, assume that chown @@ -12760,7 +12762,7 @@ 2004-11-10 Simon Josefsson - * lib/getaddrinfo.h, getaddrinfo.c: New files. + * lib/getaddrinfo.h, lib/getaddrinfo.c: New files. 2004-11-10 Simon Josefsson @@ -13202,7 +13204,7 @@ 2004-09-30 Simon Josefsson - * lib/snprintf.h, snprintf.c: New files. + * lib/snprintf.h, lib/snprintf.c: New files. 2004-09-30 Sergey Poznyakoff @@ -13517,7 +13519,7 @@ 2004-08-09 Paul Eggert - * m4/uint32_t.m4, uintptr_t.m4: New files. + * m4/uint32_t.m4, m4/uintptr_t.m4: New files. * m4/sha1.m4: Renamed from sha.m4. (gl_SHA1): Renamed from gl_SHA. All uses changed. @@ -13555,7 +13557,7 @@ 2004-08-08 Paul Eggert - * lib/xalloc-die.c: New files. + * lib/xalloc-die.c: New file. * lib/xalloc.h (xalloc_fail_func, xalloc_msg_memory_exhausted): Remove. All uses removed. * lib/xmalloc.c (xalloc_fail_func, xalloc_msg_memory_exhausted): @@ -13600,7 +13602,7 @@ More merge from coreutils. - * m4/utimens.m4, utimecmp.m4: New files. + * m4/utimens.m4, m4/utimecmp.m4: New files. * m4/backupfile.m4, euidacces.m4, acl.m4, afs.m4, calloc.m4, dirfd.m4, fsusage.m4, jm-macros.m4, ls-mntd-fs.m4, md5.m4, mountlist.m4, prereq.m4, sha.m4: Import changes from coreutils. @@ -13608,8 +13610,8 @@ 2004-08-06 Paul Eggert More merge from coreutils. - * modules/raise, modules/readtokens0, modules/utimens, - modules/utimecmp, module/xnanosleep: New files. + * modules/raise, modules/readtokens0, modules/utimens: + * modules/utimecmp, module/xnanosleep: New files. * modules/strftime: Add lib/strftime.h. Change include from to "strftime.h". * modules/yesno: Add lib/yesno.h. @@ -13629,9 +13631,9 @@ we don't compile these functions for tar. More merges from coreutils. - * lib/raise.c, lib/readtokens0.h, lib/readtokens0.c, lib/strftime.h, - lib/utimens.h, lib/utimens.c, lib/utimecmp.h, lib/utimecmp.c, - lib/xnanosleep.h, lib/xnanosleep.c, lib/yesno.h: New files. + * lib/raise.c, lib/readtokens0.h, lib/readtokens0.c, lib/strftime.h: + * lib/utimens.h, lib/utimens.c, lib/utimecmp.h, lib/utimecmp.c: + * lib/xnanosleep.h, lib/xnanosleep.c, lib/yesno.h: New files. * lib/addext.c: Remove; no longer needed. * lib/yesno.c, lib/argmatch.h, lib/argmatch.c, lib/backupfile.h, lib/backupfile.c, lib/euidaccess.c, lib/filemode.c, lib/closeout.c, @@ -13664,8 +13666,8 @@ Merge from coreutils. - * m4/c-strtod.m4, canonicalize.m4, fcntl-safer.m4, getcwd-path-max.m4: - New files. + * m4/c-strtod.m4, m4/canonicalize.m4, m4/fcntl-safer.m4: + * m4/getcwd-path-max.m4: New files. * m4/dos.m4 (gl_AC_DOS): filesystem -> file system renaming. FILESYSTEM_PREFIX_LEN -> @@ -13685,9 +13687,10 @@ * lib/.gdb-history: Remove; this doesn't belong here. - * lib/c-strtod.c, c-strtod.h, c-strtold.c, cycle-check.c, - cycle-check.h, dev-ino.h, canonicalize.h, canonicalize.c, - fcntl-safer.h, fcntl-safer.c, getcwd.c: New files. + * lib/c-strtod.c, lib/c-strtod.h, lib/c-strtold.c, lib/cycle-check.c: + * lib/cycle-check.h, lib/dev-ino.h, lib/canonicalize.h: + * lib/canonicalize.c, lib/fcntl-safer.h, lib/fcntl-safer.c: + * lib/getcwd.c: New files. * lib/dirname.h: Include . (FILE_SYSTEM_PREFIX_LEN): Renamed from FILESYSTEM_PREFIX_LEN, @@ -13724,8 +13727,8 @@ 2004-08-05 Paul Eggert Merge from coreutils. - * modules/c-strtod, modules/c-strtold, modules/canonicalize, - modules/cycle-check, modules/fcntl-safer, modules/getcwd: New files. + * modules/c-strtod, modules/c-strtold, modules/canonicalize: + * modules/cycle-check, modules/fcntl-safer, modules/getcwd: New files. * modules/path-concat: Don't depend on strdup. 2004-08-03 Simon Josefsson @@ -13822,7 +13825,8 @@ 2004-06-22 Paul Eggert - * lib/argz.c, argz_.h: New files, which are autoupdated from libtool. + * lib/argz.c, lib/argz_.h: New files, which are autoupdated from + libtool. 2004-06-22 Paul Eggert @@ -14221,8 +14225,8 @@ Merge from coreutils. - * lib/imaxtostr.c, inttostr.c, inttostr.h, offtostr.c, umaxtostr.c: - New files. + * lib/imaxtostr.c, lib/inttostr.c, lib/inttostr.h, lib/offtostr.c: + * lib/umaxtostr.c: New files. * lib/getdate.h: Include stdbool.h, and timespec.h instead of the usual dance. @@ -14327,7 +14331,7 @@ Include cloexec.h and xalloc.h. (getloadavg): Restore LC_NUMERIC locale after setting it temporarily. Use set_cloexec_flag rather than rolling our own. - * lib/cloexec.c, cloexec.h: New files. + * lib/cloexec.c, lib/cloexec.h: New files. 2004-03-29 Paul Eggert @@ -14392,7 +14396,7 @@ 2004-02-23 Karl Berry - * doc/maintain.texi, standards.texi, make-stds.texi: new files + * doc/maintain.texi, doc/standards.texi, doc/make-stds.texi: new files (from fencepost.gnu.org:/gd/gnuorg). 2004-02-23 Karl Berry @@ -14555,7 +14559,7 @@ 2004-01-18 Karl Berry - * doc/gpl.texi, lgpl.texi: new files. + * doc/gpl.texi, doc/lgpl.texi: new files. 2004-01-18 Karl Berry @@ -16161,7 +16165,7 @@ 2003-09-06 Paul Eggert - * lib/time_r.c, time_r.h: New files. + * lib/time_r.c, lib/time_r.h: New files. * lib/mktime.c (my_mktime_localtime_r): Remove; all uses changed to __localtime_r. @@ -19412,7 +19416,7 @@ 2002-06-22 Jim Meyering - * lib/c-stack.c, c-stack.h: New files, from diffutils-2.8.2. + * lib/c-stack.c, lib/c-stack.h: New files, from diffutils-2.8.2. * lib/exitfail.c, exitfail.h: Likewise. * lib/Makefile.am (libfetish_a_SOURCES): Add exitfail.c and exitfail.h. @@ -19563,7 +19567,7 @@ 2002-04-28 Paul Eggert - * lib/sig2str.h, sig2str.c: New files. + * lib/sig2str.h, lib/sig2str.c: New files. * lib/Makefile.am (libfetish_a_SOURCES): Add sig2str.h. 2002-04-28 Paul Eggert @@ -19670,7 +19674,7 @@ 2002-02-25 Paul Eggert - * lib/acl.c, acl.h: New files. + * lib/acl.c, lib/acl.h: New files. * lib/Makefile.am (libfetish_a_SOURCES): Add acl.h, acl.c. 2002-02-24 Jim Meyering @@ -19713,7 +19717,7 @@ 2002-02-15 Paul Eggert - * lib/posixver.c, posixver.h: New files. + * lib/posixver.c, lib/posixver.h: New files. * lib/Makefile.am (libfetish_a_SOURCES): Add them. 2002-02-02 Paul Eggert @@ -19749,7 +19753,7 @@ 2002-01-21 Paul Eggert - * lib/xmemcoll.h, xmemcoll.c: New files. + * lib/xmemcoll.h, lib/xmemcoll.c: New files. * lib/Makefile.am (libfetish_a_SOURCES): Add them. * lib/memcoll.c: Include errno.h, and declare errno if not defined. (memcoll): Set errno to zero if there is no error. @@ -20041,7 +20045,7 @@ 2001-11-01 Jim Meyering - * lib/dirfd.c, dirfd.h: New files. + * lib/dirfd.c, lib/dirfd.h: New files. * lib/Makefile.am (libfetish_a_SOURCES): Add dirfd.h. * lib/hash.c (hash_print) [TESTING]: Clean up. @@ -20985,8 +20989,8 @@ Add dup-safer.c, fopen-safer.c. (noinst_HEADERS): Add stdio-safer.h, unistd-safer.h. - * lib/dup-safer.c, lib/fopen-safer.c, lib/stdio-safer.h, - lib/unistd-safer.h: New files. + * lib/dup-safer.c, lib/fopen-safer.c, lib/stdio-safer.h: + * lib/unistd-safer.h: New files. 2001-02-25 Paul Eggert @@ -21019,7 +21023,7 @@ * lib/mkstemp.c (__GT_FILE): Define to zero if not defined. - * lib/mkstemp.c, tempname.c: New files, taken from glibc 2.2.2. + * lib/mkstemp.c, lib/tempname.c: New files, taken from glibc 2.2.2. 2001-02-18 Paul Eggert @@ -21253,7 +21257,7 @@ 2000-12-18 Paul Eggert - * lib/physmem.h, physmem.c: New files. + * lib/physmem.h, lib/physmem.c: New files. * lib/Makefile.am (libfetish_a_SOURCES): Add physmem.c. (noinst_HEADERS): Add physmem.h. @@ -22690,7 +22694,7 @@ * lib/config.charset: Output a line containing "Packages using this file". - * lib/ref-add.sed.in, ref-del.sed.in: New files. + * lib/ref-add.sed.in, lib/ref-del.sed.in: New files. * lib/Makefile.am (install-exec-local, uninstall-local, ref-add.sed, ref-del.sed): New rules. @@ -22784,7 +22788,7 @@ * lib/config.charset: New file. * lib/localcharset.c: New file. - * lib/unicodeio.h, unicodeio.c: New files. + * lib/unicodeio.h, lib/unicodeio.c: New files. * lib/Makefile.am (DEFS): Add -DLIBDIR=... (libfetish_a_SOURCES): Add localcharset.c and unicodeio.c. (noinst_HEADERS): Add unicodeio.h. diff --git a/MODULES.html.sh b/MODULES.html.sh index 9f77cf60e..e7032040f 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -1927,6 +1927,7 @@ func_all_modules () func_module acl func_module backupfile func_module canonicalize + func_module canonicalize-lgpl func_module clean-temp func_module copy-file func_module cycle-check diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c new file mode 100644 index 000000000..7da120680 --- /dev/null +++ b/lib/canonicalize-lgpl.c @@ -0,0 +1,353 @@ +/* Return the canonical absolute name of a given file. + Copyright (C) 1996-2003, 2005-2006 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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 Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +/* Avoid a clash of our rpl_realpath() function with the prototype in + on Solaris 2.5.1. */ +#undef realpath + +#if !HAVE_CANONICALIZE_FILE_NAME || defined _LIBC + +#include + +/* Specification. */ +#include "canonicalize.h" + +#include +#include +#include + +#if HAVE_UNISTD_H || defined _LIBC +# include +#endif + +#include + +#if HAVE_SYS_PARAM_H || defined _LIBC +# include +#endif +#ifndef MAXSYMLINKS +# define MAXSYMLINKS 20 +#endif + +#include + +#include +#ifndef _LIBC +# define __set_errno(e) errno = (e) +# ifndef ENAMETOOLONG +# define ENAMETOOLONG EINVAL +# endif +#endif + +#ifdef _LIBC +# include +#else +# define SHLIB_COMPAT(lib, introduced, obsoleted) 0 +# define versioned_symbol(lib, local, symbol, version) +# define compat_symbol(lib, local, symbol, version) +# define weak_alias(local, symbol) +# define __canonicalize_file_name canonicalize_file_name +# define __realpath rpl_realpath +# include "pathmax.h" +# include "allocsa.h" +# if HAVE_GETCWD +# ifdef VMS + /* We want the directory in Unix syntax, not in VMS syntax. */ +# define __getcwd(buf, max) getcwd (buf, max, 0) +# else +# define __getcwd getcwd +# endif +# else +# define __getcwd(buf, max) getwd (buf) +# endif +# define __readlink readlink + /* On systems without symbolic links, call stat() instead of lstat(). */ +# if !defined S_ISNLK && !HAVE_READLINK +# define lstat stat +# endif +#endif + +/* Return the canonical absolute name of file NAME. A canonical name + does not contain any `.', `..' components nor any repeated path + separators ('/') or symlinks. All path components must exist. If + RESOLVED is null, the result is malloc'd; otherwise, if the + canonical name is PATH_MAX chars or more, returns null with `errno' + set to ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars, + returns the name in RESOLVED. If the name cannot be resolved and + RESOLVED is non-NULL, it contains the path of the first component + that cannot be resolved. If the path can be resolved, RESOLVED + holds the same value as the value returned. */ + +char * +__realpath (const char *name, char *resolved) +{ + char *rpath, *dest, *extra_buf = NULL; + const char *start, *end, *rpath_limit; + long int path_max; +#ifdef S_ISLNK + int num_links = 0; +#endif + + if (name == NULL) + { + /* As per Single Unix Specification V2 we must return an error if + either parameter is a null pointer. We extend this to allow + the RESOLVED parameter to be NULL in case the we are expected to + allocate the room for the return value. */ + __set_errno (EINVAL); + return NULL; + } + + if (name[0] == '\0') + { + /* As per Single Unix Specification V2 we must return an error if + the name argument points to an empty string. */ + __set_errno (ENOENT); + return NULL; + } + +#ifdef PATH_MAX + path_max = PATH_MAX; +#else + path_max = pathconf (name, _PC_PATH_MAX); + if (path_max <= 0) + path_max = 1024; +#endif + + if (resolved == NULL) + { + rpath = malloc (path_max); + if (rpath == NULL) + return NULL; + } + else + rpath = resolved; + rpath_limit = rpath + path_max; + + if (name[0] != '/') + { + if (!__getcwd (rpath, path_max)) + { + rpath[0] = '\0'; + goto error; + } + dest = strchr (rpath, '\0'); + } + else + { + rpath[0] = '/'; + dest = rpath + 1; + } + + for (start = end = name; *start; start = end) + { +#ifdef _LIBC + struct stat64 st; +#else + struct stat st; +#endif + + /* Skip sequence of multiple path-separators. */ + while (*start == '/') + ++start; + + /* Find end of path component. */ + for (end = start; *end && *end != '/'; ++end) + /* Nothing. */; + + if (end - start == 0) + break; + else if (end - start == 1 && start[0] == '.') + /* nothing */; + else if (end - start == 2 && start[0] == '.' && start[1] == '.') + { + /* Back up to previous component, ignore if at root already. */ + if (dest > rpath + 1) + while ((--dest)[-1] != '/'); + } + else + { + size_t new_size; + + if (dest[-1] != '/') + *dest++ = '/'; + + if (dest + (end - start) >= rpath_limit) + { + ptrdiff_t dest_offset = dest - rpath; + char *new_rpath; + + if (resolved) + { + __set_errno (ENAMETOOLONG); + if (dest > rpath + 1) + dest--; + *dest = '\0'; + goto error; + } + new_size = rpath_limit - rpath; + if (end - start + 1 > path_max) + new_size += end - start + 1; + else + new_size += path_max; + new_rpath = (char *) realloc (rpath, new_size); + if (new_rpath == NULL) + goto error; + rpath = new_rpath; + rpath_limit = rpath + new_size; + + dest = rpath + dest_offset; + } + +#ifdef _LIBC + dest = __mempcpy (dest, start, end - start); +#else + memcpy (dest, start, end - start); + dest += end - start; +#endif + *dest = '\0'; + +#ifdef _LIBC + if (__lxstat64 (_STAT_VER, rpath, &st) < 0) +#else + if (lstat (rpath, &st) < 0) +#endif + goto error; + +#ifdef S_ISLNK + if (S_ISLNK (st.st_mode)) + { + char *buf; + size_t len; + int n; + + if (++num_links > MAXSYMLINKS) + { + __set_errno (ELOOP); + goto error; + } + + buf = allocsa (path_max); + if (!buf) + { + errno = ENOMEM; + goto error; + } + + n = __readlink (rpath, buf, path_max); + if (n < 0) + { + int saved_errno = errno; + freesa (buf); + errno = saved_errno; + goto error; + } + buf[n] = '\0'; + + if (!extra_buf) + { + extra_buf = allocsa (path_max); + if (!extra_buf) + { + freesa (buf); + errno = ENOMEM; + goto error; + } + } + + len = strlen (end); + if ((long int) (n + len) >= path_max) + { + freesa (buf); + __set_errno (ENAMETOOLONG); + goto error; + } + + /* Careful here, end may be a pointer into extra_buf... */ + memmove (&extra_buf[n], end, len + 1); + name = end = memcpy (extra_buf, buf, n); + + if (buf[0] == '/') + dest = rpath + 1; /* It's an absolute symlink */ + else + /* Back up to previous component, ignore if at root already: */ + if (dest > rpath + 1) + while ((--dest)[-1] != '/'); + } +#endif + } + } + if (dest > rpath + 1 && dest[-1] == '/') + --dest; + *dest = '\0'; + + if (extra_buf) + freesa (extra_buf); + + return resolved ? memcpy (resolved, rpath, dest - rpath + 1) : rpath; + +error: + { + int saved_errno = errno; + if (extra_buf) + freesa (extra_buf); + if (resolved) + strcpy (resolved, rpath); + else + free (rpath); + errno = saved_errno; + } + return NULL; +} +#ifdef _LIBC +versioned_symbol (libc, __realpath, realpath, GLIBC_2_3); +#endif + + +#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3) +char * +__old_realpath (const char *name, char *resolved) +{ + if (resolved == NULL) + { + __set_errno (EINVAL); + return NULL; + } + + return __realpath (name, resolved); +} +compat_symbol (libc, __old_realpath, realpath, GLIBC_2_0); +#endif + + +char * +__canonicalize_file_name (const char *name) +{ + return __realpath (name, NULL); +} +weak_alias (__canonicalize_file_name, canonicalize_file_name) + +#else + +/* This declaration is solely to ensure that after preprocessing + this file is never empty. */ +typedef int dummy; + +#endif diff --git a/lib/canonicalize.h b/lib/canonicalize.h index deaf27f13..8821a768e 100644 --- a/lib/canonicalize.h +++ b/lib/canonicalize.h @@ -33,12 +33,21 @@ enum canonicalize_mode_t }; typedef enum canonicalize_mode_t canonicalize_mode_t; +/* Return a malloc'd string containing the canonical absolute name of + the named file. This acts like canonicalize_file_name, except that + whether components must exist depends on the canonicalize_mode_t + argument. */ char *canonicalize_filename_mode (const char *, canonicalize_mode_t); # endif # if HAVE_DECL_CANONICALIZE_FILE_NAME # include # else +/* Return a malloc'd string containing the canonical absolute name of + the named file. If any file name component does not exist or is a + symlink to a nonexistent file, return NULL. A canonical name does + not contain any `.', `..' components nor any repeated file name + separators ('/') or symlinks. */ char *canonicalize_file_name (const char *); # endif diff --git a/m4/canonicalize-lgpl.m4 b/m4/canonicalize-lgpl.m4 new file mode 100755 index 000000000..7b1cd036c --- /dev/null +++ b/m4/canonicalize-lgpl.m4 @@ -0,0 +1,26 @@ +# canonicalize-lgpl.m4 serial 3 +dnl Copyright (C) 2003, 2006 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. + +AC_DEFUN([gl_CANONICALIZE_LGPL], +[ + dnl Do this replacement check manually because the file name is shorter + dnl than the function name. + AC_CHECK_DECLS_ONCE(canonicalize_file_name) + AC_CHECK_FUNCS_ONCE(canonicalize_file_name) + if test $ac_cv_func_canonicalize_file_name = no; then + AC_LIBOBJ(canonicalize-lgpl) + AC_DEFINE([realpath], [rpl_realpath], + [Define to a replacement function name for realpath().]) + gl_PREREQ_CANONICALIZE_LGPL + fi +]) + +# Prerequisites of lib/canonicalize-lgpl.c. +AC_DEFUN([gl_PREREQ_CANONICALIZE_LGPL], +[ + AC_CHECK_HEADERS_ONCE(sys/param.h unistd.h) + AC_CHECK_FUNCS_ONCE(getcwd readlink) +]) diff --git a/modules/canonicalize-lgpl b/modules/canonicalize-lgpl new file mode 100755 index 000000000..ccacf9886 --- /dev/null +++ b/modules/canonicalize-lgpl @@ -0,0 +1,27 @@ +Description: +Canonical absolute file name (LGPLed version). + +Files: +lib/canonicalize.h +lib/canonicalize-lgpl.c +m4/canonicalize-lgpl.m4 + +Depends-on: +alloca-opt +allocsa +pathmax +readlink + +configure.ac: +gl_CANONICALIZE_LGPL + +Makefile.am: + +Include: +"canonicalize.h" + +License: +LGPL + +Maintainer: +Bruno Haible -- 2.11.0