Ignore:
Timestamp:
May 23, 2007, 5:13:11 AM (18 years ago)
Author:
bird
Message:

Load /home/bird/src/Gnu/make/2007-05-23 into vendor/gnumake/current.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/gnumake/current/misc.c

    r501 r900  
    162162
    163163
    164 /* Return a newly-allocated string whose contents
    165    concatenate those of s1, s2, s3.  */
     164/* Return a string whose contents concatenate those of s1, s2, s3.
     165   This string lives in static, re-used memory.  */
    166166
    167167char *
     
    169169{
    170170  unsigned int len1, len2, len3;
    171   char *result;
    172 
    173   len1 = *s1 != '\0' ? strlen (s1) : 0;
    174   len2 = *s2 != '\0' ? strlen (s2) : 0;
    175   len3 = *s3 != '\0' ? strlen (s3) : 0;
    176 
    177   result = (char *) xmalloc (len1 + len2 + len3 + 1);
    178 
    179   if (*s1 != '\0')
    180     bcopy (s1, result, len1);
    181   if (*s2 != '\0')
    182     bcopy (s2, result + len1, len2);
    183   if (*s3 != '\0')
    184     bcopy (s3, result + len1 + len2, len3);
    185   *(result + len1 + len2 + len3) = '\0';
     171  static unsigned int rlen = 0;
     172  static char *result = NULL;
     173
     174  len1 = (s1 && *s1 != '\0') ? strlen (s1) : 0;
     175  len2 = (s2 && *s2 != '\0') ? strlen (s2) : 0;
     176  len3 = (s3 && *s3 != '\0') ? strlen (s3) : 0;
     177
     178  if (len1 + len2 + len3 + 1 > rlen)
     179    result = xrealloc (result, (rlen = len1 + len2 + len3 + 10));
     180
     181  if (len1)
     182    memcpy (result, s1, len1);
     183  if (len2)
     184    memcpy (result + len1, s2, len2);
     185  if (len3)
     186    memcpy (result + len1 + len2, s3, len3);
     187
     188  result[len1+len2+len3] = '\0';
    186189
    187190  return result;
     
    341344#undef xstrdup
    342345
    343 char *
     346void *
    344347xmalloc (unsigned int size)
    345348{
    346349  /* Make sure we don't allocate 0, for pre-ANSI libraries.  */
    347   char *result = (char *) malloc (size ? size : 1);
     350  void *result = malloc (size ? size : 1);
    348351  if (result == 0)
    349352    fatal (NILF, _("virtual memory exhausted"));
     
    352355
    353356
    354 char *
    355 xrealloc (char *ptr, unsigned int size)
    356 {
    357   char *result;
     357void *
     358xrealloc (void *ptr, unsigned int size)
     359{
     360  void *result;
    358361
    359362  /* Some older implementations of realloc() don't conform to ANSI.  */
     
    375378  result = strdup (ptr);
    376379#else
    377   result = (char *) malloc (strlen (ptr) + 1);
     380  result = malloc (strlen (ptr) + 1);
    378381#endif
    379382
     
    384387  return result;
    385388#else
    386   return strcpy(result, ptr);
     389  return strcpy (result, ptr);
    387390#endif
    388391}
     
    393396savestring (const char *str, unsigned int length)
    394397{
    395   register char *out = (char *) xmalloc (length + 1);
     398  char *out = xmalloc (length + 1);
    396399  if (length > 0)
    397     bcopy (str, out, length);
     400    memcpy (out, str, length);
    398401  out[length] = '\0';
    399402  return out;
     
    434437 */
    435438char *
    436 end_of_token_w32 (char *s, char stopchar)
    437 {
    438   register char *p = s;
    439   register int backslash = 0;
     439end_of_token_w32 (const char *s, char stopchar)
     440{
     441  const char *p = s;
     442  int backslash = 0;
    440443
    441444  while (*p != '\0' && *p != stopchar
     
    455458    }
    456459
    457   return p;
     460  return (char *)p;
    458461}
    459462#endif
     
    469472}
    470473
    471 /* Find the next token in PTR; return the address of it, and store the
    472    length of the token into *LENGTHPTR if LENGTHPTR is not nil.  */
     474/* Find the next token in PTR; return the address of it, and store the length
     475   of the token into *LENGTHPTR if LENGTHPTR is not nil.  Set *PTR to the end
     476   of the token, so this function can be called repeatedly in a loop.  */
    473477
    474478char *
    475 find_next_token (char **ptr, unsigned int *lengthptr)
    476 {
    477   char *p = next_token (*ptr);
    478   char *end;
     479find_next_token (const char **ptr, unsigned int *lengthptr)
     480{
     481  const char *p = next_token (*ptr);
    479482
    480483  if (*p == '\0')
    481484    return 0;
    482485
    483   *ptr = end = end_of_token (p);
     486  *ptr = end_of_token (p);
    484487  if (lengthptr != 0)
    485     *lengthptr = end - p;
    486   return p;
     488    *lengthptr = *ptr - p;
     489
     490  return (char *)p;
    487491}
    488492
     
    494498alloc_dep ()
    495499{
    496   struct dep *d = (struct dep *) xmalloc (sizeof (struct dep));
    497   bzero ((char *) d, sizeof (struct dep));
     500  struct dep *d = xmalloc (sizeof (struct dep));
     501  memset (d, '\0', sizeof (struct dep));
    498502  return d;
    499503}
     
    505509free_dep (struct dep *d)
    506510{
    507   if (d->name != 0)
    508     free (d->name);
    509 
    510   if (d->stem != 0)
    511     free (d->stem);
    512 
    513   free ((char *)d);
     511  free (d);
    514512}
    515513
     
    520518copy_dep_chain (const struct dep *d)
    521519{
    522   register struct dep *c;
    523520  struct dep *firstnew = 0;
    524521  struct dep *lastnew = 0;
     
    526523  while (d != 0)
    527524    {
    528       c = (struct dep *) xmalloc (sizeof (struct dep));
    529       bcopy ((char *) d, (char *) c, sizeof (struct dep));
    530 
    531       if (c->name != 0)
    532         c->name = xstrdup (c->name);
    533       if (c->stem != 0)
    534         c->stem = xstrdup (c->stem);
     525      struct dep *c = xmalloc (sizeof (struct dep));
     526      memcpy (c, d, sizeof (struct dep));
    535527
    536528      c->next = 0;
     
    559551}
    560552
    561 
    562 /* Free a chain of `struct nameseq'. Each nameseq->name is freed
    563    as well.  For `struct dep' chains use free_dep_chain.  */
    564 
    565 void
    566 free_ns_chain (struct nameseq *n)
    567 {
    568   register struct nameseq *tmp;
    569 
    570   while (n != 0)
    571   {
    572     if (n->name != 0)
    573       free (n->name);
    574 
    575     tmp = n;
    576 
    577     n = n->next;
    578 
    579     free (tmp);
    580   }
    581 
    582 }
    583 
    584 #ifdef  iAPX286
    585 /* The losing compiler on this machine can't handle this macro.  */
    586 
    587 char *
    588 dep_name (struct dep *dep)
    589 {
    590   return dep->name == 0 ? dep->file->name : dep->name;
     553/* Free a chain of struct nameseq.
     554   For struct dep chains use free_dep_chain.  */
     555
     556void
     557free_ns_chain (struct nameseq *ns)
     558{
     559  while (ns != 0)
     560    {
     561      struct nameseq *t = ns;
     562      ns = ns->next;
     563      free (t);
     564    }
     565}
     566
     567
     568
     569#if !HAVE_STRCASECMP && !HAVE_STRICMP && !HAVE_STRCMPI
     570
     571/* If we don't have strcasecmp() (from POSIX), or anything that can substitute
     572   for it, define our own version.  */
     573
     574int
     575strcasecmp (const char *s1, const char *s2)
     576{
     577  while (1)
     578    {
     579      int c1 = (int) *(s1++);
     580      int c2 = (int) *(s2++);
     581
     582      if (isalpha (c1))
     583        c1 = tolower (c1);
     584      if (isalpha (c2))
     585        c2 = tolower (c2);
     586
     587      if (c1 != '\0' && c1 == c2)
     588        continue;
     589
     590      return (c1 - c2);
     591    }
    591592}
    592593#endif
Note: See TracChangeset for help on using the changeset viewer.