Problem with xstrings cast to char* under Solaris
Yann Rouillard <[email protected]> Wed, 26 Dec 2007 12:27:11 +0100
| Newsgroups | gmane.network.lftp.devel |
|---|---|
| Message-ID | <1198668431.6991.3.camel@localhost> |
Hi,
I maintain the lftp package for the blastwave project (
http://www.blastwave.org/ ) and had some compilation problem with Sun CC
under Solaris 8 with the last lftp (3.6.1)
During compilation, I have several cast errors, like this one:
"FileCopy.cc", line 1042: Error: Cannot use const char* to initialize
char*.
The problematic line here is:
char *s=strrchr(orig_url,'/');
orig_url is a xstring which can be automatically cast only to const
char*.
Under Solaris as this prototype is defined
in /usr/include/iso/string_iso.h in the following manner:
extern const char *strrchr(const char *, int);
extern "C++" {
inline char * strrchr(char *__s, int __c) {
return (char *)strrchr((const char *)__s, __c);
}
}
Hence the problem.
I had to apply the patch attached to be able to compile but I am not
sure it's the good solution.
Cheers,
Yann
xstring_char_cast_bugfix.patch
(text/x-patch, 3 KB)
diff --speed-large-files --minimal -Nru lftp-3.6.1.orig/src/FileCopy.cc lftp-3.6.1/src/FileCopy.cc
--- lftp-3.6.1.orig/src/FileCopy.cc 2007-09-10 05:57:53.000000000 -0400
+++ lftp-3.6.1/src/FileCopy.cc 2007-12-21 17:06:19.864433000 -0500
@@ -1039,7 +1039,7 @@
if(orig_url)
{
int p_ind=url::path_index(orig_url);
- char *s=strrchr(orig_url,'/');
+ char *s=strrchr(orig_url.get_non_const(),'/');
int s_ind=s?s-orig_url:-1;
if(p_ind==-1 || s_ind==-1 || s_ind<p_ind)
s_ind=p_ind=strlen(orig_url);
diff --speed-large-files --minimal -Nru lftp-3.6.1.orig/src/FileGlob.cc lftp-3.6.1/src/FileGlob.cc
--- lftp-3.6.1.orig/src/FileGlob.cc 2007-09-10 06:00:04.000000000 -0400
+++ lftp-3.6.1/src/FileGlob.cc 2007-12-21 17:08:11.257919000 -0500
@@ -44,7 +44,7 @@
if(pattern[0]=='~')
{
- char *slash=strchr(pattern,'/');
+ char *slash=strchr(pattern.get_non_const(),'/');
if(slash)
{
*slash=0;
diff --speed-large-files --minimal -Nru lftp-3.6.1.orig/src/HttpDir.cc lftp-3.6.1/src/HttpDir.cc
--- lftp-3.6.1.orig/src/HttpDir.cc 2007-08-29 07:20:13.000000000 -0400
+++ lftp-3.6.1/src/HttpDir.cc 2007-12-21 17:11:13.930057000 -0500
@@ -705,7 +705,7 @@
if(hftp)
{
// workaround proxy bugs.
- char *t=strstr(link_target,";type=");
+ char *t=strstr(link_target.get_non_const(),";type=");
if(t && t[6] && t[7]=='/' && t[8]==0)
*t=0;
const char *p=link_target+url::path_index(link_target);
@@ -873,7 +873,7 @@
}
}
- char *type=strstr(link_target,";type=");
+ char *type=strstr(link_target.get_non_const(),";type=");
if(type && type[6] && !type[7])
{
type[0]=0;
@@ -1111,7 +1111,7 @@
info_done:
if(set && link_target[0]!='/' && link_target[0]!='~')
{
- char *slash=strchr(link_target,'/');
+ char *slash=strchr(link_target.get_non_const(),'/');
if(slash)
{
*slash=0;
@@ -1181,7 +1181,7 @@
if(mode==FA::RETRIEVE)
{
// strip file name, directory remains.
- char *slash=strrchr(curr_url->path,'/');
+ char *slash=strrchr((curr_url->path).get_non_const(),'/');
if(slash && slash>curr_url->path)
*slash=0;
}
diff --speed-large-files --minimal -Nru lftp-3.6.1.orig/src/LocalAccess.cc lftp-3.6.1/src/LocalAccess.cc
--- lftp-3.6.1.orig/src/LocalAccess.cc 2007-09-20 07:29:40.000000000 -0400
+++ lftp-3.6.1/src/LocalAccess.cc 2007-12-21 17:11:51.934658000 -0500
@@ -204,7 +204,7 @@
case(MAKE_DIR):
if(mkdir_p)
{
- char *sl=strchr(file,'/');
+ char *sl=strchr(file.get_non_const(),'/');
while(sl)
{
if(sl>file)
diff --speed-large-files --minimal -Nru lftp-3.6.1.orig/src/ftpclass.cc lftp-3.6.1/src/ftpclass.cc
--- lftp-3.6.1.orig/src/ftpclass.cc 2007-11-08 02:59:29.000000000 -0500
+++ lftp-3.6.1/src/ftpclass.cc 2007-12-21 17:09:22.376544000 -0500
@@ -1805,7 +1805,7 @@
{
if(mode==MAKE_DIR && mkdir_p)
{
- char *sl=strchr(file,'/');
+ char *sl=strchr(file.get_non_const(),'/');
while(sl)
{
if(sl>file)