Re: Problem with xstrings cast to char* under Solaris

"Alexander V. Lukyanov" <[email protected]> Fri, 28 Dec 2007 12:19:09 +0300
Newsgroups gmane.network.lftp.devel
Message-ID <[email protected]>
On Wed, Dec 26, 2007 at 12:27:11PM +0100, Yann Rouillard wrote:
> During compilation, I have several cast errors, like this one:
> "FileCopy.cc", line 1042: Error: Cannot use const char* to initialize char*.

Thanks for the report. Here is a better patch, please test.

--
   Alexander.
diff (text/plain, 4.7 KB)
Index: FileCopy.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/FileCopy.cc,v
retrieving revision 1.143
diff -u -p -r1.143 FileCopy.cc
--- FileCopy.cc	12 Dec 2007 14:14:25 -0000	1.143
+++ FileCopy.cc	28 Dec 2007 08:01:28 -0000
@@ -1039,7 +1039,7 @@ int FileCopyPeerFA::Get_LL(int len)
 	       if(orig_url)
 	       {
 		  int p_ind=url::path_index(orig_url);
-		  char *s=strrchr(orig_url,'/');
+		  const char *s=strrchr(orig_url,'/');
 		  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);
Index: FileGlob.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/FileGlob.cc,v
retrieving revision 1.10
diff -u -p -r1.10 FileGlob.cc
--- FileGlob.cc	10 Sep 2007 10:00:04 -0000	1.10
+++ FileGlob.cc	28 Dec 2007 08:51:02 -0000
@@ -44,15 +44,11 @@ Glob::Glob(FileAccess *s,const char *p)
 
    if(pattern[0]=='~')
    {
-      char *slash=strchr(pattern,'/');
+      const char *slash=strchr(pattern,'/');
       if(slash)
-      {
-	 *slash=0;
-	 inhibit_tilde=HasWildcards(pattern);
-	 *slash='/';
-      }
+	 inhibit_tilde=HasWildcards(xstring::get_tmp(pattern,slash-pattern));
       else
-	 inhibit_tilde=HasWildcards(pattern);;
+	 inhibit_tilde=HasWildcards(pattern);
    }
    if(pattern[0] && !HasWildcards(pattern))
    {
Index: HttpDir.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/HttpDir.cc,v
retrieving revision 1.101
diff -u -p -r1.101 HttpDir.cc
--- HttpDir.cc	29 Aug 2007 11:20:13 -0000	1.101
+++ HttpDir.cc	28 Dec 2007 08:44:24 -0000
@@ -705,9 +705,9 @@ static int parse_html(const char *buf,in
    if(hftp)
    {
       // workaround proxy bugs.
-      char *t=strstr(link_target,";type=");
+      const char *t=strstr(link_target,";type=");
       if(t && t[6] && t[7]=='/' && t[8]==0)
-	 *t=0;
+	 link_target.truncate(t-link_target);
       const char *p=link_target+url::path_index(link_target);
       if(p[0]=='/' && p[1]=='/')
 	 link_target.set_substr(p-link_target+1,1,"%2F");
@@ -873,13 +873,11 @@ parse_url_again:
       }
    }
 
-   char *type=strstr(link_target,";type=");
+   const char *type=strstr(link_target,";type=");
    if(type && type[6] && !type[7])
    {
-      type[0]=0;
-      if(!all_links || all_links->FindByName(link_target))
+      if(!all_links || all_links->FindByName(xstring::get_tmp(link_target,type-link_target)))
 	 return tag_len;
-      type[0]=';';
    }
 
    if(link_target.length()==0)
@@ -1111,10 +1109,10 @@ parse_url_again:
 info_done:
    if(set && link_target[0]!='/' && link_target[0]!='~')
    {
-      char *slash=strchr(link_target,'/');
+      const char *slash=strchr(link_target,'/');
       if(slash)
       {
-	 *slash=0;
+	 link_target.truncate(slash-link_target);
 	 info.is_directory=true;
       }
 
@@ -1181,9 +1179,9 @@ int HttpDirList::Do()
       if(mode==FA::RETRIEVE)
       {
 	 // strip file name, directory remains.
-	 char *slash=strrchr(curr_url->path,'/');
+	 const char *slash=strrchr(curr_url->path,'/');
 	 if(slash && slash>curr_url->path)
-	    *slash=0;
+	    curr_url->path.truncate(slash-curr_url->path);
       }
 
    retry:
Index: LocalAccess.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/LocalAccess.cc,v
retrieving revision 1.60
diff -u -p -r1.60 LocalAccess.cc
--- LocalAccess.cc	20 Sep 2007 11:29:40 -0000	1.60
+++ LocalAccess.cc	28 Dec 2007 08:45:42 -0000
@@ -204,15 +204,11 @@ int LocalAccess::Do()
    case(MAKE_DIR):
       if(mkdir_p)
       {
-	 char *sl=strchr(file,'/');
+	 const char *sl=strchr(file,'/');
 	 while(sl)
 	 {
 	    if(sl>file)
-	    {
-	       *sl=0;
-	       mkdir(dir_file(cwd,file),0775);
-	       *sl='/';
-	    }
+	       mkdir(dir_file(cwd,xstring::get_tmp(file,sl-file)),0775);
 	    sl=strchr(sl+1,'/');
 	 }
       }
Index: ftpclass.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/ftpclass.cc,v
retrieving revision 1.434
diff -u -p -r1.434 ftpclass.cc
--- ftpclass.cc	12 Dec 2007 14:14:37 -0000	1.434
+++ ftpclass.cc	28 Dec 2007 08:48:36 -0000
@@ -1810,18 +1810,17 @@ int   Ftp::Do()
       {
 	 if(mode==MAKE_DIR && mkdir_p)
 	 {
-	    char *sl=strchr(file,'/');
+	    const char *sl=strchr(file,'/');
 	    while(sl)
 	    {
 	       if(sl>file)
 	       {
-		  *sl=0;
-		  if(strcmp(file,".") && strcmp(file,".."))
+		  xstring& tmp=xstring::get_tmp(file,sl-file);
+		  if(strcmp(tmp,".") && strcmp(tmp,".."))
 		  {
-		     conn->SendCmd2("MKD",file,url::path_ptr(file_url),home);
+		     conn->SendCmd2("MKD",tmp);
 		     expect->Push(Expect::IGNORE);
 		  }
-		  *sl='/';
 	       }
 	       sl=strchr(sl+1,'/');
 	    }