Ignore:
Timestamp:
Jun 20, 2012, 12:44:52 AM (13 years ago)
Author:
bird
Message:

gnumake/current -> 3.82-cvs.

Location:
vendor/gnumake/current
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • vendor/gnumake/current

    • Property svn:ignore deleted
  • vendor/gnumake/current/misc.c

    r1989 r2596  
    11/* Miscellaneous generic support functions for GNU Make.
    22Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
    3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
    4 Foundation, Inc.
     31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
     42010 Free Software Foundation, Inc.
    55This file is part of GNU Make.
    66
     
    114114      ++in;
    115115
    116       /* If the newline is quoted, discard following whitespace
    117          and any preceding whitespace; leave just one space.  */
     116      /* If the newline is escaped, discard following whitespace leaving just
     117         one space.  POSIX requires that each backslash/newline/following
     118         whitespace sequence be reduced to a single space.  */
    118119      if (backslash)
    119120        {
    120121          in = next_token (in);
     122          /* Removing this loop will fix Savannah bug #16670: do we want to? */
    121123          while (out > line && isblank ((unsigned char)out[-1]))
    122124            --out;
     
    162164
    163165
    164 /* Return a string whose contents concatenate those of s1, s2, s3.
     166/* Return a string whose contents concatenate the NUM strings provided
    165167   This string lives in static, re-used memory.  */
    166168
    167 char *
    168 concat (const char *s1, const char *s2, const char *s3)
    169 {
    170   unsigned int len1, len2, len3;
     169const char *
     170#if HAVE_ANSI_COMPILER && USE_VARIADIC && HAVE_STDARG_H
     171concat (unsigned int num, ...)
     172#else
     173concat (num, va_alist)
     174     unsigned int num;
     175     va_dcl
     176#endif
     177{
    171178  static unsigned int rlen = 0;
    172179  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';
     180  int ri = 0;
     181
     182#if USE_VARIADIC
     183  va_list args;
     184#endif
     185
     186  VA_START (args, num);
     187
     188  while (num-- > 0)
     189    {
     190      const char *s = va_arg (args, const char *);
     191      unsigned int l = s ? strlen (s) : 0;
     192
     193      if (l == 0)
     194        continue;
     195
     196      if (ri + l > rlen)
     197        {
     198          rlen = ((rlen ? rlen : 60) + l) * 2;
     199          result = xrealloc (result, rlen);
     200        }
     201
     202      memcpy (result + ri, s, l);
     203      ri += l;
     204    }
     205
     206  VA_END (args);
     207
     208  /* Get some more memory if we don't have enough space for the
     209     terminating '\0'.   */
     210  if (ri == rlen)
     211    {
     212      rlen = (rlen ? rlen : 60) * 2;
     213      result = xrealloc (result, rlen);
     214    }
     215
     216  result[ri] = '\0';
    189217
    190218  return result;
     
    341369
    342370#undef xmalloc
     371#undef xcalloc
    343372#undef xrealloc
    344373#undef xstrdup
     
    347376xmalloc (unsigned int size)
    348377{
    349   /* Make sure we don't allocate 0, for pre-ANSI libraries.  */
     378  /* Make sure we don't allocate 0, for pre-ISO implementations.  */
    350379  void *result = malloc (size ? size : 1);
    351380  if (result == 0)
     
    356385
    357386void *
     387xcalloc (unsigned int size)
     388{
     389  /* Make sure we don't allocate 0, for pre-ISO implementations.  */
     390  void *result = calloc (size ? size : 1, 1);
     391  if (result == 0)
     392    fatal (NILF, _("virtual memory exhausted"));
     393  return result;
     394}
     395
     396
     397void *
    358398xrealloc (void *ptr, unsigned int size)
    359399{
    360400  void *result;
    361401
    362   /* Some older implementations of realloc() don't conform to ANSI.  */
     402  /* Some older implementations of realloc() don't conform to ISO.  */
    363403  if (! size)
    364404    size = 1;
     
    394434
    395435char *
    396 savestring (const char *str, unsigned int length)
    397 {
    398   char *out = xmalloc (length + 1);
     436xstrndup (const char *str, unsigned int length)
     437{
     438  char *result;
     439
     440#ifdef HAVE_STRNDUP
     441  result = strndup (str, length);
     442  if (result == 0)
     443    fatal (NILF, _("virtual memory exhausted"));
     444#else
     445  result = xmalloc (length + 1);
    399446  if (length > 0)
    400     memcpy (out, str, length);
    401   out[length] = '\0';
    402   return out;
     447    strncpy (result, str, length);
     448  result[length] = '\0';
     449#endif
     450
     451  return result;
    403452}
    404453
     
    493542
    494543
    495 /* Allocate a new `struct dep' with all fields initialized to 0.   */
    496 
    497 struct dep *
    498 alloc_dep ()
    499 {
    500   struct dep *d = xmalloc (sizeof (struct dep));
    501   memset (d, '\0', sizeof (struct dep));
    502   return d;
    503 }
    504 
    505 
    506 /* Free `struct dep' along with `name' and `stem'.   */
    507 
    508 void
    509 free_dep (struct dep *d)
    510 {
    511   free (d);
    512 }
    513 
    514 /* Copy a chain of `struct dep', making a new chain
    515    with the same contents as the old one.  */
     544/* Copy a chain of `struct dep'.  For 2nd expansion deps, dup the name.  */
    516545
    517546struct dep *
     
    525554      struct dep *c = xmalloc (sizeof (struct dep));
    526555      memcpy (c, d, sizeof (struct dep));
     556
     557      if (c->need_2nd_expansion)
     558        c->name = xstrdup (c->name);
    527559
    528560      c->next = 0;
     
    590622      return (c1 - c2);
    591623    }
     624}
     625#endif
     626
     627#if !HAVE_STRNCASECMP && !HAVE_STRNICMP && !HAVE_STRNCMPI
     628
     629/* If we don't have strncasecmp() (from POSIX), or anything that can
     630   substitute for it, define our own version.  */
     631
     632int
     633strncasecmp (const char *s1, const char *s2, int n)
     634{
     635  while (n-- > 0)
     636    {
     637      int c1 = (int) *(s1++);
     638      int c2 = (int) *(s2++);
     639
     640      if (isalpha (c1))
     641        c1 = tolower (c1);
     642      if (isalpha (c2))
     643        c2 = tolower (c2);
     644
     645      if (c1 != '\0' && c1 == c2)
     646        continue;
     647
     648      return (c1 - c2);
     649    }
     650
     651  return 0;
    592652}
    593653#endif
Note: See TracChangeset for help on using the changeset viewer.