diff --git a/library/changes b/library/changes index 817f579..0528db6 100644 --- a/library/changes +++ b/library/changes @@ -15,6 +15,13 @@ - Added %D, %e, %F, %g, %G and %h for strftime(); repaired %I. +- Documented __strip_double_slash() and plugged in a memmove() + in place of the copying loop. + +- Modified __translate_unix_to_amiga_path_name() and + __translate_amiga_to_unix_path_name() to not to call strlen() + on the results of __strip_double_slash(). + c.lib 1.192 (12.5.2005) diff --git a/library/unistd_headers.h b/library/unistd_headers.h index 4aad35c..b683d7e 100644 --- a/library/unistd_headers.h +++ b/library/unistd_headers.h @@ -1,5 +1,5 @@ /* - * $Id: unistd_headers.h,v 1.7 2005-03-18 12:38:25 obarthel Exp $ + * $Id: unistd_headers.h,v 1.8 2005-05-15 12:32:58 obarthel Exp $ * * :ts=4 * @@ -90,7 +90,7 @@ extern BOOL NOCOMMON __unix_path_semantics; /****************************************************************************/ extern int __set_current_path(const char * path_name); -extern void __strip_double_slash(char * file_name,int len); +extern int __strip_double_slash(char * file_name,int len); /****************************************************************************/ diff --git a/library/unistd_strip_double_slash.c b/library/unistd_strip_double_slash.c index 443189b..dbc029e 100644 --- a/library/unistd_strip_double_slash.c +++ b/library/unistd_strip_double_slash.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_strip_double_slash.c,v 1.2 2005-01-02 09:07:19 obarthel Exp $ + * $Id: unistd_strip_double_slash.c,v 1.3 2005-05-15 12:32:59 obarthel Exp $ * * :ts=4 * @@ -40,48 +40,56 @@ /* Remove '//' from an AmigaDOS path name. For example, "volume:one/two//three" is equivalent to "volume:one/three" and the following function removes the redundant part of the path. */ -void +int __strip_double_slash(char * file_name,int len) { - int start,delta,position,i; - - assert( file_name != NULL && len > 0 ); + int position; position = len; while(len > 1) { position--; + + /* Stop when we hit the volume name or the first character of the name. */ if((position == 0) || (file_name[position] == ':') || (file_name[position - 1] == ':')) break; - if((position > 1) && (file_name[position] == '/') && (file_name[position - 1] == '/') && (file_name[position - 2] != ':') && (file_name[position - 2] != '/')) + /* Do we have a // embedded in the file_name? That // must stand alone + between directory names and not in front of a volume name or + yet another /. */ + if((position > 1) && (file_name[position] == '/' && file_name[position - 1] == '/') && (file_name[position - 2] != ':' && file_name[position - 2] != '/')) { + int start,delta; + start = position; + /* Back up behind the //. */ position -= 2; + /* Find the spot where the previous directory or volume + name begins. */ while((position > 0) && (file_name[position] != ':') && (file_name[position] != '/')) position--; + /* Don't move too far. */ if((file_name[position] == ':') || (file_name[position] == '/')) position++; - i = position; - delta = start - position + 1; + /* Find out how long the directory name is that + we are going to remove now. */ + delta = start - position + 1; + /* Remove the file_name part; we copy one more byte than + necessary to account for the NUL at the end. */ len -= delta; - while(i < len) - { - file_name[i] = file_name[i + delta]; - - i++; - } - - file_name[len] = '\0'; + memmove(&file_name[position],&file_name[position + delta],len - position + 1); + /* The string is shorter, and here we go again... */ position = len; } } + + return(len); } diff --git a/library/unistd_translatea2u.c b/library/unistd_translatea2u.c index 9b9a935..b72ce7b 100644 --- a/library/unistd_translatea2u.c +++ b/library/unistd_translatea2u.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_translatea2u.c,v 1.5 2005-04-24 08:46:37 obarthel Exp $ + * $Id: unistd_translatea2u.c,v 1.6 2005-05-15 12:32:59 obarthel Exp $ * * :ts=4 * @@ -89,9 +89,7 @@ __translate_amiga_to_unix_path_name(char const ** name_ptr,struct name_translati strcpy(local_replacement,name); name = local_replacement; - __strip_double_slash(name,len); - - len = strlen(name); + len = __strip_double_slash(name,len); } /* The empty string corresponds to the current diff --git a/library/unistd_translateu2a.c b/library/unistd_translateu2a.c index 80d85eb..14eaa8b 100644 --- a/library/unistd_translateu2a.c +++ b/library/unistd_translateu2a.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_translateu2a.c,v 1.8 2005-04-24 08:46:37 obarthel Exp $ + * $Id: unistd_translateu2a.c,v 1.9 2005-05-15 12:32:59 obarthel Exp $ * * :ts=4 * @@ -524,8 +524,7 @@ __translate_unix_to_amiga_path_name(char const ** name_ptr,struct name_translati name = replace; } - __strip_double_slash(name,len); - len = strlen(name); + len = __strip_double_slash(name,len); D(("name = '%s' (line %ld)",name,__LINE__)); }