VAX PATCH: remove FILE_NAME_NONDIRECTORY
John David Anglin
dave@hiauly1.hia.nrc.ca
Sun Feb 25 15:06:00 GMT 2001
> It may be that you need to change basename()'s interface so that it
> returns a malloc-ed string which the caller is reponsible for freeing;
> I would prefer that to giving up on creating shared portable code.
Don't much like changing basename's interface, however, here is a revision
which hopefully will be able to extract the file name portion of a VMS
file spec string as well as doing what it did before. I also modified
the configuration process to test whether the host system's version of
basename is the name-within-directory variant and if it isn't to build
the libiberty version.
I have another patch to the rest of gcc which now uses basename instead
of file_name_nondirectory. You can see how you like my method of doing
the lower case translation when needed. This patch will in a separate
message.
I have bootstrapped tested the new libiberty basename patch under i686
linux. Admittedly, this is not a good test of the new basename function
since it does need the libiberty version. However, it does test the
configuration process.
Note I have patched config.in since there is no acconfig.h file for it.
Dave
--
J. David Anglin dave.anglin@nrc.ca
National Research Council of Canada (613) 990-0752 (FAX: 952-6605)
2001-02-25 John David Anglin <dave@hiauly1.hia.nrc.ca>
* aclocal.m4 (libiberty_AC_FUNC_BASENAME): New macro to test for
name-within-directory variant of basename function.
* basename.c (basename): Add support for VMS file specification
strings and revise comments.
* config.in (HAVE_BASENAME): Revise comment.
* configure.in: Add code to perform checks for functions with
incompatible variants. Check for name-within-directory basename
function.
* configure: Rebuilt.
* makefile.vms (OBJS): Add basename to OBJS.
--- aclocal.m4.orig Wed Nov 22 03:32:26 2000
+++ aclocal.m4 Sun Feb 25 14:25:44 2001
@@ -126,6 +126,30 @@
AC_SUBST(ac_libiberty_warn_cflags)
])
+dnl Determine if basename is available and returns the name-within-directory
+dnl of a file name. There are two main variants of this function. The XPG
+dnl variant returns the last component of a pathname instead of the
+dnl name-within-directory.
+
+AC_DEFUN(libiberty_AC_FUNC_BASENAME,
+[
+AC_CACHE_CHECK([for name-within-directory basename], ac_cv_func_nonxpg_basename,
+[AC_TRY_RUN([
+extern char * basename ();
+int
+main ()
+{
+ char *s = basename ("/");
+ if (*s) exit (1);
+ exit (0);
+}
+],
+ac_cv_func_nonxpg_basename=yes,
+ac_cv_func_nonxpg_basename=no,
+ac_cv_func_nonxpg_basename=no)
+])
+])
+
# Work around a bug in autoheader. This can go away when we switch to
# autoconf >2.50. The use of define instead of AC_DEFUN is
# deliberate.
--- basename.c.orig Thu Dec 7 22:00:26 2000
+++ basename.c Sat Feb 24 20:30:42 2001
@@ -1,27 +1,38 @@
-/* Return the basename of a pathname.
+/* Return the name-within-directory of a pathname (file specification).
This file is in the public domain. */
/*
NAME
- basename -- return pointer to last component of a pathname
+ basename -- return pointer to the name-within-directory of a pathname
SYNOPSIS
char *basename (const char *name)
DESCRIPTION
- Given a pointer to a string containing a typical pathname
- (/usr/src/cmd/ls/ls.c for example), returns a pointer to the
- last component of the pathname ("ls.c" in this case).
+ Given a pointer to a string containing a pathname
+ (/usr/src/cmd/ls/ls.c for example), return a pointer
+ to the file-within-directory component of the pathname
+ ("ls.c" in this case). If the string terminates in a
+ directory separator, the file-within-directory component
+ may be an empty string.
BUGS
- Presumes a UNIX or DOS/Windows style path with UNIX or DOS/Windows
- style separators.
+ Presumes a VMS, UNIX or DOS/Windows style pathname with the
+ separator style determined by the compilation environment.
*/
#include "ansidecl.h"
#include "libiberty.h"
#include "safe-ctype.h"
+#ifdef VMS
+/* VMS uses '::', ':', '[...]' and '<...>' to separate the different
+ components of a file specification. It's a bit of a stretch to
+ call ':', ']' and '>' directory separators, so just define the test
+ to find the file name component. */
+#define IS_DIR_SEPARATOR(ch) ((ch) == ':' || (ch) == ']' || (ch) == '>')
+#endif
+
#ifndef DIR_SEPARATOR
#define DIR_SEPARATOR '/'
#endif
@@ -34,6 +45,7 @@
#endif
#endif
+#ifndef IS_DIR_SEPARATOR
/* Define IS_DIR_SEPARATOR. */
#ifndef DIR_SEPARATOR_2
# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
@@ -41,6 +53,7 @@
# define IS_DIR_SEPARATOR(ch) \
(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
#endif /* DIR_SEPARATOR_2 */
+#endif
char *
basename (name)
@@ -61,6 +74,7 @@
base = name + 1;
}
}
+
return (char *) base;
}
--- config.in.orig Tue Dec 26 17:16:22 2000
+++ config.in Sun Feb 25 11:55:10 2001
@@ -58,7 +58,7 @@
/* Define if you have the atexit function. */
#undef HAVE_ATEXIT
-/* Define if you have the basename function. */
+/* Define if you have the name-within-directory basename function. */
#undef HAVE_BASENAME
/* Define if you have the bcmp function. */
--- configure.in.orig Tue Dec 26 17:16:22 2000
+++ configure.in Sun Feb 25 11:43:47 2001
@@ -276,6 +276,23 @@
# We haven't set the list of objects yet. Use the standard autoconf
# tests. This will only work if the compiler works.
AC_PROG_CC_WORKS
+
+ # Do special tests for functions that have noncompatible versions.
+ for f in $funcs; do
+ case $f in
+ basename)
+ libiberty_AC_FUNC_BASENAME
+ if test $ac_cv_func_nonxpg_basename = yes; then
+ AC_DEFINE_UNQUOTED(HAVE_BASENAME)
+ else
+ LIBOBJS="$LIBOBJS basename.o"
+ fi
+ ac_cv_func_basename=$ac_cv_func_nonxpg_basename
+ funcs="`echo $funcs | sed -e 's/basename//'`"
+ ;;
+ esac
+ done
+
AC_REPLACE_FUNCS($funcs)
case "${host}" in
--- makefile.vms.orig Wed Sep 8 04:19:52 1999
+++ makefile.vms Sat Feb 24 19:40:11 2001
@@ -7,10 +7,11 @@
#
#
-OBJS=bcopy.obj,bcmp.obj,getopt.obj,obstack.obj,xexit.obj,xmalloc.obj,hex.obj,\
- getopt1.obj,cplus-dem.obj,strncasecmp.obj,strcasecmp.obj,strdup.obj,\
- concat.obj,getruntime.obj,getpagesize.obj,alloca.obj,xstrerror.obj,\
- xmemdup.obj,xstrdup.obj,xatexit.obj,choose-temp.obj,fnmatch.obj,objalloc.obj
+OBJS=basename.obj,bcopy.obj,bcmp.obj,getopt.obj,obstack.obj,xexit.obj, \
+ xmalloc.obj,hex.obj,getopt1.obj,cplus-dem.obj,strncasecmp.obj, \
+ strcasecmp.obj,strdup.obj,concat.obj,getruntime.obj,getpagesize.obj, \
+ alloca.obj,xstrerror.obj,xmemdup.obj,xstrdup.obj,xatexit.obj, \
+ choose-temp.obj,fnmatch.obj,objalloc.obj
ifeq ($(CC),gcc)
CFLAGS=/include=([],[-.include])
More information about the Gcc-patches
mailing list