[BACK]Return to str.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / make

Diff for /src/usr.bin/make/str.c between version 1.11 and 1.12

version 1.11, 1999/12/09 18:18:24 version 1.12, 2000/06/23 16:41:53
Line 51 
Line 51 
   
 /*-  /*-
  * str_concat --   * str_concat --
  *      concatenate the two strings, inserting a space or slash between them,   *      concatenate the two strings, possibly inserting a separator
  *      freeing them if requested.  
  *   *
  * returns --   * returns --
  *      the resulting string in allocated space.   *      the resulting string in allocated space.
  */   */
 char *  char *
 str_concat(s1, s2, flags)  str_concat(s1, s2, sep)
         char *s1, *s2;      const char *s1, *s2;
         int flags;      char sep;
 {  {
         register int len1, len2;      size_t len1, len2;
         register char *result;      char *result;
   
         /* get the length of both strings */      /* get the length of both strings */
         len1 = strlen(s1);      len1 = strlen(s1);
         len2 = strlen(s2);      len2 = strlen(s2);
   
         /* allocate length plus separator plus EOS */      /* space for separator */
         result = emalloc((u_int)(len1 + len2 + 2));      if (sep)
           len1++;
       result = emalloc(len1 + len2 + 1);
   
         /* copy first string into place */      /* copy first string into place */
         memcpy(result, s1, len1);      memcpy(result, s1, len1);
   
         /* add separator character */      /* add separator character */
         if (flags & STR_ADDSPACE) {      if (sep)
                 result[len1] = ' ';          result[len1-1] = sep;
                 ++len1;  
         } else if (flags & STR_ADDSLASH) {  
                 result[len1] = '/';  
                 ++len1;  
         }  
   
         /* copy second string plus EOS into place */      /* copy second string plus EOS into place */
         memcpy(result + len1, s2, len2 + 1);      memcpy(result + len1, s2, len2 + 1);
       return result;
         /* free original strings */  
         if (flags & STR_DOFREE) {  
                 (void)free(s1);  
                 (void)free(s2);  
         }  
         return(result);  
 }  }
   
 /*-  /*-

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12