[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Cvs-cvs] ccvs/lib ChangeLog Makefile.am Makefile.gnulib ...
From: |
Derek Robert Price |
Subject: |
[Cvs-cvs] ccvs/lib ChangeLog Makefile.am Makefile.gnulib ... |
Date: |
Thu, 06 Jul 2006 02:17:59 +0000 |
CVSROOT: /cvsroot/cvs
Module name: ccvs
Changes by: Derek Robert Price <dprice> 06/07/06 02:17:59
Modified files:
lib : ChangeLog Makefile.am Makefile.gnulib
Makefile.in basename.c cycle-check.c
cycle-check.h dirname.c dirname.h filenamecat.c
getcwd.c inttypes.h stat-macros.h stat_.h
stdint_.h stripslash.c
Added files:
lib : same-inode.h strndup.c strndup.h strnlen.c
strnlen.h xstrndup.c xstrndup.h
Log message:
* same-inode.h, strndup.c, strndup.h, strnlen.c, strnlen.h, xstrndup.c,
xstrndup.h: New file from GNULIB.
* Makefile.am: Move changes from...
* Makefile.gnulib: ...this regenerated file.
* basename.c, cycle-check.c, cycle-check.h, dirname.c, dirname.h,
filenamecat.c, getcwd.c, inttypes.h, stat-macros.h, stat_.h, stdint_.h,
stripslash.c: Update from GNULIB.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/ChangeLog?cvsroot=cvs&r1=1.528&r2=1.529
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/Makefile.am?cvsroot=cvs&r1=1.116&r2=1.117
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/Makefile.gnulib?cvsroot=cvs&r1=1.79&r2=1.80
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/Makefile.in?cvsroot=cvs&r1=1.216&r2=1.217
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/basename.c?cvsroot=cvs&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/cycle-check.c?cvsroot=cvs&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/cycle-check.h?cvsroot=cvs&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/dirname.c?cvsroot=cvs&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/dirname.h?cvsroot=cvs&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/filenamecat.c?cvsroot=cvs&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/getcwd.c?cvsroot=cvs&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/inttypes.h?cvsroot=cvs&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/stat-macros.h?cvsroot=cvs&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/stat_.h?cvsroot=cvs&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/stdint_.h?cvsroot=cvs&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/stripslash.c?cvsroot=cvs&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/same-inode.h?cvsroot=cvs&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/strndup.c?cvsroot=cvs&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/strndup.h?cvsroot=cvs&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/strnlen.c?cvsroot=cvs&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/strnlen.h?cvsroot=cvs&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/xstrndup.c?cvsroot=cvs&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/ccvs/lib/xstrndup.h?cvsroot=cvs&rev=1.1
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/cvs/ccvs/lib/ChangeLog,v
retrieving revision 1.528
retrieving revision 1.529
diff -u -b -r1.528 -r1.529
--- ChangeLog 3 Jul 2006 08:39:41 -0000 1.528
+++ ChangeLog 6 Jul 2006 02:17:59 -0000 1.529
@@ -1,3 +1,13 @@
+2006-07-05 Derek Price <address@hidden>
+
+ * same-inode.h, strndup.c, strndup.h, strnlen.c, strnlen.h, xstrndup.c,
+ xstrndup.h: New file from GNULIB.
+ * Makefile.am: Move changes from...
+ * Makefile.gnulib: ...this regenerated file.
+ * basename.c, cycle-check.c, cycle-check.h, dirname.c, dirname.h,
+ filenamecat.c, getcwd.c, inttypes.h, stat-macros.h, stat_.h, stdint_.h,
+ stripslash.c: Update from GNULIB.
+
2006-07-03 Mark D. Baushke <address@hidden>
* stdint_.h: Fork stdint_.h to work on MacOS X 10.4.x.
Index: Makefile.am
===================================================================
RCS file: /cvsroot/cvs/ccvs/lib/Makefile.am,v
retrieving revision 1.116
retrieving revision 1.117
diff -u -b -r1.116 -r1.117
--- Makefile.am 3 Jul 2006 02:10:59 -0000 1.116
+++ Makefile.am 6 Jul 2006 02:17:59 -0000 1.117
@@ -92,7 +92,7 @@
## begin gnulib module cycle-check
-libcvs_a_SOURCES += cycle-check.c cycle-check.h dev-ino.h
+libcvs_a_SOURCES += cycle-check.c cycle-check.h dev-ino.h same-inode.h
## end gnulib module cycle-check
@@ -291,7 +291,7 @@
sed -e 's/@''HAVE_WCHAR_H''@/$(HAVE_WCHAR_H)/g' \
-e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \
-e 's/@''HAVE_SYS_TYPES_H''@/$(HAVE_SYS_TYPES_H)/g' \
- -e 's|@''FULL_PATH_STDINT_H''@|$(FULL_PATH_STDINT_H)|g' \
+ -e 's|@''ABSOLUTE_STDINT_H''@|$(ABSOLUTE_STDINT_H)|g' \
-e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \
-e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \
-e 's/@''HAVE_SYS_BITYPES_H''@/$(HAVE_SYS_BITYPES_H)/g' \
@@ -358,7 +358,7 @@
# has one that is incomplete.
sys/stat.h: stat_.h
test -d sys || mkdir sys
- sed -e 's|@''FULL_PATH_SYS_STAT_H''@|$(FULL_PATH_SYS_STAT_H)|g' \
+ sed -e 's|@''ABSOLUTE_SYS_STAT_H''@|$(ABSOLUTE_SYS_STAT_H)|g' \
< $(srcdir)/stat_.h > address@hidden
mv address@hidden $@
MOSTLYCLEANFILES += sys/stat.h sys/stat.h-t
@@ -420,6 +420,12 @@
## end gnulib module xsize
+## begin gnulib module xstrndup
+
+libcvs_a_SOURCES += xstrndup.h xstrndup.c
+
+## end gnulib module xstrndup
+
mostlyclean-local:
@test -z "$(MOSTLYCLEANDIRS)" || \
Index: Makefile.gnulib
===================================================================
RCS file: /cvsroot/cvs/ccvs/lib/Makefile.gnulib,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -b -r1.79 -r1.80
--- Makefile.gnulib 3 Jul 2006 02:10:59 -0000 1.79
+++ Makefile.gnulib 6 Jul 2006 02:17:59 -0000 1.80
@@ -63,7 +63,7 @@
## begin gnulib module cycle-check
-libgnu_a_SOURCES += cycle-check.c cycle-check.h dev-ino.h
+libgnu_a_SOURCES += cycle-check.c cycle-check.h dev-ino.h same-inode.h
## end gnulib module cycle-check
@@ -233,7 +233,7 @@
sed -e 's/@''HAVE_WCHAR_H''@/$(HAVE_WCHAR_H)/g' \
-e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \
-e 's/@''HAVE_SYS_TYPES_H''@/$(HAVE_SYS_TYPES_H)/g' \
- -e 's|@''FULL_PATH_STDINT_H''@|$(FULL_PATH_STDINT_H)|g' \
+ -e 's|@''ABSOLUTE_STDINT_H''@|$(ABSOLUTE_STDINT_H)|g' \
-e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \
-e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \
-e 's/@''HAVE_SYS_BITYPES_H''@/$(HAVE_SYS_BITYPES_H)/g' \
@@ -300,7 +300,7 @@
# has one that is incomplete.
sys/stat.h: stat_.h
test -d sys || mkdir sys
- sed -e 's|@''FULL_PATH_SYS_STAT_H''@|$(FULL_PATH_SYS_STAT_H)|g' \
+ sed -e 's|@''ABSOLUTE_SYS_STAT_H''@|$(ABSOLUTE_SYS_STAT_H)|g' \
< $(srcdir)/stat_.h > address@hidden
mv address@hidden $@
MOSTLYCLEANFILES += sys/stat.h sys/stat.h-t
@@ -362,6 +362,12 @@
## end gnulib module xsize
+## begin gnulib module xstrndup
+
+libgnu_a_SOURCES += xstrndup.h xstrndup.c
+
+## end gnulib module xstrndup
+
mostlyclean-local:
@test -z "$(MOSTLYCLEANDIRS)" || \
Index: Makefile.in
===================================================================
RCS file: /cvsroot/cvs/ccvs/lib/Makefile.in,v
retrieving revision 1.216
retrieving revision 1.217
diff -u -b -r1.216 -r1.217
--- Makefile.in 3 Jul 2006 02:10:59 -0000 1.216
+++ Makefile.in 6 Jul 2006 02:17:59 -0000 1.217
@@ -77,14 +77,15 @@
regex_internal.c regex_internal.h regexec.c rename.c rpmatch.c \
save-cwd.c save-cwd.h setenv.c stat-macros.h strcasecmp.c \
strdup.c strdup.h strerror.c strftime.c strftime.h \
- strncasecmp.c strstr.c strtoimax.c strtol.c strtoll.c \
- strtoul.c strtoull.c strtoumax.c sunos57-select.c tempname.c \
- time_r.c time_r.h timespec.h unistd--.h unistd-safer.h \
- unlocked-io.h unsetenv.c vasnprintf.c vasprintf.c waitpid.c \
- xalloc.h xgetcwd.c xgetcwd.h xmalloc.c xreadlink.c xreadlink.h \
- yesno.c yesno.h
+ strncasecmp.c strndup.c strndup.h strnlen.c strnlen.h strstr.c \
+ strtoimax.c strtol.c strtoll.c strtoul.c strtoull.c \
+ strtoumax.c sunos57-select.c tempname.c time_r.c time_r.h \
+ timespec.h unistd--.h unistd-safer.h unlocked-io.h unsetenv.c \
+ vasnprintf.c vasprintf.c waitpid.c xalloc.h xgetcwd.c \
+ xgetcwd.h xmalloc.c xreadlink.c xreadlink.h yesno.c yesno.h
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/_inttypes_h.m4 \
+ $(top_srcdir)/m4/absolute-header.m4 \
$(top_srcdir)/m4/acx_extract_cpp_defn.m4 \
$(top_srcdir)/m4/acx_with_external_zlib.m4 \
$(top_srcdir)/m4/acx_with_gssapi.m4 $(top_srcdir)/m4/alloca.m4 \
@@ -98,14 +99,14 @@
$(top_srcdir)/m4/cvs_func_printf_ptr.m4 \
$(top_srcdir)/m4/d-ino.m4 $(top_srcdir)/m4/d-type.m4 \
$(top_srcdir)/m4/dirname.m4 $(top_srcdir)/m4/dos.m4 \
- $(top_srcdir)/m4/dup2.m4 $(top_srcdir)/m4/eealloc.m4 \
- $(top_srcdir)/m4/eoverflow.m4 $(top_srcdir)/m4/error.m4 \
- $(top_srcdir)/m4/exitfail.m4 $(top_srcdir)/m4/extensions.m4 \
- $(top_srcdir)/m4/fcntl-safer.m4 \
+ $(top_srcdir)/m4/double-slash-root.m4 $(top_srcdir)/m4/dup2.m4 \
+ $(top_srcdir)/m4/eealloc.m4 $(top_srcdir)/m4/eoverflow.m4 \
+ $(top_srcdir)/m4/error.m4 $(top_srcdir)/m4/exitfail.m4 \
+ $(top_srcdir)/m4/extensions.m4 $(top_srcdir)/m4/fcntl-safer.m4 \
$(top_srcdir)/m4/filenamecat.m4 $(top_srcdir)/m4/fnmatch.m4 \
$(top_srcdir)/m4/fpending.m4 $(top_srcdir)/m4/ftruncate.m4 \
- $(top_srcdir)/m4/full-header-path.m4 \
$(top_srcdir)/m4/getaddrinfo.m4 \
+ $(top_srcdir)/m4/getcwd-abort-bug.m4 \
$(top_srcdir)/m4/getcwd-path-max.m4 $(top_srcdir)/m4/getcwd.m4 \
$(top_srcdir)/m4/getdate.m4 $(top_srcdir)/m4/getdelim.m4 \
$(top_srcdir)/m4/gethostname.m4 $(top_srcdir)/m4/getline.m4 \
@@ -142,6 +143,7 @@
$(top_srcdir)/m4/stdint.m4 $(top_srcdir)/m4/stdint_h.m4 \
$(top_srcdir)/m4/strcase.m4 $(top_srcdir)/m4/strdup.m4 \
$(top_srcdir)/m4/strerror.m4 $(top_srcdir)/m4/strftime.m4 \
+ $(top_srcdir)/m4/strndup.m4 $(top_srcdir)/m4/strnlen.m4 \
$(top_srcdir)/m4/strstr.m4 $(top_srcdir)/m4/strtoimax.m4 \
$(top_srcdir)/m4/strtol.m4 $(top_srcdir)/m4/strtoll.m4 \
$(top_srcdir)/m4/strtoul.m4 $(top_srcdir)/m4/strtoull.m4 \
@@ -157,8 +159,8 @@
$(top_srcdir)/m4/wchar_t.m4 $(top_srcdir)/m4/wcwidth.m4 \
$(top_srcdir)/m4/wint_t.m4 $(top_srcdir)/m4/xalloc.m4 \
$(top_srcdir)/m4/xgetcwd.m4 $(top_srcdir)/m4/xreadlink.m4 \
- $(top_srcdir)/m4/xsize.m4 $(top_srcdir)/m4/yesno.m4 \
- $(top_srcdir)/configure.in
+ $(top_srcdir)/m4/xsize.m4 $(top_srcdir)/m4/xstrndup.m4 \
+ $(top_srcdir)/m4/yesno.m4 $(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
@@ -172,7 +174,7 @@
am_libcvs_a_OBJECTS = sighandle.$(OBJEXT) allocsa.$(OBJEXT) \
base64.$(OBJEXT) cycle-check.$(OBJEXT) basename.$(OBJEXT) \
stripslash.$(OBJEXT) getnline.$(OBJEXT) strnlen1.$(OBJEXT) \
- xalloc-die.$(OBJEXT) xgethostname.$(OBJEXT)
+ xalloc-die.$(OBJEXT) xgethostname.$(OBJEXT) xstrndup.$(OBJEXT)
libcvs_a_OBJECTS = $(am_libcvs_a_OBJECTS)
am_getdate_OBJECTS = getdate-error.$(OBJEXT) getdate-getdate.$(OBJEXT) \
getdate-progname.$(OBJEXT)
@@ -195,6 +197,8 @@
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ABSOLUTE_STDINT_H = @ABSOLUTE_STDINT_H@
+ABSOLUTE_SYS_STAT_H = @ABSOLUTE_SYS_STAT_H@
ACLOCAL = @ACLOCAL@
ALLOCA = @ALLOCA@
ALLOCA_H = @ALLOCA_H@
@@ -230,8 +234,6 @@
EOVERFLOW = @EOVERFLOW@
EXEEXT = @EXEEXT@
FNMATCH_H = @FNMATCH_H@
-FULL_PATH_STDINT_H = @FULL_PATH_STDINT_H@
-FULL_PATH_SYS_STAT_H = @FULL_PATH_SYS_STAT_H@
GETOPT_H = @GETOPT_H@
GLOB_H = @GLOB_H@
GL_COND_LIBTOOL_FALSE = @GL_COND_LIBTOOL_FALSE@
@@ -369,12 +371,13 @@
# matching?)
libcvs_a_SOURCES = sighandle.c system.h wait.h xselect.h xtime.h \
allocsa.h allocsa.c base64.h base64.c cycle-check.c \
- cycle-check.h dev-ino.h basename.c stripslash.c error.h exit.h \
- getaddrinfo.h getnline.h getnline.c gettext.h inet_ntop.h \
- mbchar.h mbuiter.h minmax.h setenv.h size_max.h strcase.h \
- strnlen1.h strnlen1.c strstr.h printf-args.h printf-parse.h \
- vasnprintf.h vasprintf.h verify.h wcwidth.h xalloc-die.c \
- xgethostname.h xgethostname.c xsize.h
+ cycle-check.h dev-ino.h same-inode.h basename.c stripslash.c \
+ error.h exit.h getaddrinfo.h getnline.h getnline.c gettext.h \
+ inet_ntop.h mbchar.h mbuiter.h minmax.h setenv.h size_max.h \
+ strcase.h strnlen1.h strnlen1.c strstr.h printf-args.h \
+ printf-parse.h vasnprintf.h vasprintf.h verify.h wcwidth.h \
+ xalloc-die.c xgethostname.h xgethostname.c xsize.h xstrndup.h \
+ xstrndup.c
libcvs_a_LIBADD = @LIBOBJS@ @ALLOCA@
BUILT_SOURCES = $(ALLOCA_H) $(FNMATCH_H) getdate.c $(GETOPT_H) \
$(GLOB_H) $(STDBOOL_H) $(STDINT_H) $(SYS_SOCKET_H) \
@@ -537,6 +540,8 @@
@AMDEP_TRUE@@am__include@ @address@hidden(DEPDIR)/address@hidden@
@AMDEP_TRUE@@am__include@ @address@hidden(DEPDIR)/address@hidden@
@AMDEP_TRUE@@am__include@ @address@hidden(DEPDIR)/address@hidden@
address@hidden@@am__include@ @address@hidden(DEPDIR)/address@hidden@
address@hidden@@am__include@ @address@hidden(DEPDIR)/address@hidden@
@AMDEP_TRUE@@am__include@ @address@hidden(DEPDIR)/address@hidden@
@AMDEP_TRUE@@am__include@ @address@hidden(DEPDIR)/address@hidden@
@AMDEP_TRUE@@am__include@ @address@hidden(DEPDIR)/address@hidden@
@@ -568,6 +573,7 @@
@AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
@AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
@AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
address@hidden@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
.c.o:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c
-o $@ $<; \
@@ -915,7 +921,7 @@
sed -e 's/@''HAVE_WCHAR_H''@/$(HAVE_WCHAR_H)/g' \
-e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \
-e 's/@''HAVE_SYS_TYPES_H''@/$(HAVE_SYS_TYPES_H)/g' \
- -e 's|@''FULL_PATH_STDINT_H''@|$(FULL_PATH_STDINT_H)|g' \
+ -e 's|@''ABSOLUTE_STDINT_H''@|$(ABSOLUTE_STDINT_H)|g' \
-e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \
-e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \
-e 's/@''HAVE_SYS_BITYPES_H''@/$(HAVE_SYS_BITYPES_H)/g' \
@@ -947,7 +953,7 @@
# has one that is incomplete.
sys/stat.h: stat_.h
test -d sys || mkdir sys
- sed -e 's|@''FULL_PATH_SYS_STAT_H''@|$(FULL_PATH_SYS_STAT_H)|g' \
+ sed -e 's|@''ABSOLUTE_SYS_STAT_H''@|$(ABSOLUTE_SYS_STAT_H)|g' \
< $(srcdir)/stat_.h > address@hidden
mv address@hidden $@
Index: basename.c
===================================================================
RCS file: /cvsroot/cvs/ccvs/lib/basename.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- basename.c 19 Sep 2005 21:26:13 -0000 1.5
+++ basename.c 6 Jul 2006 02:17:59 -0000 1.6
@@ -1,6 +1,6 @@
/* basename.c -- return the last element in a file name
- Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free
+ Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006 Free
Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
@@ -22,58 +22,110 @@
#endif
#include "dirname.h"
-#include <string.h>
-/* In general, we can't use the builtin `basename' function if available,
- since it has different meanings in different environments.
- In some environments the builtin `basename' modifies its argument.
+#include <string.h>
+#include "xalloc.h"
+#include "xstrndup.h"
- Return the address of the last file name component of NAME. If
- NAME has no file name components because it is all slashes, return
- NAME if it is empty, the address of its last slash otherwise. */
+/* Return the address of the last file name component of NAME. If
+ NAME has no relative file name components because it is a file
+ system root, return the empty string. */
char *
-base_name (char const *name)
+last_component (char const *name)
{
char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
char const *p;
+ bool saw_slash = false;
+
+ while (ISSLASH (*base))
+ base++;
for (p = base; *p; p++)
{
if (ISSLASH (*p))
+ saw_slash = true;
+ else if (saw_slash)
{
- /* Treat multiple adjacent slashes like a single slash. */
- do p++;
- while (ISSLASH (*p));
-
- /* If the file name ends in slash, use the trailing slash as
- the basename if no non-slashes have been found. */
- if (! *p)
- {
- if (ISSLASH (*base))
- base = p - 1;
- break;
- }
-
- /* *P is a non-slash preceded by a slash. */
base = p;
+ saw_slash = false;
}
}
return (char *) base;
}
-/* Return the length of of the basename NAME. Typically NAME is the
- value returned by base_name. Act like strlen (NAME), except omit
- redundant trailing slashes. */
+
+/* In general, we can't use the builtin `basename' function if available,
+ since it has different meanings in different environments.
+ In some environments the builtin `basename' modifies its argument.
+
+ Return the last file name component of NAME, allocated with
+ xmalloc. On systems with drive letters, a leading "./"
+ distinguishes relative names that would otherwise look like a drive
+ letter. Unlike POSIX basename(), NAME cannot be NULL,
+ base_name("") returns "", and the first trailing slash is not
+ stripped.
+
+ If lstat (NAME) would succeed, then { chdir (dir_name (NAME));
+ lstat (base_name (NAME)); } will access the same file. Likewise,
+ if the sequence { chdir (dir_name (NAME));
+ rename (base_name (NAME), "foo"); } succeeds, you have renamed NAME
+ to "foo" in the same directory NAME was in. */
+
+char *
+base_name (char const *name)
+{
+ char const *base = last_component (name);
+ size_t length;
+
+ /* If there is no last component, then name is a file system root or the
+ empty string. */
+ if (! *base)
+ return xstrndup (name, base_len (name));
+
+ /* Collapse a sequence of trailing slashes into one. */
+ length = base_len (base);
+ if (ISSLASH (base[length]))
+ length++;
+
+ /* On systems with drive letters, `a/b:c' must return `./b:c' rather
+ than `b:c' to avoid confusion with a drive letter. On systems
+ with pure POSIX semantics, this is not an issue. */
+ if (FILE_SYSTEM_PREFIX_LEN (base))
+ {
+ char *p = xmalloc (length + 3);
+ p[0] = '.';
+ p[1] = '/';
+ memcpy (p + 2, base, length);
+ p[length + 2] = '\0';
+ return p;
+ }
+
+ /* Finally, copy the basename. */
+ return xstrndup (base, length);
+}
+
+/* Return the length of the basename NAME. Typically NAME is the
+ value returned by base_name or last_component. Act like strlen
+ (NAME), except omit all trailing slashes. */
size_t
base_len (char const *name)
{
size_t len;
+ size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--)
continue;
+ if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1
+ && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])
+ return 2;
+
+ if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len
+ && len == prefix_len && ISSLASH (name[prefix_len]))
+ return prefix_len + 1;
+
return len;
}
Index: cycle-check.c
===================================================================
RCS file: /cvsroot/cvs/ccvs/lib/cycle-check.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- cycle-check.c 19 Sep 2005 21:26:13 -0000 1.2
+++ cycle-check.c 6 Jul 2006 02:17:59 -0000 1.3
@@ -1,6 +1,6 @@
/* help detect directory cycles efficiently
- Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004, 2005, 2006 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
@@ -33,10 +33,6 @@
#include "cycle-check.h"
-#define SAME_INODE(Stat_buf_1, Stat_buf_2) \
- ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
- && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
-
#define CC_MAGIC 9827862
/* Return true if I is a power of 2, or is zero. */
Index: cycle-check.h
===================================================================
RCS file: /cvsroot/cvs/ccvs/lib/cycle-check.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- cycle-check.h 23 May 2005 22:56:57 -0000 1.1
+++ cycle-check.h 6 Jul 2006 02:17:59 -0000 1.2
@@ -1,6 +1,6 @@
/* help detect directory cycles efficiently
- Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004, 2006 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
@@ -30,6 +30,7 @@
# endif
# include <stdbool.h>
# include "dev-ino.h"
+# include "same-inode.h"
struct cycle_check_state
{
@@ -41,4 +42,18 @@
void cycle_check_init (struct cycle_check_state *state);
bool cycle_check (struct cycle_check_state *state, struct stat const *sb);
+# define CYCLE_CHECK_REFLECT_CHDIR_UP(State, SB_dir, SB_subdir) \
+ do \
+ { \
+ /* You must call cycle_check at least once before using this macro. */ \
+ if ((State)->chdir_counter == 0) \
+ abort (); \
+ if (SAME_INODE ((State)->dev_ino, SB_subdir)) \
+ { \
+ (State)->dev_ino.st_dev = (SB_dir).st_dev; \
+ (State)->dev_ino.st_ino = (SB_dir).st_ino; \
+ } \
+ } \
+ while (0)
+
#endif
Index: dirname.c
===================================================================
RCS file: /cvsroot/cvs/ccvs/lib/dirname.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- dirname.c 19 Sep 2005 21:26:13 -0000 1.5
+++ dirname.c 6 Jul 2006 02:17:59 -0000 1.6
@@ -1,6 +1,6 @@
/* dirname.c -- return all but the last element in a file name
- Copyright (C) 1990, 1998, 2000, 2001, 2003, 2004, 2005 Free Software
+ Copyright (C) 1990, 1998, 2000, 2001, 2003, 2004, 2005, 2006 Free Software
Foundation, Inc.
This program is free software; you can redistribute it and/or modify
@@ -26,96 +26,62 @@
#include <string.h>
#include "xalloc.h"
-/* Return the length of `dirname (FILE)', or zero if FILE is
- in the working directory. Works properly even if
- there are trailing slashes (by effectively ignoring them). */
+/* Return the length of the prefix of FILE that will be used by
+ dir_name. If FILE is in the working directory, this returns zero
+ even though `dir_name (FILE)' will return ".". Works properly even
+ if there are trailing slashes (by effectively ignoring them). */
+
size_t
dir_len (char const *file)
{
size_t prefix_length = FILE_SYSTEM_PREFIX_LEN (file);
size_t length;
+ /* Advance prefix_length beyond important leading slashes. */
+ prefix_length += (prefix_length != 0
+ ? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
+ && ISSLASH (file[prefix_length]))
+ : (ISSLASH (file[0])
+ ? ((DOUBLE_SLASH_IS_DISTINCT_ROOT
+ && ISSLASH (file[1]) && ! ISSLASH (file[2])
+ ? 2 : 1))
+ : 0));
+
/* Strip the basename and any redundant slashes before it. */
- for (length = base_name (file) - file; prefix_length < length; length--)
+ for (length = last_component (file) - file;
+ prefix_length < length; length--)
if (! ISSLASH (file[length - 1]))
+ break;
return length;
-
- /* But don't strip the only slash from "/". */
- return prefix_length + ISSLASH (file[prefix_length]);
}
-/* Return the leading directories part of FILE,
- allocated with xmalloc.
- Works properly even if there are trailing slashes
- (by effectively ignoring them). */
+
+/* In general, we can't use the builtin `dirname' function if available,
+ since it has different meanings in different environments.
+ In some environments the builtin `dirname' modifies its argument.
+
+ Return the leading directories part of FILE, allocated with xmalloc.
+ Works properly even if there are trailing slashes (by effectively
+ ignoring them). Unlike POSIX dirname(), FILE cannot be NULL.
+
+ If lstat (FILE) would succeed, then { chdir (dir_name (FILE));
+ lstat (base_name (FILE)); } will access the same file. Likewise,
+ if the sequence { chdir (dir_name (FILE));
+ rename (base_name (FILE), "foo"); } succeeds, you have renamed FILE
+ to "foo" in the same directory FILE was in. */
char *
dir_name (char const *file)
{
size_t length = dir_len (file);
- bool append_dot = (length == FILE_SYSTEM_PREFIX_LEN (file));
+ bool append_dot = (length == 0
+ || (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
+ && length == FILE_SYSTEM_PREFIX_LEN (file)
+ && file[2] != '\0' && ! ISSLASH (file[2])));
char *dir = xmalloc (length + append_dot + 1);
memcpy (dir, file, length);
if (append_dot)
dir[length++] = '.';
- dir[length] = 0;
+ dir[length] = '\0';
return dir;
}
-
-#ifdef TEST_DIRNAME
-/*
-
-Run the test like this (expect no output):
- gcc -DHAVE_CONFIG_H -DTEST_DIRNAME -I.. -O -Wall \
- basename.c dirname.c xmalloc.c error.c
- sed -n '/^BEGIN-DATA$/,/^END-DATA$/p' dirname.c|grep -v DATA|./a.out
-
-If it's been built on a DOS or Windows platforms, run another test like
-this (again, expect no output):
- sed -n '/^BEGIN-DOS-DATA$/,/^END-DOS-DATA$/p' dirname.c|grep -v DATA|./a.out
-
-BEGIN-DATA
-foo//// .
-bar/foo//// bar
-foo/ .
-/ /
-. .
-a .
-END-DATA
-
-BEGIN-DOS-DATA
-c:///// c:/
-c:/ c:/
-c:/. c:/
-c:foo c:.
-c:foo/bar c:foo
-END-DOS-DATA
-
-*/
-
-# define MAX_BUFF_LEN 1024
-# include <stdio.h>
-
-char *program_name;
-
-int
-main (int argc, char *argv[])
-{
- char buff[MAX_BUFF_LEN + 1];
-
- program_name = argv[0];
-
- buff[MAX_BUFF_LEN] = 0;
- while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0])
- {
- char file[MAX_BUFF_LEN];
- char expected_result[MAX_BUFF_LEN];
- char const *result;
- sscanf (buff, "%s %s", file, expected_result);
- result = dir_name (file);
- if (strcmp (result, expected_result))
- printf ("%s: got %s, expected %s\n", file, result, expected_result);
- }
- return 0;
-}
-#endif
Index: dirname.h
===================================================================
RCS file: /cvsroot/cvs/ccvs/lib/dirname.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- dirname.h 10 Jun 2005 20:30:20 -0000 1.4
+++ dirname.h 6 Jul 2006 02:17:59 -0000 1.5
@@ -1,6 +1,6 @@
/* Take file names apart into directory and base names.
- Copyright (C) 1998, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2003-2006 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
@@ -31,16 +31,39 @@
# endif
# ifndef FILE_SYSTEM_PREFIX_LEN
-# define FILE_SYSTEM_PREFIX_LEN(File_name) 0
+# if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX
+ /* This internal macro assumes ASCII, but all hosts that support drive
+ letters use ASCII. */
+# define _IS_DRIVE_LETTER(c) (((unsigned int) (c) | ('a' - 'A')) - 'a' \
+ <= 'z' - 'a')
+# define FILE_SYSTEM_PREFIX_LEN(Filename) \
+ (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0)
+# else
+# define FILE_SYSTEM_PREFIX_LEN(Filename) 0
+# endif
+# endif
+
+# ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
+# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
# endif
+# ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
+# define DOUBLE_SLASH_IS_DISTINCT_ROOT 1
+# endif
+
+# if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)])
+# else
+# define IS_ABSOLUTE_FILE_NAME(F) \
+ (ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F))
+# endif
# define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F))
char *base_name (char const *file);
char *dir_name (char const *file);
size_t base_len (char const *file);
size_t dir_len (char const *file);
+char *last_component (char const *file);
bool strip_trailing_slashes (char *file);
Index: filenamecat.c
===================================================================
RCS file: /cvsroot/cvs/ccvs/lib/filenamecat.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- filenamecat.c 19 Sep 2005 21:26:13 -0000 1.2
+++ filenamecat.c 6 Jul 2006 02:17:59 -0000 1.3
@@ -1,7 +1,7 @@
/* Concatenate two arbitrary file names.
- Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
Free
- Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+ 2005, 2006 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
@@ -64,7 +64,7 @@
char *
file_name_concat (char const *dir, char const *abase, char **base_in_result)
{
- char const *dirbase = base_name (dir);
+ char const *dirbase = last_component (dir);
size_t dirbaselen = base_len (dirbase);
size_t dirlen = dirbase - dir + dirbaselen;
size_t needs_separator = (dirbaselen && ! ISSLASH (dirbase[dirbaselen - 1]));
Index: getcwd.c
===================================================================
RCS file: /cvsroot/cvs/ccvs/lib/getcwd.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- getcwd.c 20 Mar 2006 02:21:56 -0000 1.8
+++ getcwd.c 6 Jul 2006 02:17:59 -0000 1.9
@@ -211,6 +211,7 @@
int parent_status;
size_t dirroom;
size_t namlen;
+ bool use_d_ino = true;
/* Look at the parent directory. */
#ifdef AT_FDCWD
@@ -257,11 +258,26 @@
NULL. */
__set_errno (0);
d = __readdir (dirstream);
+
+ /* When we've iterated through all directory entries without finding
+ one with a matching d_ino, rewind the stream and consider each
+ name again, but this time, using lstat. This is necessary in a
+ chroot on at least one system (glibc-2.3.6 + linux 2.6.12), where
+ .., ../.., ../../.., etc. all had the same device number, yet the
+ d_ino values for entries in / did not match those obtained
+ via lstat. */
+ if (d == NULL && errno == 0 && use_d_ino)
+ {
+ use_d_ino = false;
+ rewinddir (dirstream);
+ d = __readdir (dirstream);
+ }
+
if (d == NULL)
{
if (errno == 0)
- /* EOF on dirstream, which means that the current directory
- has been removed. */
+ /* EOF on dirstream, which can mean e.g., that the current
+ directory has been removed. */
__set_errno (ENOENT);
goto lose;
}
@@ -269,7 +285,14 @@
(d->d_name[1] == '\0' ||
(d->d_name[1] == '.' && d->d_name[2] == '\0')))
continue;
- if (MATCHING_INO (d, thisino) || mount_point)
+
+ if (use_d_ino)
+ {
+ bool match = (MATCHING_INO (d, thisino) || mount_point);
+ if (! match)
+ continue;
+ }
+
{
int entry_status;
#ifdef AT_FDCWD
@@ -309,7 +332,7 @@
while (i < dotlen);
}
- strcpy (dotlist + dotlen, d->d_name);
+ memcpy (dotlist + dotlen, d->d_name, _D_ALLOC_NAMLEN (d));
entry_status = __lstat (dotlist, &st);
#endif
/* We don't fail here if we cannot stat() a directory entry.
Index: inttypes.h
===================================================================
RCS file: /cvsroot/cvs/ccvs/lib/inttypes.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- inttypes.h 13 May 2006 20:47:48 -0000 1.3
+++ inttypes.h 6 Jul 2006 02:17:59 -0000 1.4
@@ -33,7 +33,7 @@
# if HAVE_INCLUDE_NEXT
# include_next <inttypes.h>
# else
-# include FULL_PATH_INTTYPES_H
+# include ABSOLUTE_INTTYPES_H
# endif
#endif
#include <stdint.h>
Index: stat-macros.h
===================================================================
RCS file: /cvsroot/cvs/ccvs/lib/stat-macros.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- stat-macros.h 23 May 2005 17:44:32 -0000 1.2
+++ stat-macros.h 6 Jul 2006 02:17:59 -0000 1.3
@@ -1,6 +1,7 @@
/* stat-related macros
- Copyright (C) 1993, 1994, 2001, 2002, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1993, 1994, 2001, 2002, 2004, 2006 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
@@ -33,7 +34,6 @@
# undef S_ISBLK
# undef S_ISCHR
# undef S_ISDIR
-# undef S_ISDOOR
# undef S_ISFIFO
# undef S_ISLNK
# undef S_ISNAM
@@ -70,12 +70,8 @@
# endif
# ifndef S_ISDOOR /* Solaris 2.5 and up */
-# ifdef S_IFDOOR
-# define S_ISDOOR(m) (((m) & S_IFMT) == S_IFDOOR)
-# else
# define S_ISDOOR(m) 0
# endif
-# endif
# ifndef S_ISFIFO
# ifdef S_IFIFO
@@ -119,6 +115,10 @@
# endif
# endif
+# ifndef S_ISPORT /* Solaris 10 and up */
+# define S_ISPORT(m) 0
+# endif
+
# ifndef S_ISREG
# ifdef S_IFREG
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
@@ -161,7 +161,7 @@
# endif
# endif
-/* contiguous */
+/* high performance ("contiguous data") */
# ifndef S_ISCTG
# define S_ISCTG(p) 0
# endif
@@ -176,6 +176,11 @@
# define S_ISOFL(p) 0
# endif
+/* 4.4BSD whiteout */
+# ifndef S_ISWHT
+# define S_ISWHT(m) 0
+# endif
+
/* If any of the following are undefined,
define them to their de facto standard values. */
# if !S_ISUID
Index: stat_.h
===================================================================
RCS file: /cvsroot/cvs/ccvs/lib/stat_.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- stat_.h 1 Jul 2006 12:58:08 -0000 1.2
+++ stat_.h 6 Jul 2006 02:17:59 -0000 1.3
@@ -22,7 +22,7 @@
/* This file is supposed to be used on platforms where <sys/stat.h> is
incomplete. It is intended to provide definitions and prototypes
needed by an application. Start with what the system provides. */
-#include @FULL_PATH_SYS_STAT_H@
+#include @ABSOLUTE_SYS_STAT_H@
/* mingw does not support symlinks, therefore it does not have lstat. But
without links, stat does just fine. */
Index: stdint_.h
===================================================================
RCS file: /cvsroot/cvs/ccvs/lib/stdint_.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- stdint_.h 3 Jul 2006 08:39:21 -0000 1.19
+++ stdint_.h 6 Jul 2006 02:17:59 -0000 1.20
@@ -32,20 +32,6 @@
for the "fast" types and macros, which we recommend against using
in public interfaces due to compiler differences. */
-/* <sys/types.h> defines some of the stdint.h types as well, on glibc,
- IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>). */
-#if @HAVE_SYS_TYPES_H@
-/* <sys/types.h> on MacOS X 10.4.6 includes <stdint.h> and needs the
- real one rather than the generated version. */
-#if __APPLE__ && @HAVE_STDINT_H@
-# include @FULL_PATH_STDINT_H@
-#endif
-# include <sys/types.h>
-#endif
-
-/* Get LONG_MIN, LONG_MAX, ULONG_MAX. */
-#include <limits.h>
-
#if @HAVE_STDINT_H@
# if defined __sgi && ! defined __c99
/* Bypass IRIX's <stdint.h> if in C89 mode, since it merely annoys users
@@ -57,14 +43,30 @@
Include it before <inttypes.h>, since any "#include <stdint.h>"
in <inttypes.h> would reinclude us, skipping our contents because
_GL_STDINT_H is defined. */
-# include @FULL_PATH_STDINT_H@
+# include @ABSOLUTE_STDINT_H@
#endif
+/* <sys/types.h> defines some of the stdint.h types as well, on glibc,
+ IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>).
+ MacOS X 10.4.6 <sys/types.h> includes <stdint.h> (which is us), but
+ relies on the system <stdint.h> definitions, so include
+ <sys/types.h> after @address@hidden */
+#if @HAVE_SYS_TYPES_H@
+# include <sys/types.h>
+#endif
+
+/* Get LONG_MIN, LONG_MAX, ULONG_MAX. */
+#include <limits.h>
+
#if @HAVE_INTTYPES_H@
/* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines
int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__.
<inttypes.h> also defines intptr_t and uintptr_t. */
# include <inttypes.h>
+#elif @HAVE_SYS_INTTYPES_H@
+ /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
+ the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */
+# include <sys/inttypes.h>
#endif
#if @HAVE_SYS_BITYPES_H@ && ! defined __BIT_TYPES_DEFINED__
@@ -74,13 +76,6 @@
# include <sys/bitypes.h>
#endif
-#if @HAVE_SYS_INTTYPES_H@ && address@hidden@
- /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
- the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX.
- But note that <sys/int_types.h> contains only the type definitions! */
-# include <sys/inttypes.h>
-#endif
-
#if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS
/* Get WCHAR_MIN, WCHAR_MAX. */
Index: stripslash.c
===================================================================
RCS file: /cvsroot/cvs/ccvs/lib/stripslash.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- stripslash.c 19 Sep 2005 21:26:14 -0000 1.7
+++ stripslash.c 6 Jul 2006 02:17:59 -0000 1.8
@@ -1,6 +1,6 @@
/* stripslash.c -- remove redundant trailing slashes from a file name
- Copyright (C) 1990, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1990, 2001, 2003-2006 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
@@ -22,19 +22,26 @@
#include "dirname.h"
-/* Remove trailing slashes from FILE.
- Return true if a trailing slash was removed.
- This is useful when using file name completion from a shell that
- adds a "/" after directory names (such as tcsh and bash), because
- the Unix rename and rmdir system calls return an "Invalid argument" error
- when given a file that ends in "/" (except for the root directory). */
+/* Remove trailing slashes from FILE. Return true if a trailing slash
+ was removed. This is useful when using file name completion from a
+ shell that adds a "/" after directory names (such as tcsh and
+ bash), because on symlinks to directories, several system calls
+ have different semantics according to whether a trailing slash is
+ present. */
bool
strip_trailing_slashes (char *file)
{
- char *base = base_name (file);
- char *base_lim = base + base_len (base);
- bool had_slash = (*base_lim != '\0');
+ char *base = last_component (file);
+ char *base_lim;
+ bool had_slash;
+
+ /* last_component returns "" for file system roots, but we need to turn
+ `///' into `/'. */
+ if (! *base)
+ base = file;
+ base_lim = base + base_len (base);
+ had_slash = (*base_lim != '\0');
*base_lim = '\0';
return had_slash;
}
Index: same-inode.h
===================================================================
RCS file: same-inode.h
diff -N same-inode.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ same-inode.h 6 Jul 2006 02:17:59 -0000 1.1
@@ -0,0 +1,26 @@
+/* Determine whether two stat buffers refer to the same file.
+
+ Copyright (C) 2006 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 Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#ifndef SAME_INODE_H
+# define SAME_INODE_H 1
+
+# define SAME_INODE(Stat_buf_1, Stat_buf_2) \
+ ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
+ && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
+
+#endif
Index: strndup.c
===================================================================
RCS file: strndup.c
diff -N strndup.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ strndup.c 6 Jul 2006 02:17:59 -0000 1.1
@@ -0,0 +1,66 @@
+/* Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006 Free
+ Software Foundation, Inc.
+
+ NOTE: The canonical source of this file is maintained with the GNU C
Library.
+ Bugs can be reported to address@hidden
+
+ 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. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#if !_LIBC
+# include "strndup.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#if !_LIBC
+# include "strnlen.h"
+# ifndef __strnlen
+# define __strnlen strnlen
+# endif
+#endif
+
+#undef __strndup
+#if _LIBC
+# undef strndup
+#endif
+
+#ifndef weak_alias
+# define __strndup strndup
+#endif
+
+char *
+__strndup (s, n)
+ const char *s;
+ size_t n;
+{
+ size_t len = __strnlen (s, n);
+ char *new = malloc (len + 1);
+
+ if (new == NULL)
+ return NULL;
+
+ new[len] = '\0';
+ return memcpy (new, s, len);
+}
+#ifdef libc_hidden_def
+libc_hidden_def (__strndup)
+#endif
+#ifdef weak_alias
+weak_alias (__strndup, strndup)
+#endif
Index: strndup.h
===================================================================
RCS file: strndup.h
diff -N strndup.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ strndup.h 6 Jul 2006 02:17:59 -0000 1.1
@@ -0,0 +1,30 @@
+/* Duplicate a size-bounded string.
+ Copyright (C) 2003 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 Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#if HAVE_STRNDUP
+
+/* Get strndup() declaration. */
+#include <string.h>
+
+#else
+
+#include <stddef.h>
+
+/* Return a newly allocated copy of at most N bytes of STRING. */
+extern char *strndup (const char *string, size_t n);
+
+#endif
Index: strnlen.c
===================================================================
RCS file: strnlen.c
diff -N strnlen.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ strnlen.c 6 Jul 2006 02:17:59 -0000 1.1
@@ -0,0 +1,33 @@
+/* Find the length of STRING, but scan at most MAXLEN characters.
+ Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ Written by Simon Josefsson.
+
+ 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. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "strnlen.h"
+
+/* Find the length of STRING, but scan at most MAXLEN characters.
+ If no '\0' terminator is found in that many characters, return MAXLEN. */
+
+size_t
+strnlen (const char *string, size_t maxlen)
+{
+ const char *end = memchr (string, '\0', maxlen);
+ return end ? (size_t) (end - string) : maxlen;
+}
Index: strnlen.h
===================================================================
RCS file: strnlen.h
diff -N strnlen.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ strnlen.h 6 Jul 2006 02:17:59 -0000 1.1
@@ -0,0 +1,32 @@
+/* Find the length of STRING, but scan at most MAXLEN characters.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+ Written by Simon Josefsson.
+
+ 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. */
+
+#ifndef STRNLEN_H
+#define STRNLEN_H
+
+/* Get strnlen declaration, if available. */
+#include <string.h>
+
+#if defined HAVE_DECL_STRNLEN && !HAVE_DECL_STRNLEN
+/* Find the length (number of bytes) of STRING, but scan at most
+ MAXLEN bytes. If no '\0' terminator is found in that many bytes,
+ return MAXLEN. */
+extern size_t strnlen(const char *string, size_t maxlen);
+#endif
+
+#endif /* STRNLEN_H */
Index: xstrndup.c
===================================================================
RCS file: xstrndup.c
diff -N xstrndup.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ xstrndup.c 6 Jul 2006 02:17:59 -0000 1.1
@@ -0,0 +1,39 @@
+/* Duplicate a bounded initial segment of a string, with out-of-memory
+ checking.
+ Copyright (C) 2003 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 Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Specification. */
+#include "xstrndup.h"
+
+#include "strndup.h"
+#include "xalloc.h"
+
+/* Return a newly allocated copy of at most N bytes of STRING.
+ In other words, return a copy of the initial segment of length N of
+ STRING. */
+char *
+xstrndup (const char *string, size_t n)
+{
+ char *s = strndup (string, n);
+ if (! s)
+ xalloc_die ();
+ return s;
+}
Index: xstrndup.h
===================================================================
RCS file: xstrndup.h
diff -N xstrndup.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ xstrndup.h 6 Jul 2006 02:17:59 -0000 1.1
@@ -0,0 +1,24 @@
+/* Duplicate a bounded initial segment of a string, with out-of-memory
+ checking.
+ Copyright (C) 2003 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 Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#include <stddef.h>
+
+/* Return a newly allocated copy of at most N bytes of STRING.
+ In other words, return a copy of the initial segment of length N of
+ STRING. */
+extern char *xstrndup (const char *string, size_t n);