This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[rfa] const char *lbasename(const char *);


Hello,

The current lbasename() implementation loosely translates into:

	char *
	lbasename (const char *name)
	  return (char *) name;

the attatched patch changes this to:

	const char *
	lbasename (const char *name)
	  return name;

so that the function doesn't silently cast a ``const char *'' into a 
writeable ``char *''.

A quick check of GCC indicates that this change will cause additional 
warnings in the GCC sources.  What should I do about these?  Can I also 
just check in the tweeks that fix these.

For GDB, this patch has no affect.  GDB already assumes that lbasename() 
returns a constant buffer.

	Andrew


Index: include/ChangeLog
2001-06-13  Andrew Cagney  <ac131313@redhat.com>

	* libiberty.h (lbasename): Return const char*.

Index: libiberty/ChangeLog
2001-06-13  Andrew Cagney  <ac131313@redhat.com>

	* lbasename.c (lbasename): Return const char*.

Index: include/libiberty.h
===================================================================
RCS file: /cvs/gcc/gcc/include/libiberty.h,v
retrieving revision 1.18
diff -p -r1.18 libiberty.h
*** libiberty.h	2001/03/31 18:59:56	1.18
--- libiberty.h	2001/06/13 19:38:37
*************** extern char *basename ();
*** 83,89 ****
  
  /* A well-defined basename () that is always compiled in.  */
  
! extern char *lbasename PARAMS ((const char *));
  
  /* Concatenate an arbitrary number of strings, up to (char *) NULL.
     Allocates memory using xmalloc.  */
--- 83,89 ----
  
  /* A well-defined basename () that is always compiled in.  */
  
! extern const char *lbasename PARAMS ((const char *));
  
  /* Concatenate an arbitrary number of strings, up to (char *) NULL.
     Allocates memory using xmalloc.  */
Index: libiberty/lbasename.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/lbasename.c,v
retrieving revision 1.1
diff -p -r1.1 lbasename.c
*** lbasename.c	2001/03/10 10:41:24	1.1
--- lbasename.c	2001/06/13 19:38:38
*************** NAME
*** 23,29 ****
  	lbasename -- return pointer to last component of a pathname
  
  SYNOPSIS
! 	char *lbasename (const char *name)
  
  DESCRIPTION
  	Given a pointer to a string containing a typical pathname
--- 23,29 ----
  	lbasename -- return pointer to last component of a pathname
  
  SYNOPSIS
! 	const char *lbasename (const char *name)
  
  DESCRIPTION
  	Given a pointer to a string containing a typical pathname
*************** DESCRIPTION
*** 69,75 ****
  #  endif
  #endif
  
! char *
  lbasename (name)
       const char *name;
  {
--- 69,75 ----
  #  endif
  #endif
  
! const char *
  lbasename (name)
       const char *name;
  {
*************** lbasename (name)
*** 85,89 ****
      if (IS_DIR_SEPARATOR (*name))
        base = name + 1;
  
!   return (char *) base;
  }
--- 85,89 ----
      if (IS_DIR_SEPARATOR (*name))
        base = name + 1;
  
!   return base;
  }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]